'use client'; import React, { useState } from 'react'; import { Card } from 'primereact/card'; import { InputText } from 'primereact/inputtext'; import { Dropdown } from 'primereact/dropdown'; import { InputNumber } from 'primereact/inputnumber'; import { Calendar } from 'primereact/calendar'; import { MultiSelect } from 'primereact/multiselect'; import { Button } from 'primereact/button'; import { Toast } from 'primereact/toast'; import { useRouter } from 'next/navigation'; import { apiClient } from '../../../../services/api-client'; interface NouvelEmploye { nom: string; prenom: string; email: string; telephone: string; metier: string; statut: string; dateEmbauche: Date | null; salaire: number | null; competences: string[]; certifications: string[]; adresse: string; numeroSecu: string; niveauExperience: string; } const NouvelEmployePage = () => { const [employe, setEmploye] = useState({ nom: '', prenom: '', email: '', telephone: '', metier: '', statut: 'ACTIF', dateEmbauche: null, salaire: null, competences: [], certifications: [], adresse: '', numeroSecu: '', niveauExperience: 'DEBUTANT' }); const [loading, setLoading] = useState(false); const router = useRouter(); const statutOptions = [ { label: 'Actif', value: 'ACTIF' }, { label: 'Inactif', value: 'INACTIF' }, { label: 'Formation', value: 'FORMATION' } ]; const metierOptions = [ { label: 'Maçon', value: 'MACON' }, { label: 'Électricien', value: 'ELECTRICIEN' }, { label: 'Plombier', value: 'PLOMBIER' }, { label: 'Charpentier', value: 'CHARPENTIER' }, { label: 'Peintre', value: 'PEINTRE' }, { label: 'Chef d\'équipe', value: 'CHEF_EQUIPE' }, { label: 'Conducteur', value: 'CONDUCTEUR' }, { label: 'Couvreur', value: 'COUVREUR' }, { label: 'Carreleur', value: 'CARRELEUR' }, { label: 'Menuisier', value: 'MENUISIER' } ]; const niveauExperienceOptions = [ { label: 'Débutant', value: 'DEBUTANT' }, { label: 'Intermédiaire', value: 'INTERMEDIAIRE' }, { label: 'Expérimenté', value: 'EXPERIMENTE' }, { label: 'Expert', value: 'EXPERT' } ]; const competencesOptions = [ { label: 'Maçonnerie', value: 'MACONNERIE' }, { label: 'Électricité', value: 'ELECTRICITE' }, { label: 'Plomberie', value: 'PLOMBERIE' }, { label: 'Charpente', value: 'CHARPENTE' }, { label: 'Peinture', value: 'PEINTURE' }, { label: 'Carrelage', value: 'CARRELAGE' }, { label: 'Menuiserie', value: 'MENUISERIE' }, { label: 'Couverture', value: 'COUVERTURE' }, { label: 'Isolation', value: 'ISOLATION' }, { label: 'Cloisons sèches', value: 'CLOISONS_SECHES' }, { label: 'Terrassement', value: 'TERRASSEMENT' }, { label: 'Conduite d\'engins', value: 'CONDUITE_ENGINS' } ]; const certificationsOptions = [ { label: 'CACES R482', value: 'CACES_R482' }, { label: 'CACES R489', value: 'CACES_R489' }, { label: 'Habilitation électrique', value: 'HABILITATION_ELECTRIQUE' }, { label: 'Travail en hauteur', value: 'TRAVAIL_HAUTEUR' }, { label: 'Soudure', value: 'SOUDURE' }, { label: 'Échafaudage', value: 'ECHAFAUDAGE' }, { label: 'Amiante', value: 'AMIANTE' }, { label: 'Plomb', value: 'PLOMB' } ]; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!employe.nom || !employe.prenom || !employe.email || !employe.metier) { console.error('❌ Champs obligatoires manquants'); return; } try { setLoading(true); console.log('🔄 Création de l\'employé...', employe); const employeData = { ...employe, dateEmbauche: employe.dateEmbauche?.toISOString().split('T')[0] }; const response = await apiClient.post('/api/employes', employeData); console.log('✅ Employé créé avec succès:', response.data); router.push('/employes'); } catch (error) { console.error('❌ Erreur lors de la création:', error); } finally { setLoading(false); } }; const handleCancel = () => { router.push('/employes'); }; return (
{/* Informations personnelles */}

Informations personnelles

setEmploye({...employe, nom: e.target.value})} required className="w-full" />
setEmploye({...employe, prenom: e.target.value})} required className="w-full" />
setEmploye({...employe, email: e.target.value})} required className="w-full" />
setEmploye({...employe, telephone: e.target.value})} className="w-full" />
setEmploye({...employe, adresse: e.target.value})} className="w-full" />
setEmploye({...employe, numeroSecu: e.target.value})} className="w-full" />
{/* Informations professionnelles */}

Informations professionnelles

setEmploye({...employe, metier: e.value})} placeholder="Sélectionner un métier" className="w-full" />
setEmploye({...employe, niveauExperience: e.value})} className="w-full" />
setEmploye({...employe, statut: e.value})} className="w-full" />
setEmploye({...employe, dateEmbauche: e.value as Date})} dateFormat="dd/mm/yy" className="w-full" />
setEmploye({...employe, salaire: e.value})} mode="currency" currency="EUR" locale="fr-FR" className="w-full" />
setEmploye({...employe, competences: e.value})} placeholder="Sélectionner les compétences" className="w-full" display="chip" />
setEmploye({...employe, certifications: e.value})} placeholder="Sélectionner les certifications" className="w-full" display="chip" />
{/* Boutons d'action */}
); }; export default NouvelEmployePage;