diff --git a/web/src/pages/user-settings/UserSettingsPage.ts b/web/src/pages/user-settings/UserSettingsPage.ts index d2fb255b0..426bd4897 100644 --- a/web/src/pages/user-settings/UserSettingsPage.ts +++ b/web/src/pages/user-settings/UserSettingsPage.ts @@ -18,8 +18,8 @@ import { DEFAULT_CONFIG } from "../../api/Config"; import { until } from "lit-html/directives/until"; import { ifDefined } from "lit-html/directives/if-defined"; import "../../elements/Tabs"; +import "./tokens/UserTokenList"; import "./UserDetailsPage"; -import "./UserTokenList"; import "./settings/UserSettingsAuthenticatorTOTP"; import "./settings/UserSettingsAuthenticatorStatic"; import "./settings/UserSettingsAuthenticatorWebAuthn"; diff --git a/web/src/pages/user-settings/tokens/UserTokenForm.ts b/web/src/pages/user-settings/tokens/UserTokenForm.ts new file mode 100644 index 000000000..1de5b64dd --- /dev/null +++ b/web/src/pages/user-settings/tokens/UserTokenForm.ts @@ -0,0 +1,54 @@ +import { CoreApi, Token } from "authentik-api"; +import { gettext } from "django"; +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"; + +@customElement("ak-user-token-form") +export class UserTokenForm extends Form { + + @property({attribute: false}) + token?: Token; + + getSuccessMessage(): string { + if (this.token) { + return gettext("Successfully updated token."); + } else { + return gettext("Successfully created token."); + } + } + + send = (data: Token): Promise => { + if (this.token) { + return new CoreApi(DEFAULT_CONFIG).coreTokensUpdate({ + identifier: this.token.identifier, + data: data + }); + } else { + return new CoreApi(DEFAULT_CONFIG).coreTokensCreate({ + data: data + }); + } + }; + + renderForm(): TemplateResult { + return html`
+ + + + + + +
`; + } + +} diff --git a/web/src/pages/user-settings/UserTokenList.ts b/web/src/pages/user-settings/tokens/UserTokenList.ts similarity index 67% rename from web/src/pages/user-settings/UserTokenList.ts rename to web/src/pages/user-settings/tokens/UserTokenList.ts index 92c61c9f1..60cd1e25b 100644 --- a/web/src/pages/user-settings/UserTokenList.ts +++ b/web/src/pages/user-settings/tokens/UserTokenList.ts @@ -1,16 +1,19 @@ import { gettext } from "django"; -import { customElement, html, property, TemplateResult } from "lit-element"; -import { AKResponse } from "../../api/Client"; +import { CSSResult, customElement, html, property, TemplateResult } from "lit-element"; +import { AKResponse } from "../../../api/Client"; +import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css"; -import "../../elements/forms/DeleteForm"; -import "../../elements/buttons/ModalButton"; -import "../../elements/buttons/Dropdown"; -import "../../elements/buttons/TokenCopyButton"; -import { Table, TableColumn } from "../../elements/table/Table"; -import { PAGE_SIZE } from "../../constants"; +import "../../../elements/forms/DeleteForm"; +import "../../../elements/forms/ModalForm"; +import "../../../elements/buttons/ModalButton"; +import "../../../elements/buttons/Dropdown"; +import "../../../elements/buttons/TokenCopyButton"; +import { Table, TableColumn } from "../../../elements/table/Table"; +import { PAGE_SIZE } from "../../../constants"; import { CoreApi, Token } from "authentik-api"; -import { DEFAULT_CONFIG } from "../../api/Config"; -import { AdminURLManager } from "../../api/legacy"; +import { DEFAULT_CONFIG } from "../../../api/Config"; +import { AdminURLManager } from "../../../api/legacy"; +import "./UserTokenForm"; @customElement("ak-user-token-list") export class UserTokenList extends Table { @@ -39,14 +42,25 @@ export class UserTokenList extends Table { ]; } + static get styles(): CSSResult[] { + return super.styles.concat(PFDescriptionList); + } + renderToolbar(): TemplateResult { return html` - - + + ${gettext("Create")} - -
-
+ + + ${gettext("Create Token")} + + + + + ${super.renderToolbar()} `; } @@ -90,12 +104,19 @@ export class UserTokenList extends Table { return [ html`${item.identifier}`, html` - - + + + ${gettext("Update")} + + + ${gettext("Update Token")} + + + + +