import { Application, CoreApi, PolicyTestResult } 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 { until } from "lit-html/directives/until"; import "../../elements/forms/HorizontalFormElement"; @customElement("ak-application-check-access-form") export class ApplicationCheckAccessForm extends Form { @property({attribute: false}) application!: Application; @property({ attribute: false}) result?: PolicyTestResult; @property({ attribute: false}) request?: number; getSuccessMessage(): string { return t`Successfully sent test-request.`; } send = (data: number): Promise => { this.request = data; return new CoreApi(DEFAULT_CONFIG).coreApplicationsCheckAccessRetrieve({ slug: this.application?.slug, forUser: data, }).then(result => this.result = result); }; renderResult(): TemplateResult { return html`
${this.result?.passing ? t`Yes` : t`No`}
    ${(this.result?.messages || []).length > 0 ? this.result?.messages?.map(m => { return html`
  • ${m}
  • `; }) : html`
  • -
  • `}
`; } renderForm(): TemplateResult { return html`
${this.result ? this.renderResult(): html``}
`; } }