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 { TestiEStringhe, TestiEStringheStingaId, } from "~/schemas/public/TestiEStringhe"; import Tiptap from "~/components/tip-tap/editor"; import { Confirm } from "~/components/confirm"; type FormProps = { initialValues: TestiEStringhe | null; submitMutation: (values: TestiEStringhe) => void; del?: (stringheId: TestiEStringheStingaId) => void; }; export const FormStringhe = ({ initialValues, submitMutation, del, }: FormProps) => { const Schema = z.object({ stinga_id: z.string(), stringa_value: z.string().nullable(), }); type FormValues = z.infer; let defaultValues: FormValues; // This can come from your database or API. if (!initialValues) { defaultValues = { stinga_id: "", stringa_value: null, }; } else { defaultValues = { stinga_id: initialValues.stinga_id, stringa_value: initialValues.stringa_value, }; } z.config(z.locales.it()); const form = useZodForm(Schema, { defaultValues: defaultValues, }); function onSubmit(fields: FormValues) { const values = { stinga_id: fields.stinga_id as TestiEStringheStingaId, stringa_value: fields.stringa_value, }; submitMutation(values); } return ( <>
(
Codice
)} /> (
Valore testuale
)} />
{initialValues?.stinga_id && del && ( del(initialValues.stinga_id)} > )}
); };