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 { CodeBlock } from "~/client/components/ui/code-block"; import { Label } from "~/client/components/ui/label"; 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 || []; 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"; } const previewCode = `${values.method} ${values.url}\nContent-Type: ${contentType}${headers.length > 0 ? `\n${headers.join("\n")}` : ""} ${body}`; return (

This is a preview of the HTTP request that will be sent.

); }; export const GenericForm = ({ form }: Props) => { const watchedValues = useWatch({ control: form.control }); const useJson = useWatch({ control: form.control, name: "useJson" }); return ( <> ( Webhook URL The target URL for the webhook. )} /> ( Method )} /> ( Content Type )} /> ( Headers