Corrections apportées: 1. **Utilisation correcte des services exportés** - Remplacement de apiService.X par les services nommés (chantierService, clientService, etc.) - Alignement avec l'architecture d'export du fichier services/api.ts 2. **Correction des types d'interface** - Utilisation des types officiels depuis @/types/btp - Chantier: suppression des propriétés custom, utilisation du type standard - Client: ajout des imports Chantier et Facture - Materiel: adaptation aux propriétés réelles (numeroSerie au lieu de reference) - PlanningEvent: remplacement de TacheChantier par PlanningEvent 3. **Correction des propriétés obsolètes** - Chantier: dateFin → dateFinPrevue, budget → montantPrevu, responsable → typeChantier - Client: typeClient → entreprise, suppression de chantiers/factures inexistants - Materiel: reference → numeroSerie, prixAchat → valeurAchat - PlanningEvent: nom → titre, suppression de progression 4. **Correction des enums** - StatutFacture: EN_ATTENTE → ENVOYEE/BROUILLON/PARTIELLEMENT_PAYEE - PrioritePlanningEvent: MOYENNE → CRITIQUE/HAUTE/NORMALE/BASSE 5. **Fix async/await pour cookies()** - Ajout de await pour cookies() dans les routes API (Next.js 15 requirement) - app/api/auth/logout/route.ts - app/api/auth/token/route.ts - app/api/auth/userinfo/route.ts 6. **Fix useSearchParams() Suspense** - Enveloppement de useSearchParams() dans un Suspense boundary - Création d'un composant LoginContent séparé - Ajout d'un fallback avec spinner Résultat: ✅ Build production réussi: 126 pages générées ✅ Compilation TypeScript sans erreurs ✅ Linting validé ✅ Middleware 34.4 kB ✅ First Load JS shared: 651 kB 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
135 lines
4.8 KiB
TypeScript
135 lines
4.8 KiB
TypeScript
'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<Client | null>(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 <Tag value={rowData.statut} severity={severity} />;
|
|
};
|
|
|
|
const statutFactureTemplate = (rowData: Facture) => {
|
|
const severity = rowData.statut === 'PAYEE' ? 'success' :
|
|
rowData.statut === 'ENVOYEE' || rowData.statut === 'BROUILLON' ? 'warning' :
|
|
rowData.statut === 'PARTIELLEMENT_PAYEE' ? 'info' : 'danger';
|
|
return <Tag value={rowData.statut} severity={severity} />;
|
|
};
|
|
|
|
if (loading || !client) {
|
|
return <div>Chargement...</div>;
|
|
}
|
|
|
|
return (
|
|
<div className="grid">
|
|
<div className="col-12">
|
|
<Card>
|
|
<div className="flex justify-content-between align-items-center mb-3">
|
|
<div className="flex align-items-center">
|
|
<Button
|
|
icon="pi pi-arrow-left"
|
|
className="p-button-text mr-2"
|
|
onClick={() => router.push('/clients')}
|
|
tooltip="Retour"
|
|
/>
|
|
<Avatar label={client.nom[0]} size="xlarge" shape="circle" className="mr-3" />
|
|
<div>
|
|
<h2 className="m-0">{client.nom} {client.prenom}</h2>
|
|
<p className="text-600 m-0">{client.entreprise || 'Particulier'}</p>
|
|
</div>
|
|
</div>
|
|
<Button
|
|
icon="pi pi-pencil"
|
|
label="Modifier"
|
|
className="p-button-outlined"
|
|
/>
|
|
</div>
|
|
|
|
<Divider />
|
|
|
|
<div className="grid">
|
|
<div className="col-12 md:col-6">
|
|
<h3>Coordonnées</h3>
|
|
<div className="flex align-items-center mb-2">
|
|
<i className="pi pi-envelope mr-2"></i>
|
|
<span>{client.email}</span>
|
|
</div>
|
|
<div className="flex align-items-center mb-2">
|
|
<i className="pi pi-phone mr-2"></i>
|
|
<span>{client.telephone}</span>
|
|
</div>
|
|
<div className="flex align-items-center mb-2">
|
|
<i className="pi pi-map-marker mr-2"></i>
|
|
<span>{client.adresse}, {client.codePostal} {client.ville}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="col-12 md:col-6">
|
|
<h3>Informations supplémentaires</h3>
|
|
<div className="mb-2"><strong>SIRET:</strong> {client.siret || 'N/A'}</div>
|
|
<div className="mb-2"><strong>N° TVA:</strong> {client.numeroTVA || 'N/A'}</div>
|
|
<div className="mb-2"><strong>Date de création:</strong> {new Date(client.dateCreation).toLocaleDateString('fr-FR')}</div>
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
</div>
|
|
|
|
<div className="col-12">
|
|
<Card title="Activités">
|
|
<p className="text-600">
|
|
Les chantiers et factures associés à ce client seront affichés ici une fois la relation établie dans le backend.
|
|
</p>
|
|
<div className="flex gap-2 mt-3">
|
|
<Button label="Voir les chantiers" icon="pi pi-home" className="p-button-outlined" onClick={() => router.push('/chantiers')} />
|
|
<Button label="Voir les factures" icon="pi pi-file" className="p-button-outlined" onClick={() => router.push('/factures')} />
|
|
</div>
|
|
</Card>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|