import { useWatch, type UseFormReturn } from "react-hook-form"; import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "~/client/components/ui/form"; import { Input } from "~/client/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/client/components/ui/select"; import { Checkbox } from "~/client/components/ui/checkbox"; import { Textarea } from "~/client/components/ui/textarea"; import { WebhookRequestPreview } from "~/client/components/webhook-request-preview"; import type { NotificationFormValues } from "../create-notification-form"; type Props = { form: UseFormReturn; }; const WebhookPreview = ({ values }: { values: Partial }) => { if (values.type !== "generic") return null; const contentType = values.contentType || "application/json"; const headers = values.headers?.filter(Boolean) || []; const useJson = values.useJson; const titleKey = values.titleKey || "title"; const messageKey = values.messageKey || "message"; let body = ""; if (useJson) { body = JSON.stringify( { [titleKey]: "Notification title", [messageKey]: "Notification message", }, null, 2, ); } else { body = "Notification message"; } return ( ); }; export const GenericForm = ({ form }: Props) => { const watchedValues = useWatch({ control: form.control }); const useJson = useWatch({ control: form.control, name: "useJson" }); return ( <> ( Webhook URL The target origin must be listed in WEBHOOK_ALLOWED_ORIGINS. )} /> ( Method )} /> ( Content Type )} /> ( Headers