diff --git a/src/components/event-dialog.tsx b/src/components/event-dialog.tsx index d8634d6..6d00141 100644 --- a/src/components/event-dialog.tsx +++ b/src/components/event-dialog.tsx @@ -36,6 +36,12 @@ import { } from "@/lib/event-form"; import { parseRecurrenceRule, validateRecurrence } from "@/lib/recurrence"; +const STEP_FIELDS: Record<1 | 2 | 3, (keyof EventFormValues)[]> = { + 1: ["title", "url"], + 2: ["start", "end"], + 3: ["recurrenceRule"], +}; + interface EventDialogProps { open: boolean; onOpenChange: (open: boolean) => void; @@ -96,12 +102,6 @@ export const EventDialog = ({ onOpenChange(nextOpen); }; - const STEP_FIELDS: Record<1 | 2 | 3, (keyof EventFormValues)[]> = { - 1: ["title", "url"], - 2: ["start", "end"], - 3: ["recurrenceRule"], - }; - const handleNext = async () => { const valid = await trigger(STEP_FIELDS[step]); if (valid) advanceStep(); @@ -148,41 +148,42 @@ export const EventDialog = ({ reset(getDefaultEventFormValues()); }); - const onSubmit = handleSubmit((values) => { - const result = validateEventFormValues(values); - if (!result.success) { - const fieldErrors = result.error.flatten().fieldErrors; - for (const [fieldName, messages] of Object.entries(fieldErrors)) { - const firstMessage = messages?.[0]; - if (firstMessage) { - setError(fieldName as keyof EventFormValues, { - message: firstMessage, - }); - } - } - return; - } - - if (values.recurrenceRule) { - const recurrenceValidation = validateRecurrence(parseRecurrenceRule(values.recurrenceRule)); - if (!recurrenceValidation.isValid) { - setError("recurrenceRule", { - message: - recurrenceValidation.errors.rule || - recurrenceValidation.errors.count || - recurrenceValidation.errors.until || - "Invalid recurrence.", - }); - return; - } - } - - onSave(result.data); - reset(getDefaultEventFormValues()); - }); - const stepProps = { control, register, errors, watch, setValue, isAiDraft }; + if (!isMobile) { + return ( + + ); + } + const progressBars = (