diff --git a/app/client/modules/notifications/components/create-notification-form.tsx b/app/client/modules/notifications/components/create-notification-form.tsx index 2fd240cf..ea532a55 100644 --- a/app/client/modules/notifications/components/create-notification-form.tsx +++ b/app/client/modules/notifications/components/create-notification-form.tsx @@ -17,7 +17,8 @@ import { Input } from "~/client/components/ui/input"; import { SecretInput } from "~/client/components/ui/secret-input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/client/components/ui/select"; import { Checkbox } from "~/client/components/ui/checkbox"; -import { notificationConfigSchema } from "~/schemas/notifications"; +import { NOTIFICATION_CONFIG_SHAPES, notificationConfigSchema, type NotificationConfig } from "~/schemas/notifications"; +import { stripDiscriminatedUnion } from "~/utils/object"; export const formSchema = type({ name: "2<=string<=32", @@ -26,6 +27,9 @@ const cleanSchema = type.pipe((d) => formSchema(deepClean(d))); export type NotificationFormValues = typeof formSchema.inferIn; +export const toNotificationConfig = (values: NotificationFormValues): NotificationConfig => + stripDiscriminatedUnion(values, "type", NOTIFICATION_CONFIG_SHAPES) as unknown as NotificationConfig; + type Props = { onSubmit: (values: NotificationFormValues) => void; mode?: "create" | "update"; diff --git a/app/client/modules/notifications/routes/create-notification.tsx b/app/client/modules/notifications/routes/create-notification.tsx index 72268a6b..cda7ec96 100644 --- a/app/client/modules/notifications/routes/create-notification.tsx +++ b/app/client/modules/notifications/routes/create-notification.tsx @@ -9,7 +9,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "~/client/components/ui import { parseError } from "~/client/lib/errors"; import type { Route } from "./+types/create-notification"; import { Alert, AlertDescription } from "~/client/components/ui/alert"; -import { CreateNotificationForm, type NotificationFormValues } from "../components/create-notification-form"; +import { CreateNotificationForm, type NotificationFormValues, toNotificationConfig } from "../components/create-notification-form"; export const handle = { breadcrumb: () => [{ label: "Notifications", href: "/notifications" }, { label: "Create" }], @@ -38,7 +38,7 @@ export default function CreateNotification() { }); const handleSubmit = (values: NotificationFormValues) => { - createNotification.mutate({ body: { name: values.name, config: values } }); + createNotification.mutate({ body: { name: values.name, config: toNotificationConfig(values) } }); }; return ( diff --git a/app/client/modules/notifications/routes/notification-details.tsx b/app/client/modules/notifications/routes/notification-details.tsx index c6675360..53598bff 100644 --- a/app/client/modules/notifications/routes/notification-details.tsx +++ b/app/client/modules/notifications/routes/notification-details.tsx @@ -26,7 +26,7 @@ import { cn } from "~/client/lib/utils"; import { Card, CardContent, CardHeader, CardTitle } from "~/client/components/ui/card"; import { Bell, Save, TestTube2, Trash2, X } from "lucide-react"; import { Alert, AlertDescription } from "~/client/components/ui/alert"; -import { CreateNotificationForm, type NotificationFormValues } from "../components/create-notification-form"; +import { CreateNotificationForm, type NotificationFormValues, toNotificationConfig } from "../components/create-notification-form"; export const handle = { breadcrumb: (match: Route.MetaArgs) => [ @@ -109,7 +109,7 @@ export default function NotificationDetailsPage({ loaderData }: Route.ComponentP path: { id: String(data.id) }, body: { name: values.name, - config: values, + config: toNotificationConfig(values), }, }); }; @@ -172,7 +172,12 @@ export default function NotificationDetailsPage({ loaderData }: Route.ComponentP )} - +