From e46af92bb3a4655e6c155662ed9bd0bd4396c1c1 Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Mon, 20 Apr 2026 12:19:02 +0200 Subject: [PATCH] feat: refactor expires_date validation and update default values in FormAddCodaEmail --- apps/infoalloggi/src/forms/FormNewMail.tsx | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/apps/infoalloggi/src/forms/FormNewMail.tsx b/apps/infoalloggi/src/forms/FormNewMail.tsx index 87db699..c0f8109 100644 --- a/apps/infoalloggi/src/forms/FormNewMail.tsx +++ b/apps/infoalloggi/src/forms/FormNewMail.tsx @@ -29,8 +29,6 @@ import { type TemplateType, } from "~/server/services/mail-templates"; - - type FormProps = { submitMutation: (values: { lock_expires: Date; @@ -41,9 +39,16 @@ type FormProps = { const Schema = z .object({ - expires_date: z.date().refine((d) => isAfter(d, new Date()) || d.toDateString() === new Date().toDateString(), { - message: "La data deve essere nel futuro o oggi", - }), + expires_date: z + .date() + .refine( + (d) => + isAfter(d, new Date()) || + d.toDateString() === new Date().toDateString(), + { + message: "La data deve essere nel futuro o oggi", + }, + ), expires_time: z.string(), mailType: z.enum(TemplateKeys), mailProps: z.record(z.string(), z.unknown()).optional(), @@ -66,11 +71,11 @@ const Schema = z type FormValues = z.infer; export const FormAddCodaEmail = ({ submitMutation }: FormProps) => { z.config(z.locales.it()); - + const now = new Date(); const form = useZodForm(Schema, { defaultValues: { - expires_date: new Date(), - expires_time: "00:00:00", + expires_date: now, + expires_time: format(now, "HH:mm:ss"), mailType: TemplateKeys[0], mailProps: undefined, subject: "", @@ -118,7 +123,6 @@ export const FormAddCodaEmail = ({ submitMutation }: FormProps) => { return ( <>
- { field.onChange(e.target.value)} step="1"