import { EVENT_REFRESH } from "@goauthentik/web/constants"; import { ModalButton } from "@goauthentik/web/elements/buttons/ModalButton"; import "@goauthentik/web/elements/buttons/SpinnerButton"; import { MessageLevel } from "@goauthentik/web/elements/messages/Message"; import { showMessage } from "@goauthentik/web/elements/messages/MessageContainer"; import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; @customElement("ak-forms-confirm") export class ConfirmationForm extends ModalButton { @property() successMessage!: string; @property() errorMessage!: string; @property() action!: string; @property({ attribute: false }) onConfirm!: () => Promise; confirm(): Promise { return this.onConfirm() .then(() => { this.onSuccess(); this.open = false; this.dispatchEvent( new CustomEvent(EVENT_REFRESH, { bubbles: true, composed: true, }), ); }) .catch((e) => { this.onError(e); throw e; }); } onSuccess(): void { showMessage({ message: this.successMessage, level: MessageLevel.success, }); } onError(e: Error): void { showMessage({ message: t`${this.errorMessage}: ${e.toString()}`, level: MessageLevel.error, }); } renderModalInner(): TemplateResult { return html`

`; } }