'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'; interface Client { id: number; nom: string; email: string; telephone: string; adresse: string; ville: string; codePostal: string; typeClient: string; dateCreation: string; chantiers: Chantier[]; factures: Facture[]; } interface Chantier { id: number; nom: string; statut: string; dateDebut: string; budget: number; } interface Facture { id: number; numero: string; montant: number; dateEmission: string; statut: string; } 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 API_URL = process.env.NEXT_PUBLIC_API_URL || 'https://api.lions.dev/btpxpress'; const response = await fetch(`${API_URL}/api/v1/clients/${id}`); if (response.ok) { const data = await response.json(); setClient(data); } } catch (error) { console.error('Erreur:', error); } 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 === 'EN_ATTENTE' ? 'warning' : 'danger'; return ; }; if (loading || !client) { return
Chargement...
; } return (

Coordonnées

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

Statistiques

Chantiers
{client.chantiers?.length || 0}
Factures
{client.factures?.length || 0}
formatMontant(rowData.budget)} sortable /> (
); }