'use client'; import React, { useState, useEffect } from 'react'; import { useParams, useRouter } from 'next/navigation'; import { Card } from 'primereact/card'; import { TabView, TabPanel } from 'primereact/tabview'; import { Button } from 'primereact/button'; import { Avatar } from 'primereact/avatar'; import { Divider } from 'primereact/divider'; import { DataTable } from 'primereact/datatable'; import { Column } from 'primereact/column'; import { Tag } from 'primereact/tag'; import { clientService } from '@/services/api'; import type { Client, Chantier, Facture } from '@/types/btp'; export default function ClientDetailsPage() { const params = useParams(); const router = useRouter(); const id = params.id as string; const [client, setClient] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { if (id) { loadClient(); } }, [id]); const loadClient = async () => { try { setLoading(true); const data = await clientService.getById(id); setClient(data); } catch (error) { console.error('Erreur lors du chargement du client:', error); // L'intercepteur API gérera automatiquement la redirection si 401 } finally { setLoading(false); } }; const formatMontant = (montant: number) => { return new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' }).format(montant); }; const statutChantierTemplate = (rowData: Chantier) => { const severity = rowData.statut === 'EN_COURS' ? 'warning' : rowData.statut === 'TERMINE' ? 'success' : 'info'; return ; }; const statutFactureTemplate = (rowData: Facture) => { const severity = rowData.statut === 'PAYEE' ? 'success' : rowData.statut === 'ENVOYEE' || rowData.statut === 'BROUILLON' ? 'warning' : rowData.statut === 'PARTIELLEMENT_PAYEE' ? 'info' : 'danger'; return ; }; if (loading || !client) { return
Chargement...
; } return (

Coordonnées

{client.email}
{client.telephone}
{client.adresse}, {client.codePostal} {client.ville}

Informations supplémentaires

SIRET: {client.siret || 'N/A'}
N° TVA: {client.numeroTVA || 'N/A'}
Date de création: {new Date(client.dateCreation).toLocaleDateString('fr-FR')}

Les chantiers et factures associés à ce client seront affichés ici une fois la relation établie dans le backend.

); }