|
import React, { useEffect, useState } from "react"; |
|
import { useParams, useNavigate } from "react-router-dom"; |
|
import JobPageSection from "../sections/jobs/JobPageSection"; |
|
import jobData from "../data/jobdescription"; |
|
|
|
const JobPage = () => { |
|
const { slug } = useParams(); |
|
const navigate = useNavigate(); |
|
const [job, setJob] = useState(null); |
|
const [error, setError] = useState(null); |
|
|
|
useEffect(() => { |
|
|
|
if (!/^\d+$/.test(slug)) { |
|
setError("Invalid job slug. Redirecting..."); |
|
setTimeout(() => navigate("/jobs"), 2000); |
|
return; |
|
} |
|
|
|
|
|
const foundJob = jobData.find((item) => item.id === parseInt(slug, 10)); |
|
if (!foundJob) { |
|
setError("Job description not found. Redirecting..."); |
|
setTimeout(() => navigate("/jobs"), 2000); |
|
} else { |
|
setJob(foundJob); |
|
} |
|
}, [slug, navigate]); |
|
|
|
|
|
if (error) return <div>{error}</div>; |
|
|
|
|
|
if (!job) { |
|
return <div>Loading...</div>; |
|
} |
|
|
|
|
|
return ( |
|
<div> |
|
<JobPageSection job={job} /> {/* Pass the job data to JobPageSection */} |
|
</div> |
|
); |
|
}; |
|
|
|
export default JobPage; |
|
|