import { useMutation, useSuspenseQuery } from "@tanstack/react-query"; import { useId } from "react"; import { useNavigate } from "@tanstack/react-router"; import { Bell, Save } from "lucide-react"; import { toast } from "sonner"; import { getNotificationDestinationOptions, updateNotificationDestinationMutation, } from "~/client/api-client/@tanstack/react-query.gen"; import { Alert, AlertDescription } from "~/client/components/ui/alert"; import { Button } from "~/client/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "~/client/components/ui/card"; import { parseError } from "~/client/lib/errors"; import { CreateNotificationForm, type NotificationFormValues } from "../components/create-notification-form"; export function EditNotificationPage({ notificationId }: { notificationId: string }) { const navigate = useNavigate(); const formId = useId(); const { data } = useSuspenseQuery({ ...getNotificationDestinationOptions({ path: { id: notificationId } }), }); const updateDestination = useMutation({ ...updateNotificationDestinationMutation(), onSuccess: () => { toast.success("Notification destination updated successfully"); void navigate({ to: `/notifications/${data.id}` }); }, onError: (error) => { toast.error("Failed to update notification destination", { description: parseError(error)?.message, }); }, }); const handleSubmit = (values: NotificationFormValues) => { updateDestination.mutate({ path: { id: String(data.id) }, body: { name: values.name, config: values, }, }); }; return (
Edit Notification Destination
{updateDestination.isError && ( Failed to update notification destination:
{parseError(updateDestination.error)?.message}
)}
); }