import { z } from "zod/v4"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "~/components/custom_ui/form"; import Input from "~/components/custom_ui/input"; import { IconMatrixTooltip } from "~/components/IconComponents"; import { Button } from "~/components/ui/button"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "~/components/ui/select"; import { Switch } from "~/components/ui/switch"; import { NullableStringOnChange } from "~/lib/form_utils"; import { useZodForm } from "~/lib/zodForm"; import type { Banners, BannersIdbanner } from "~/schemas/public/Banners"; type FormProps = { initialValues: Banners | null; submitMutation: (values: Banners) => void; del?: (idbanner: BannersIdbanner) => void; }; export const FormBanners = ({ initialValues, submitMutation, del, }: FormProps) => { const Schema = z.object({ color: z.string().nullable(), cta_href: z.string().nullable(), cta_icon: z.string().nullable(), cta_text: z.string().nullable(), has_cta: z.boolean(), hide_duration: z.number().nullable(), idbanner: z.custom(), is_active: z.boolean(), is_unskippable: z.boolean(), show_private: z.boolean(), show_public: z.boolean(), testo: z.string().nullable(), titolo: z.string().nullable(), }); type FormValues = z.infer; let defaultValues: FormValues; if (!initialValues) { defaultValues = { color: "", cta_href: "", cta_icon: "arrowR", cta_text: "", has_cta: false, hide_duration: 1, idbanner: "" as BannersIdbanner, is_active: false, is_unskippable: false, show_private: false, show_public: true, testo: "", titolo: "", }; } else { defaultValues = { ...initialValues, }; } z.config(z.locales.it()); const form = useZodForm(Schema, { defaultValues: defaultValues, }); function onSubmit(fields: FormValues) { const values = { ...fields, }; submitMutation(values); } const COLORI_OPTIONS = ["blu", "rosso", "verde", "indaco"]; return ( <>
(
Codice
)} /> (
Titolo
NullableStringOnChange(e, field.onChange)} value={field.value || ""} />
)} /> (
Testo
NullableStringOnChange(e, field.onChange)} value={field.value || ""} />
)} /> (
Non Saltabile
)} /> (
Ha Link
)} /> (
Per quanto il banner stà nascosto
{ field.onChange(Number.parseInt(e.target.value)); }} value={field.value || 1} />
)} /> (
Indirizzo Link
NullableStringOnChange(e, field.onChange)} value={field.value || ""} />
)} /> (
Icona Link -
NullableStringOnChange(e, field.onChange)} value={field.value || ""} />
)} /> (
Testo Link
NullableStringOnChange(e, field.onChange)} value={field.value || ""} />
)} /> (
Colore
)} /> (
Attivo
)} /> (
Mostra nel pubblico
)} /> (
Mostra in area riservata
)} />
{initialValues?.idbanner && del && ( )}
); };