"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { CalendarCheckIcon, AlertCircleIcon, Loader2Icon } from "lucide-react"; import { Button } from "@/components/ui/button"; import { createReminderAction, updateReminderAction } from "@/actions/reminders"; import { cn } from "@/lib/utils"; import type { MessagePart } from "@/lib/reminder-messages"; interface ReviewSubmitClientProps { accountId: string; groupIds?: string; name?: string; messages: MessagePart[]; scheduledAt: string; rrule?: string; editReminderId?: string; timezone: string; } export function ReviewSubmitClient({ accountId, groupIds, name, messages, scheduledAt, rrule, editReminderId, timezone, }: ReviewSubmitClientProps) { const router = useRouter(); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(null); async function handleSchedule() { const trimmedName = name?.trim(); if (!trimmedName) { // The wizard's compose step now blocks Continue when the name is // blank, so the only way to land here without one is a stale // bookmarked URL. Bounce the operator back to step 2 with a // clear error rather than letting the server reject it. setError("Give the reminder a name (back on the Message step)."); return; } setSubmitting(true); setError(null); try { const payload = { accountId, groupIds: groupIds ? groupIds.split(",").filter(Boolean) : [], name: trimmedName, messages, scheduledAtIso: scheduledAt, rrule: rrule ?? null, timezone, }; const result = editReminderId ? await updateReminderAction({ ...payload, reminderId: editReminderId }) : await createReminderAction(payload); if (result.ok) { // eslint-disable-next-line @typescript-eslint/no-explicit-any router.push(`/reminders/${result.reminderId}` as any); } else { setError(result.error); setSubmitting(false); } } catch (err) { setError(err instanceof Error ? err.message : "An unexpected error occurred."); setSubmitting(false); } } return (
{error && (
{error}
)}
); }