import { EventsApi, NotificationTransport, NotificationTransportModeEnum } from "@goauthentik/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 { ifDefined } from "lit-html/directives/if-defined"; import "../../elements/forms/HorizontalFormElement"; import { first } from "../../utils"; import { ModelForm } from "../../elements/forms/ModelForm"; @customElement("ak-event-transport-form") export class TransportForm extends ModelForm { loadInstance(pk: string): Promise { return new EventsApi(DEFAULT_CONFIG).eventsTransportsRetrieve({ uuid: pk, }); } @property({ type: Boolean }) showWebhook = false; getSuccessMessage(): string { if (this.instance) { return t`Successfully updated transport.`; } else { return t`Successfully created transport.`; } } send = (data: NotificationTransport): Promise => { if (this.instance) { return new EventsApi(DEFAULT_CONFIG).eventsTransportsUpdate({ uuid: this.instance.pk || "", notificationTransportRequest: data, }); } else { return new EventsApi(DEFAULT_CONFIG).eventsTransportsCreate({ notificationTransportRequest: data, }); } }; renderTransportModes(): TemplateResult { return html` `; } firstUpdated(): void { if (this.instance) { this.onModeChange(this.instance.mode); } } onModeChange(mode: string): void { if ( mode === NotificationTransportModeEnum.Webhook || mode === NotificationTransportModeEnum.WebhookSlack ) { this.showWebhook = true; } else { this.showWebhook = false; } } renderForm(): TemplateResult { return html`

${t`Only send notification once, for example when sending a webhook into a chat channel.`}

`; } }