import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { until } from "lit/directives/until.js"; import { EventsApi, NotificationTransport, NotificationTransportModeEnum, PropertymappingsApi, } from "@goauthentik/api"; import { DEFAULT_CONFIG } from "../../api/Config"; import "../../elements/forms/HorizontalFormElement"; import { ModelForm } from "../../elements/forms/ModelForm"; import { first } from "../../utils"; @customElement("ak-event-transport-form") export class TransportForm extends ModelForm { loadInstance(pk: string): Promise { return new EventsApi(DEFAULT_CONFIG) .eventsTransportsRetrieve({ uuid: pk, }) .then((transport) => { this.onModeChange(transport.mode); return transport; }); } @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` `; } 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.`}

`; } }