From 985a302a057012b1e21b6f89564520fe98db3dbb Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Thu, 12 Mar 2026 16:26:01 +0100 Subject: [PATCH] Refactor Prezziario schema and related components - Updated the Prezziario schema to replace boolean flags (isAcconto, isSaldo, isConsulenza, isStabile, isTransitorio) with new fields (order_type, service_type, service_variant) to better represent service attributes. - Modified NewPrezzoModal to align with the updated schema. - Renamed FormNewServizioAcquisto to FormServizioAcquisto in user onboarding pages for consistency. - Adjusted imports and component usage in the user view and service onboarding pages to reflect the new form name. --- .../src/components/custom_ui/data-table.tsx | 13 +- .../components/servizio/admin_conferma.tsx | 11 +- .../components/servizio/servizi_header.tsx | 4 +- .../components/tables/prezziario-tables.tsx | 101 +++------- apps/infoalloggi/src/forms/FormPrezzo.tsx | 190 ++++++++++-------- .../{FormNewServizio.tsx => FormServizio.tsx} | 4 +- ...oAcquisto.tsx => FormServizioAcquisto.tsx} | 24 +-- .../pages/area-riservata/admin/prezziario.tsx | 8 +- .../admin/user-view/onboard/[servizioId].tsx | 4 +- .../pages/servizio/onboard/[servizioId].tsx | 4 +- .../src/schemas/public/Prezziario.ts | 12 +- 11 files changed, 174 insertions(+), 201 deletions(-) rename apps/infoalloggi/src/forms/{FormNewServizio.tsx => FormServizio.tsx} (99%) rename apps/infoalloggi/src/forms/{FormNewServizioAcquisto.tsx => FormServizioAcquisto.tsx} (98%) diff --git a/apps/infoalloggi/src/components/custom_ui/data-table.tsx b/apps/infoalloggi/src/components/custom_ui/data-table.tsx index af2f72e..66d690d 100644 --- a/apps/infoalloggi/src/components/custom_ui/data-table.tsx +++ b/apps/infoalloggi/src/components/custom_ui/data-table.tsx @@ -45,7 +45,6 @@ type DataTableProps = { highlightedRow?: string; defaultColumnVisibility?: VisibilityState; tabClassName?: string; - pagination?: boolean; onStateChange?: () => void; defaultFilterState?: ColumnFiltersState; onTableInit?: (table: TableType) => void; @@ -79,7 +78,6 @@ export function DataTable({ highlightedRow, defaultColumnVisibility, tabClassName, - pagination = true, onStateChange, defaultFilterState, onTableInit, @@ -88,6 +86,10 @@ export function DataTable({ }: DataTableProps) { const [sorting, setSorting] = useState(defaultSort || []); const [rowSelection, setRowSelection] = useState({}); + const [pagination, setPagination] = useState({ + pageIndex: 0, //initial page index + pageSize: 20, //default page size + }); const [columnFilters, setColumnFilters] = useState( defaultFilterState || [], @@ -114,12 +116,14 @@ export function DataTable({ onGlobalFilterChange: setGlobalFilter, onRowSelectionChange: setRowSelection, onSortingChange: setSorting, + onPaginationChange: setPagination, state: { columnFilters, columnVisibility, globalFilter, rowSelection, sorting, + pagination, }, }); @@ -235,9 +239,8 @@ export function DataTable({ - {pagination ? ( - - ) : null} + + ); } diff --git a/apps/infoalloggi/src/components/servizio/admin_conferma.tsx b/apps/infoalloggi/src/components/servizio/admin_conferma.tsx index 579774a..c31f47d 100644 --- a/apps/infoalloggi/src/components/servizio/admin_conferma.tsx +++ b/apps/infoalloggi/src/components/servizio/admin_conferma.tsx @@ -587,10 +587,11 @@ const TransitorioSection = () => { }; const preferenzeDescrizione = data.desc_it?.match(/Permanenza:.*$/m); - const permanenzaAnnuncio = data.permanenza - ? `${data.permanenza.join(" - ")} mesi` - : (preferenzeDescrizione?.[0] ?? - "errore: testo non trovato in descrizione"); + const permanenzaAnnuncio = + data.permanenza !== null + ? `${data.permanenza.join(" - ")} mesi` + : (preferenzeDescrizione?.[0] ?? + "errore: testo non trovato in descrizione"); return (
@@ -601,7 +602,7 @@ const TransitorioSection = () => { desc
- void; setEditData: (data: Prezziario | null) => void; }) => { - const tabledata = data.map((row) => { - return { - actions: "Azioni", - categoria: [ - row.isAcconto && "acconto", - row.isSaldo && "saldo", - row.isConsulenza && "consulenza", - ].filter(Boolean), - desc_en: row.desc_en, - desc_it: row.desc_it, - id: row.idprezziario, - isAcconto: row.isAcconto, - isActive: row.isActive, - isConsulenza: row.isConsulenza, - isSaldo: row.isSaldo, - isStabile: row.isStabile, - isTransitorio: row.isTransitorio, - nome_en: row.nome_en, - nome_it: row.nome_it, - prezzo_cent: row.prezzo_cent, - sconto: row.sconto, - testo_condizioni: row.testo_condizioni, - }; - }); + const tabledata = data; - const cat_options = [ - { label: "acconto", value: "acconto" }, - { label: "saldo", value: "saldo" }, - { label: "consulenza", value: "consulenza" }, - ]; + const tipologia_options = Object.values(OrderTypeEnum).map((value) => ({ + label: value, + value: value, + })); + + const cat_options = Object.values(TipologiaPosizioneEnum).map((value) => ({ + label: value, + value: value, + })); const columns_titles = { actions: "Azioni", @@ -61,11 +44,10 @@ export const PrezzarioTable = ({ tipologia: "Tipo", }; type Column = (typeof tabledata)[number]; - const includesAll = (arr: string[], values: string[]) => - values.every((v) => arr.includes(v)); + const columns: ColumnDef[] = [ { - accessorKey: "id", + accessorKey: "idprezziario", enableHiding: false, header: ({ column }) => ( @@ -85,10 +67,8 @@ export const PrezzarioTable = ({ ), }, { - accessorKey: "categoria", - filterFn: (row, id, value) => { - return includesAll(row.getValue(id), value as string[]); - }, + accessorKey: "service_type", + header: ({ column }) => ( { - return ( -
- {(() => { - if (row.original.isTransitorio && row.original.isStabile) - return "Transitorio/Stabile"; - if (row.original.isTransitorio) return "Transitorio"; - if (row.original.isStabile) return "Stabile"; - return ""; - })()} -
- ); - }, - filterFn: (row, id, value) => { - return includesAll(row.getValue(id), value as string[]); - }, + accessorKey: "order_type", + header: ({ column }) => ( ( ), + enableSorting: false, }, { accessorKey: "actions", cell: ({ row }) => { - const rowData = row.original; return (
@@ -243,10 +247,9 @@ export const FormPrezzo = ({ elementId="select-testo-condizioni" elementName="testo_condizioni" isMulti={false} + key={`${field.value}-select-testo`} onValueChange={async (value) => { - if (value.value === "") { - field.onChange(undefined); - } else { + if (value.value !== "") { field.onChange( stringhe_condizioni_options[ Number.parseInt(value.value) @@ -268,101 +271,116 @@ export const FormPrezzo = ({
(
- Acconto - - + Tipologia + + {field.value !== null && ( + form.setValue("order_type", null)} /> - + )}
+ + +
)} /> (
- Saldo - - + Categoria + + {field.value !== null && ( + form.setValue("service_type", null)} /> - + )}
+ + +
)} /> (
- Consulenza - - + Variante Categoria + + {field.value !== null && ( + form.setValue("service_variant", null)} /> - - -
-
- )} - /> - ( - -
- Transitorio - - - - -
-
- )} - /> - ( - -
- Stabile - - - + )}
+ + { + const v = e.target.value.trim(); + if (v !== null && v !== "") { + field.onChange(parseInt(v, 10)); + } else { + field.onChange(null); + } + }} + value={field.value !== null ? String(field.value) : ""} + /> +
)} /> diff --git a/apps/infoalloggi/src/forms/FormNewServizio.tsx b/apps/infoalloggi/src/forms/FormServizio.tsx similarity index 99% rename from apps/infoalloggi/src/forms/FormNewServizio.tsx rename to apps/infoalloggi/src/forms/FormServizio.tsx index 364e0a0..fdc6b89 100644 --- a/apps/infoalloggi/src/forms/FormNewServizio.tsx +++ b/apps/infoalloggi/src/forms/FormServizio.tsx @@ -68,7 +68,7 @@ const Schema = z export type FormValues = z.infer; -export const FormNewServizio = ({ +export const FormServizio = ({ initialData, onSubmit, isLimited, @@ -290,7 +290,7 @@ export const FormNewServizio = ({ ; +type FormServizioAcquistoValues = z.infer; -export const FormNewServizioAcquisto = ({ +export const FormServizioAcquisto = ({ initialData, userId, isAdmin, @@ -122,8 +122,8 @@ export const FormNewServizioAcquisto = ({ }) => { const router = useRouter(); const { comuni, nazioni } = useCatasto(); - console.log(isAdmin); - const schema = FormNewServizioSchema.superRefine( + + const form_schema = schema.superRefine( ( { telefono, @@ -270,7 +270,7 @@ export const FormNewServizioAcquisto = ({ ); // This can come from your database or API. - const defaultValues: FormNewServizioValues = { + const defaultValues: FormServizioAcquistoValues = { ...initialData.userData, cap_recapiti: initialData.anagrafica?.cap_residenza || "", citta_recapiti: initialData.anagrafica?.comune_residenza || null, @@ -291,7 +291,7 @@ export const FormNewServizioAcquisto = ({ const { locale, t } = useTranslation(); z.config(z.locales[locale]()); - const form = useZodForm(schema, { + const form = useZodForm(form_schema, { defaultValues: defaultValues, }); const DatePickerLocale = locale === "it" ? it : enUS; @@ -323,7 +323,7 @@ export const FormNewServizioAcquisto = ({ }, }); - function onSubmit(fields: FormNewServizioValues) { + function onSubmit(fields: FormServizioAcquistoValues) { const a: UsersAnagraficaUpdate = { cap_residenza: fields.cap_recapiti, civico_residenza: fields.civico_recapiti, @@ -572,7 +572,7 @@ export const FormNewServizioAcquisto = ({ ; - trigger: (name?: keyof FormNewServizioValues) => Promise; + control: Control; + trigger: (name?: keyof FormServizioAcquistoValues) => Promise; // biome-ignore lint/suspicious/noExplicitAny: - setValue: (field: keyof FormNewServizioValues, value: any) => void; + setValue: (field: keyof FormServizioAcquistoValues, value: any) => void; }) => { const { t } = useTranslation(); const { comuni, nazioni, provincie } = useCatasto(); diff --git a/apps/infoalloggi/src/pages/area-riservata/admin/prezziario.tsx b/apps/infoalloggi/src/pages/area-riservata/admin/prezziario.tsx index 67073bb..15283f8 100644 --- a/apps/infoalloggi/src/pages/area-riservata/admin/prezziario.tsx +++ b/apps/infoalloggi/src/pages/area-riservata/admin/prezziario.tsx @@ -130,12 +130,10 @@ const NewPrezzoModal = () => { desc_en: "translations to be inserted", desc_it: "traduzioni da inserire", idprezziario: "" as PrezziarioIdprezziario, - isAcconto: false, + order_type: null, + service_type: null, + service_variant: null, isActive: true, - isConsulenza: false, - isSaldo: false, - isStabile: false, - isTransitorio: false, nome_en: "New service", nome_it: "Nuovo servizio", prezzo_cent: 0, diff --git a/apps/infoalloggi/src/pages/area-riservata/admin/user-view/onboard/[servizioId].tsx b/apps/infoalloggi/src/pages/area-riservata/admin/user-view/onboard/[servizioId].tsx index 5637ab7..4538e56 100644 --- a/apps/infoalloggi/src/pages/area-riservata/admin/user-view/onboard/[servizioId].tsx +++ b/apps/infoalloggi/src/pages/area-riservata/admin/user-view/onboard/[servizioId].tsx @@ -2,7 +2,7 @@ import type { GetServerSideProps } from "next"; import { AreaRiservataLayoutUserView } from "~/components/Layout"; import { LoadingPage } from "~/components/loading"; import { Status500 } from "~/components/status-page"; -import { FormNewServizioAcquisto } from "~/forms/FormNewServizioAcquisto"; +import { FormServizioAcquisto } from "~/forms/FormServizioAcquisto"; import type { NextPageWithLayout } from "~/pages/_app"; import { CatastoProvider } from "~/providers/CatastoProvider"; import type { ServizioServizioId } from "~/schemas/public/Servizio"; @@ -40,7 +40,7 @@ const OnboardUser: NextPageWithLayout = ({
- = ({
- ; - isAcconto: ColumnType; + order_type: ColumnType; - isSaldo: ColumnType; + service_type: ColumnType; - isConsulenza: ColumnType; - - isStabile: ColumnType; - - isTransitorio: ColumnType; + service_variant: ColumnType; } export type Prezziario = Selectable;