import { t } from "@lingui/macro"; import { html, TemplateResult } from "lit"; import { customElement, property } from "lit/decorators"; import { ifDefined } from "lit/directives/if-defined"; import { until } from "lit/directives/until"; 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` ${t`Email`} ${t`Webhook (generic)`} ${t`Webhook (Slack/Discord)`} `; } onModeChange(mode: string): void { if ( mode === NotificationTransportModeEnum.Webhook || mode === NotificationTransportModeEnum.WebhookSlack ) { this.showWebhook = true; } else { this.showWebhook = false; } } renderForm(): TemplateResult { return html` { const current = (ev.target as HTMLInputElement).value; this.onModeChange(current); }} > ${this.renderTransportModes()} --------- ${until( new PropertymappingsApi(DEFAULT_CONFIG) .propertymappingsNotificationList({}) .then((mappings) => { return mappings.results.map((mapping) => { return html` ${mapping.name} `; }); }), html`${t`Loading...`}`, )} ${t`Send once`} ${t`Only send notification once, for example when sending a webhook into a chat channel.`} `; } }
${t`Only send notification once, for example when sending a webhook into a chat channel.`}