import { FunctionComponent, createRef } from "preact"; import { useCallback, useState } from "preact/hooks" import { BridgeConfig } from "../../BridgeAPI"; import type { OutboundHookConnectionState, OutboundHookResponseItem } from "../../../src/Connections/OutboundHook"; import { ConnectionConfigurationProps, RoomConfig } from "./RoomConfig"; import { InputField, ButtonSet, Button } from "../elements"; import WebhookIcon from "../../icons/webhook.png"; const ConnectionConfiguration: FunctionComponent> = ({existingConnection, onSave, onRemove, isUpdating}) => { const [outboundUrl, setOutboundUrl] = useState(existingConnection?.config.url ?? ''); const nameRef = createRef(); const canEdit = !existingConnection || (existingConnection?.canEdit ?? false); const handleSave = useCallback((evt: Event) => { evt.preventDefault(); if (!canEdit) { return; } onSave({ name: nameRef?.current?.value || existingConnection?.config.name || "Generic Webhook", url: outboundUrl, }); }, [canEdit, onSave, nameRef, outboundUrl, existingConnection]); const onUrlChange = useCallback((evt: any) => { setOutboundUrl(evt.target?.value); }, [setOutboundUrl]); const [tokenRevealed, setTokenRevealed] = useState(false); const revealToken = useCallback((evt: any) => { evt.preventDefault(); setTokenRevealed(true); }, [setTokenRevealed]); return
{ canEdit && } { canEdit && existingConnection && }
; }; interface ServiceConfig { allowJsTransformationFunctions: boolean, waitForComplete: boolean, } const RoomConfigText = { header: 'Outbound Webhooks', createNew: 'Create new webhook', listCanEdit: 'Your webhooks', listCantEdit: 'Configured webhooks', }; const RoomConfigListItemFunc = (c: OutboundHookResponseItem) => c.config.name; const OutboundWebhookConfig: BridgeConfig = ({ roomId, showHeader }) => { return headerImg={WebhookIcon} darkHeaderImg={true} showHeader={showHeader} roomId={roomId} type="genericOutbound" connectionEventType="uk.half-shot.matrix-hookshot.outbound-hook" text={RoomConfigText} listItemName={RoomConfigListItemFunc} connectionConfigComponent={ConnectionConfiguration} />; }; export default OutboundWebhookConfig;