import { z } from "zod/v4"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "~/components/custom_ui/form"; import { useZodForm } from "~/lib/zodForm"; import Input from "~/components/custom_ui/input"; import { Button } from "~/components/ui/button"; import type { Etichette, EtichetteIdEtichetta, } from "~/schemas/public/Etichette"; import { zEtichettaId } from "~/server/utils/zod_types"; import { ColorPicker } from "~/components/color_picker"; import { Confirm } from "~/components/confirm"; type FormProps = { initialValues: Etichette | null; submitMutation: (values: Etichette) => void; del?: (id_etichetta: EtichetteIdEtichetta) => void; }; export const FormEtichette = ({ initialValues, submitMutation, del, }: FormProps) => { const Schema = z.object({ id_etichetta: zEtichettaId, title: z.string(), color_hex: z.string().max(7), }); type FormValues = z.infer; let defaultValues: FormValues; // This can come from your database or API. if (!initialValues) { defaultValues = { id_etichetta: 0 as EtichetteIdEtichetta, title: "", color_hex: "", }; } else { defaultValues = { id_etichetta: initialValues.id_etichetta, title: initialValues.title, color_hex: initialValues.color_hex, }; } z.config(z.locales.it()); const form = useZodForm(Schema, { defaultValues: defaultValues, }); function onSubmit(fields: FormValues) { const values = { id_etichetta: fields.id_etichetta, title: fields.title, color_hex: fields.color_hex, }; submitMutation(values); } return ( <>
(
Titolo
)} /> (
Colore
)} />
{initialValues?.id_etichetta && del && ( del(initialValues.id_etichetta)} > )}
); };