import { CoreApi, User } from "authentik-api"; import { t } from "@lingui/macro"; import { customElement, property } from "lit-element"; import { html, TemplateResult } from "lit-html"; import { DEFAULT_CONFIG } from "../../api/Config"; import { Form } from "../../elements/forms/Form"; import { ifDefined } from "lit-html/directives/if-defined"; import "../../elements/forms/HorizontalFormElement"; import "../../elements/CodeMirror"; import YAML from "yaml"; import { first } from "../../utils"; @customElement("ak-user-form") export class UserForm extends Form { @property({ attribute: false }) user?: User; getSuccessMessage(): string { if (this.user) { return t`Successfully updated user.`; } else { return t`Successfully created user.`; } } send = (data: User): Promise => { if (this.user) { return new CoreApi(DEFAULT_CONFIG).coreUsersUpdate({ id: this.user.pk || 0, data: data }); } else { return new CoreApi(DEFAULT_CONFIG).coreUsersCreate({ data: data }); } }; renderForm(): TemplateResult { return html`

${t`Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.`}

${t`User's display name.`}

${t`Designates whether this user should be treated as active. Unselect this instead of deleting accounts.`}

${t`Set custom attributes using YAML or JSON.`}

`; } }