From e311d8ace3b6a0e6b72191ac6b49c018efc22797 Mon Sep 17 00:00:00 2001 From: AV77web Date: Tue, 14 Jul 2026 10:51:04 +0200 Subject: [PATCH] correzione dei dati lato frontend --- src/api/client.ts | 12 +++++++++++- src/components/Layout.tsx | 2 +- src/pages/Dashboard.tsx | 10 ++++++++-- src/types/index.ts | 9 +++++++-- src/validation/constraints.ts | 30 ++++++++++++------------------ 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/api/client.ts b/src/api/client.ts index 8be4a99..420c24c 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -59,7 +59,17 @@ export async function login(email: string, password: string): Promise { const data = await response.json().catch(() => ({})) as { url?: string }; if (!response.ok || data.url?.includes("error=")) { - throw new Error("Credenziali non valide"); + const errorType = data.url?.match(/error=([^&]+)/)?.[1]; + if (errorType === "CredentialsSignin") { + throw new Error("Credenziali non valide"); + } + if (errorType === "MissingCSRF") { + throw new Error("Sessione scaduta: ricarica la pagina e riprova"); + } + if (errorType === "Configuration") { + throw new Error("Errore di configurazione del server (database o auth)"); + } + throw new Error("Accesso non riuscito"); } } diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index 63725c2..493bb00 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -15,7 +15,7 @@ export default function Layout() {
- Esame ITS 24-26 + Academy aziendale
); diff --git a/src/types/index.ts b/src/types/index.ts index f8514c1..65d5d0d 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,5 +1,10 @@ -export type Ruolo = "Operatore" | "Amministratore"; - +//======================================= +// File: index.ts +// Script per la gestione dei tipi utente +// author: "villari.andrea@libero.it" +// version: "1.0.0 2026-07-14" +//======================================= +export type Ruolo = "Dipendente" | "Referente Academy"; export interface Utente { id: number; diff --git a/src/validation/constraints.ts b/src/validation/constraints.ts index 0d8ac6c..3bb4842 100644 --- a/src/validation/constraints.ts +++ b/src/validation/constraints.ts @@ -1,8 +1,8 @@ //=================================================== // File: constraints.ts -// Vincoli derivati da initdb/01_schema.sql. +// Vincoli derivati da initdb/01_schema.sql (backend). // author: "villari.andrea@libero.it" -// version: "1.0.0 2026-06-24" +// version: "1.0.0 2026-07-14" //=================================================== export const UTENTE_CONSTRAINTS = { @@ -11,29 +11,23 @@ export const UTENTE_CONSTRAINTS = { email: { maxLength: 255, required: true }, password: { minLength: 8, maxLength: 72, required: true }, ruolo: { - allowedValues: ["Operatore", "Amministratore"], + allowedValues: ["Dipendente", "Referente Academy"] as const, required: true, }, } as const; -export const CLIENTE_CONSTRAINTS = { - nome: { maxLength: 100, required: true }, - cognome: { maxLength: 100, required: true }, - via: { maxLength: 100, required: true }, - comune: { maxLength: 100, required: true }, - provincia: { maxLength: 2, required: true }, - telefono: { maxLength: 30, required: true }, - email: { maxLength: 255, required: true }, - note: { required: false }, +export const CORSO_CONSTRAINTS = { + titolo: { maxLength: 200, required: true }, + descrizione: { maxLength: 65535, required: false }, + categoria: { maxLength: 100, required: true }, + durataOre: { min: 1, max: 65535, required: true }, + obbligatorio: { required: false }, + attivo: { required: false }, } as const; -export const CONSEGNA_CONSTRAINTS = { - dataRitiro: { required: false }, - dataConsegna: { required: false }, +export const ASSEGNAZIONE_CONSTRAINTS = { stato: { - allowedValues: ["da ritirare", "in consegna", "in giacenza", "in deposito"], + allowedValues: ["Assegnato", "Completato", "Scaduto", "Annullato"] as const, required: true, }, - chiaveConsegna: { maxLength: 8, required: true }, - clienteId: { required: true }, } as const;