web/admin: fix empty request being sent due to multiple forms in duo import modal

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-11-24 12:08:06 +01:00
parent 0813a49ca5
commit 474677017f
1 changed files with 26 additions and 30 deletions

View File

@ -42,15 +42,14 @@ export class DuoDeviceImportForm extends ModelForm<AuthenticatorDuoStage, string
}; };
renderForm(): TemplateResult { renderForm(): TemplateResult {
return html`${this.instance?.adminIntegrationKey !== "" return html` <form class="pf-c-form pf-m-horizontal">
? this.renderFormAutomatic() ${this.instance?.adminIntegrationKey !== "" ? this.renderFormAutomatic() : html``}
: html``} ${this.renderFormManual()}
${this.renderFormManual()}`; </form>`;
} }
renderFormManual(): TemplateResult { renderFormManual(): TemplateResult {
return html`<form class="pf-c-form pf-m-horizontal"> return html`<ak-form-element-horizontal label=${t`User`} ?required=${true} name="username">
<ak-form-element-horizontal label=${t`User`} ?required=${true} name="username">
<select class="pf-c-form-control"> <select class="pf-c-form-control">
${until( ${until(
new CoreApi(DEFAULT_CONFIG) new CoreApi(DEFAULT_CONFIG)
@ -76,35 +75,32 @@ export class DuoDeviceImportForm extends ModelForm<AuthenticatorDuoStage, string
<p class="pf-c-form__helper-text"> <p class="pf-c-form__helper-text">
${t`The user ID in Duo, can be found in the URL after clicking on a user.`} ${t`The user ID in Duo, can be found in the URL after clicking on a user.`}
</p> </p>
</ak-form-element-horizontal> </ak-form-element-horizontal>`;
</form>`;
} }
renderFormAutomatic(): TemplateResult { renderFormAutomatic(): TemplateResult {
return html` return html`
<form class="pf-c-form pf-m-horizontal"> <ak-form-element-horizontal label=${t`Automatic import`}>
<ak-form-element-horizontal label=${t`Automatic import`}> <ak-action-button
<ak-action-button class="pf-m-primary"
class="pf-m-primary" .apiRequest=${() => {
.apiRequest=${() => { return new StagesApi(DEFAULT_CONFIG)
return new StagesApi(DEFAULT_CONFIG) .stagesAuthenticatorDuoImportDevicesAutomaticCreate({
.stagesAuthenticatorDuoImportDevicesAutomaticCreate({ stageUuid: this.instance?.pk || "",
stageUuid: this.instance?.pk || "", })
}) .then((res) => {
.then((res) => { showMessage({
showMessage({ level: MessageLevel.info,
level: MessageLevel.info, message: t`Successfully imported ${res.count} devices.`,
message: t`Successfully imported ${res.count} devices.`,
});
const modal = this.parentElement as ModalForm;
modal.open = false;
}); });
}} const modal = this.parentElement as ModalForm;
> modal.open = false;
${t`Start automatic import`} });
</ak-action-button> }}
</ak-form-element-horizontal> >
</form> ${t`Start automatic import`}
</ak-action-button>
</ak-form-element-horizontal>
<ak-divider>${t`Or manually import`}</ak-divider> <ak-divider>${t`Or manually import`}</ak-divider>
<br /> <br />
`; `;