import { t } from "@lingui/macro"; import { customElement } from "@lit/reactive-element/decorators/custom-element.js"; import { TemplateResult, html } from "lit"; import { ApplicationRequest, CoreApi, Provider } from "@goauthentik/api"; import { DEFAULT_CONFIG } from "../../../api/Config"; import { KeyUnknown } from "../../../elements/forms/Form"; import "../../../elements/forms/FormGroup"; import "../../../elements/forms/HorizontalFormElement"; import { WizardFormPage } from "../../../elements/wizard/WizardFormPage"; import { convertToSlug } from "../../../utils"; @customElement("ak-application-wizard-initial") export class InitialApplicationWizardPage extends WizardFormPage { sidebarLabel = () => t`Application details`; nextDataCallback = async (data: KeyUnknown): Promise => { const name = data.name as string; let slug = convertToSlug(name || ""); // Check if an application with the generated slug already exists const apps = await new CoreApi(DEFAULT_CONFIG).coreApplicationsList({ search: slug, }); if (apps.results.filter((app) => app.slug == slug)) { slug += "-1"; } this.host.state["slug"] = slug; this.host.state["name"] = name; this.host.addActionBefore(t`Create application`, async (): Promise => { const req: ApplicationRequest = { name: name || "", slug: slug, metaPublisher: data.metaPublisher as string, metaDescription: data.metaDescription as string, }; if ("provider" in this.host.state) { req.provider = (this.host.state["provider"] as Provider).pk; } if ("link" in this.host.state) { req.metaLaunchUrl = this.host.state["link"] as string; } this.host.state["app"] = await new CoreApi(DEFAULT_CONFIG).coreApplicationsCreate({ applicationRequest: req, }); return true; }); return true; }; renderForm(): TemplateResult { return html`

${t`Application's display Name.`}

${t`Additional UI settings`}
`; } }