import { EventsApi, NotificationTransport, NotificationTransportModeEnum } 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-event-transport-form") export class TransportForm extends Form { @property({attribute: false}) transport?: NotificationTransport; @property({type: Boolean}) showWebhook = false; getSuccessMessage(): string { if (this.transport) { return gettext("Successfully updated transport."); } else { return gettext("Successfully created transport."); } } send = (data: NotificationTransport): Promise => { if (this.transport) { return new EventsApi(DEFAULT_CONFIG).eventsTransportsUpdate({ uuid: this.transport.pk || "", data: data }); } else { return new EventsApi(DEFAULT_CONFIG).eventsTransportsCreate({ data: data }); } }; renderTransportModes(): TemplateResult { return html` `; } firstUpdated(): void { if (this.transport) { this.onModeChange(this.transport.mode); } } onModeChange(mode: string): void { if (mode === NotificationTransportModeEnum.Webhook || mode === NotificationTransportModeEnum.WebhookSlack) { this.showWebhook = true; } else { this.showWebhook = false; } } renderForm(): TemplateResult { return html`

${gettext("Only send notification once, for example when sending a webhook into a chat channel.")}

`; } }