correzione dei dati lato frontend
All checks were successful
Deploy to VPS / build (push) Successful in 22s
Deploy to VPS / deploy (push) Successful in 26s

This commit is contained in:
AV77web 2026-07-14 10:51:04 +02:00
parent 948cdb8765
commit e311d8ace3
5 changed files with 39 additions and 24 deletions

View file

@ -59,8 +59,18 @@ export async function login(email: string, password: string): Promise<void> {
const data = await response.json().catch(() => ({})) as { url?: string }; const data = await response.json().catch(() => ({})) as { url?: string };
if (!response.ok || data.url?.includes("error=")) { if (!response.ok || data.url?.includes("error=")) {
const errorType = data.url?.match(/error=([^&]+)/)?.[1];
if (errorType === "CredentialsSignin") {
throw new Error("Credenziali non valide"); 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");
}
} }
export async function logout(): Promise<void> { export async function logout(): Promise<void> {

View file

@ -15,7 +15,7 @@ export default function Layout() {
<header className="header"> <header className="header">
<div className="header-inner"> <div className="header-inner">
<Link to="/dashboard" className="logo"> <Link to="/dashboard" className="logo">
Esame ITS 24-26 Academy aziendale
</Link> </Link>
<nav> <nav>
<Link to="/dashboard">Dashboard</Link> <Link to="/dashboard">Dashboard</Link>

View file

@ -1,3 +1,9 @@
//=======================================
// File: Daschborad.tsx
// Componete Dashborad dell'applicazione
// author: "villari.andrea@libero.it"
// version: "1.0.0 2026-07.14"
//=======================================
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom"; import { useLocation, useNavigate } from "react-router-dom";
import { useAuth } from "../context/AuthContext"; import { useAuth } from "../context/AuthContext";
@ -6,7 +12,7 @@ export default function Dashboard() {
const { user } = useAuth(); const { user } = useAuth();
const location = useLocation(); const location = useLocation();
const navigate = useNavigate(); const navigate = useNavigate();
const isAdmin = user?.ruolo === "Amministratore"; const isReferente = user?.ruolo === "Referente Academy";
const [deniedMessage, setDeniedMessage] = useState<string | null>(null); const [deniedMessage, setDeniedMessage] = useState<string | null>(null);
useEffect(() => { useEffect(() => {
@ -24,7 +30,7 @@ export default function Dashboard() {
<p> <p>
Benvenuto, <strong>{user?.nome} {user?.cognome}</strong> Benvenuto, <strong>{user?.nome} {user?.cognome}</strong>
</p> </p>
<p className="muted">Ruolo: {isAdmin ? "Amministratore" : "Operatore"}</p> <p className="muted">Ruolo: {isReferente ? "Referente Academy" : "Dipendente"}</p>
<p className="muted">Email: {user?.email}</p> <p className="muted">Email: {user?.email}</p>
</div> </div>
); );

View file

@ -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 { export interface Utente {
id: number; id: number;

View file

@ -1,8 +1,8 @@
//=================================================== //===================================================
// File: constraints.ts // File: constraints.ts
// Vincoli derivati da initdb/01_schema.sql. // Vincoli derivati da initdb/01_schema.sql (backend).
// author: "villari.andrea@libero.it" // author: "villari.andrea@libero.it"
// version: "1.0.0 2026-06-24" // version: "1.0.0 2026-07-14"
//=================================================== //===================================================
export const UTENTE_CONSTRAINTS = { export const UTENTE_CONSTRAINTS = {
@ -11,29 +11,23 @@ export const UTENTE_CONSTRAINTS = {
email: { maxLength: 255, required: true }, email: { maxLength: 255, required: true },
password: { minLength: 8, maxLength: 72, required: true }, password: { minLength: 8, maxLength: 72, required: true },
ruolo: { ruolo: {
allowedValues: ["Operatore", "Amministratore"], allowedValues: ["Dipendente", "Referente Academy"] as const,
required: true, required: true,
}, },
} as const; } as const;
export const CLIENTE_CONSTRAINTS = { export const CORSO_CONSTRAINTS = {
nome: { maxLength: 100, required: true }, titolo: { maxLength: 200, required: true },
cognome: { maxLength: 100, required: true }, descrizione: { maxLength: 65535, required: false },
via: { maxLength: 100, required: true }, categoria: { maxLength: 100, required: true },
comune: { maxLength: 100, required: true }, durataOre: { min: 1, max: 65535, required: true },
provincia: { maxLength: 2, required: true }, obbligatorio: { required: false },
telefono: { maxLength: 30, required: true }, attivo: { required: false },
email: { maxLength: 255, required: true },
note: { required: false },
} as const; } as const;
export const CONSEGNA_CONSTRAINTS = { export const ASSEGNAZIONE_CONSTRAINTS = {
dataRitiro: { required: false },
dataConsegna: { required: false },
stato: { stato: {
allowedValues: ["da ritirare", "in consegna", "in giacenza", "in deposito"], allowedValues: ["Assegnato", "Completato", "Scaduto", "Annullato"] as const,
required: true, required: true,
}, },
chiaveConsegna: { maxLength: 8, required: true },
clienteId: { required: true },
} as const; } as const;