import React, { useState, useEffect } from 'react'; import { useParams, Link } from 'react-router-dom'; import axios from 'axios'; import type { JobOffer } from '../types'; // Use type-only import const API_BASE_URL = 'http://localhost:3000/api/jobs'; const JobDetail: React.FC = () => { const { id } = useParams<{ id: string }>(); const [job, setJob] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchJobDetail = async () => { setLoading(true); setError(null); try { const response = await axios.get(`${API_BASE_URL}/${id}`); setJob(response.data); } catch (err) { console.error('Error fetching job detail:', err); if (axios.isAxiosError(err) && err.response?.status === 404) { setError('Job offer not found.'); } else { setError('Failed to load job offer details. Please try again.'); } } finally { setLoading(false); } }; if (id) { fetchJobDetail(); } }, [id]); const handleApplyClick = () => { // Logique pour trouver la meilleure URL de candidature const applyUrl = job?.urlOffre || job?.contact?.urlPostulation || job?.origineOffre?.urlOrigine; if (applyUrl) { window.open(applyUrl, '_blank'); // Ouvre l'URL dans un nouvel onglet } else { alert("No application URL available for this job offer."); } }; if (loading) { return

Loading job details...

; } if (error) { return (

Error: {error}

Back to Search
); } if (!job) { return (

No job details available.

Back to Search
); } return (
← Back to Job Search

{job.title}

Company: {job.companyName || 'N/A'}

Location: {job.locationLabel || job.cityName || 'N/A'}

Contract: {job.contractLabel || job.contractType || 'N/A'}

Published: {new Date(job.publicationDate).toLocaleDateString()}

{job.romeLabel &&

ROME: {job.romeLabel}

} {job.postalCode &&

Postal Code: {job.postalCode}

} {job.departmentCode &&

Department Code: {job.departmentCode}

}

Description

{job.description}

{/* Bouton Postuler */} {(job.urlOffre || job.contact?.urlPostulation || job.origineOffre?.urlOrigine) && ( )}
); }; export default JobDetail;