import { CoreApi, Token } from "authentik-api"; import { t } from "@lingui/macro"; import { customElement } from "lit-element"; import { html, TemplateResult } from "lit-html"; import { DEFAULT_CONFIG } from "../../../api/Config"; import { ifDefined } from "lit-html/directives/if-defined"; import "../../../elements/forms/HorizontalFormElement"; import { ModelForm } from "../../../elements/forms/ModelForm"; @customElement("ak-user-token-form") export class UserTokenForm extends ModelForm { loadInstance(pk: string): Promise { return new CoreApi(DEFAULT_CONFIG).coreTokensRetrieve({ identifier: pk, }); } getSuccessMessage(): string { if (this.instance) { return t`Successfully updated token.`; } else { return t`Successfully created token.`; } } send = (data: Token): Promise => { if (this.instance) { return new CoreApi(DEFAULT_CONFIG).coreTokensUpdate({ identifier: this.instance.identifier, tokenRequest: data, }); } else { return new CoreApi(DEFAULT_CONFIG).coreTokensCreate({ tokenRequest: data, }); } }; renderForm(): TemplateResult { return html`
`; } }