DEV: Convert second-factor-edit modals to component-based API (#22367)

This PR converts the following modals:
- `second-factor-edit-security-key`
- `second-factor-edit`

to make use of the new component-based API
This commit is contained in:
Isaac Janzen 2023-07-04 12:13:54 -05:00 committed by GitHub
parent 1122454904
commit 8f21d2cf40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 134 additions and 108 deletions

View File

@ -0,0 +1,26 @@
<DModal
@title={{i18n "user.second_factor.security_key.edit"}}
@closeModal={{@closeModal}}
>
<:body>
<form class="form-horizontal">
<div class="input-group">
<label for="security-key-name">{{i18n
"user.second_factor.security_key.edit_description"
}}</label>
<Input
name="security-key-name"
@type="text"
@value={{@model.securityKey.name}}
/>
</div>
</form>
</:body>
<:footer>
<DButton
@action={{this.editSecurityKey}}
class="btn-primary"
@label="user.second_factor.security_key.save"
/>
</:footer>
</DModal>

View File

@ -0,0 +1,31 @@
import Component from "@glimmer/component";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
export default class SecondFactorEditSecurityKey extends Component {
@tracked loading = false;
@action
editSecurityKey() {
this.loading = true;
this.args.model.user
.updateSecurityKey(
this.args.model.securityKey.id,
this.args.model.securityKey.name,
false
)
.then((response) => {
if (response.error) {
return;
}
this.args.model.markDirty();
})
.catch((error) => {
this.args.model.onError(error);
})
.finally(() => {
this.loading = false;
this.args.closeModal();
});
}
}

View File

@ -0,0 +1,24 @@
<DModal
@title={{i18n "user.second_factor.edit_title"}}
@closeModal={{@closeModal}}
>
<:body>
<div class="input-group">
<label for="authenticator-name">{{i18n
"user.second_factor.edit_description"
}}</label>
<Input
name="authenticator-name"
@type="text"
@value={{@model.secondFactor.name}}
/>
</div>
</:body>
<:footer>
<DButton
@action={{this.editSecondFactor}}
class="btn-primary"
@label="user.second_factor.save"
/>
</:footer>
</DModal>

View File

@ -0,0 +1,33 @@
import Component from "@glimmer/component";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
export default class SecondFactorEdit extends Component {
@tracked loading = false;
@action
editSecondFactor() {
this.loading = true;
this.args.model.user
.updateSecondFactor(
this.args.model.secondFactor.id,
this.args.model.secondFactor.name,
false,
this.args.model.secondFactor.method
)
.then((response) => {
if (response.error) {
return;
}
this.args.model.markDirty();
})
.catch((error) => {
this.args.closeModal();
this.args.model.onError(error);
})
.finally(() => {
this.loading = false;
this.args.closeModal();
});
}
}

View File

@ -12,6 +12,8 @@ import showModal from "discourse/lib/show-modal";
import { inject as service } from "@ember/service";
import SecondFactorConfirmPhrase from "discourse/components/dialog-messages/second-factor-confirm-phrase";
import SecondFactorAddSecurityKey from "discourse/components/modal/second-factor-add-security-key";
import SecondFactorEditSecurityKey from "discourse/components/modal/second-factor-edit-security-key";
import SecondFactorEdit from "discourse/components/modal/second-factor-edit";
export default Controller.extend(CanCheckEmails, {
dialog: service(),
@ -284,30 +286,28 @@ export default Controller.extend(CanCheckEmails, {
this.loadSecondFactors();
},
editSecurityKey(security_key) {
const controller = showModal("second-factor-edit-security-key", {
model: security_key,
title: "user.second_factor.security_key.edit",
});
controller.setProperties({
user: this.model,
onClose: () => this.loadSecondFactors(),
markDirty: () => this.markDirty(),
onError: (e) => this.handleError(e),
async editSecurityKey(security_key) {
await this.modal.show(SecondFactorEditSecurityKey, {
model: {
securityKey: security_key,
user: this.model,
markDirty: () => this.markDirty(),
onError: (e) => this.handleError(e),
},
});
this.loadSecondFactors();
},
editSecondFactor(second_factor) {
const controller = showModal("second-factor-edit", {
model: second_factor,
title: "user.second_factor.edit_title",
});
controller.setProperties({
user: this.model,
onClose: () => this.loadSecondFactors(),
markDirty: () => this.markDirty(),
onError: (e) => this.handleError(e),
async editSecondFactor(second_factor) {
await this.modal.show(SecondFactorEdit, {
model: {
secondFactor: second_factor,
user: this.model,
markDirty: () => this.markDirty(),
onError: (e) => this.handleError(e),
},
});
this.loadSecondFactors();
},
editSecondFactorBackup() {

View File

@ -1,24 +0,0 @@
import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
export default Controller.extend(ModalFunctionality, {
actions: {
editSecurityKey() {
this.user
.updateSecurityKey(this.model.id, this.model.name, false)
.then((response) => {
if (response.error) {
return;
}
this.markDirty();
})
.catch((error) => {
this.onError(error);
})
.finally(() => {
this.set("loading", false);
this.send("closeModal");
});
},
},
});

View File

@ -1,30 +0,0 @@
import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
export default Controller.extend(ModalFunctionality, {
actions: {
editSecondFactor() {
this.user
.updateSecondFactor(
this.model.id,
this.model.name,
false,
this.model.method
)
.then((response) => {
if (response.error) {
return;
}
this.markDirty();
})
.catch((error) => {
this.send("closeModal");
this.onError(error);
})
.finally(() => {
this.set("loading", false);
this.send("closeModal");
});
},
},
});

View File

@ -1,18 +0,0 @@
<DModalBody>
<form class="form-horizontal">
<div class="input-group">
<label for="security-key-name">{{i18n
"user.second_factor.security_key.edit_description"
}}</label>
<Input name="security-key-name" @type="text" @value={{this.model.name}} />
</div>
</form>
</DModalBody>
<div class="modal-footer">
<DButton
@action={{action "editSecurityKey"}}
@class="btn-primary"
@label="user.second_factor.security_key.save"
/>
</div>

View File

@ -1,16 +0,0 @@
<DModalBody>
<div class="input-group">
<label for="authenticator-name">{{i18n
"user.second_factor.edit_description"
}}</label>
<Input name="authenticator-name" @type="text" @value={{this.model.name}} />
</div>
</DModalBody>
<div class="modal-footer">
<DButton
@action={{action "editSecondFactor"}}
@class="btn-primary"
@label="user.second_factor.save"
/>
</div>