mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 19:56:42 +00:00
Cleanup created user if person creation is cancelled (#7865)
This commit is contained in:
parent
3bdab738c6
commit
c4f850cb14
@ -68,6 +68,8 @@ class DialogPersonDetail extends LitElement {
|
|||||||
|
|
||||||
@internalProperty() private _submitting = false;
|
@internalProperty() private _submitting = false;
|
||||||
|
|
||||||
|
@internalProperty() private _personExists = false;
|
||||||
|
|
||||||
private _deviceTrackersAvailable = memoizeOne((hass) => {
|
private _deviceTrackersAvailable = memoizeOne((hass) => {
|
||||||
return Object.keys(hass.states).some(
|
return Object.keys(hass.states).some(
|
||||||
(entityId) =>
|
(entityId) =>
|
||||||
@ -79,6 +81,7 @@ class DialogPersonDetail extends LitElement {
|
|||||||
this._params = params;
|
this._params = params;
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
if (this._params.entry) {
|
if (this._params.entry) {
|
||||||
|
this._personExists = true;
|
||||||
this._name = this._params.entry.name || "";
|
this._name = this._params.entry.name || "";
|
||||||
this._userId = this._params.entry.user_id || undefined;
|
this._userId = this._params.entry.user_id || undefined;
|
||||||
this._deviceTrackers = this._params.entry.device_trackers || [];
|
this._deviceTrackers = this._params.entry.device_trackers || [];
|
||||||
@ -88,6 +91,7 @@ class DialogPersonDetail extends LitElement {
|
|||||||
: undefined;
|
: undefined;
|
||||||
this._isAdmin = this._user?.group_ids.includes(SYSTEM_GROUP_ID_ADMIN);
|
this._isAdmin = this._user?.group_ids.includes(SYSTEM_GROUP_ID_ADMIN);
|
||||||
} else {
|
} else {
|
||||||
|
this._personExists = false;
|
||||||
this._name = "";
|
this._name = "";
|
||||||
this._userId = undefined;
|
this._userId = undefined;
|
||||||
this._user = undefined;
|
this._user = undefined;
|
||||||
@ -398,6 +402,7 @@ class DialogPersonDetail extends LitElement {
|
|||||||
await this._params!.updateEntry(values);
|
await this._params!.updateEntry(values);
|
||||||
} else {
|
} else {
|
||||||
await this._params!.createEntry(values);
|
await this._params!.createEntry(values);
|
||||||
|
this._personExists = true;
|
||||||
}
|
}
|
||||||
this._params = undefined;
|
this._params = undefined;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -422,6 +427,14 @@ class DialogPersonDetail extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _close(): void {
|
private _close(): void {
|
||||||
|
// If we do not have a person ID yet (= person creation dialog was just cancelled), but
|
||||||
|
// we already created a user ID for it, delete it now to not have it "free floating".
|
||||||
|
if (!this._personExists && this._userId) {
|
||||||
|
deleteUser(this.hass, this._userId);
|
||||||
|
this._params?.refreshUsers();
|
||||||
|
this._userId = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
this._params = undefined;
|
this._params = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user