"use client"; import React, { useState, useEffect } from 'react'; import { useParams, useRouter } from 'next/navigation'; import { Career } from '@/app/types'; import { apiClient } from '@/app/utils/apiClient'; import JobApplicationForm from '@/app/components/career/JobApplicationForm'; import { Box, Container, Typography, Paper, Chip, Button, Divider, CircularProgress, Alert } from '@mui/material'; import CalendarTodayIcon from '@mui/icons-material/CalendarToday'; import LocationOnIcon from '@mui/icons-material/LocationOn'; import WorkIcon from '@mui/icons-material/Work'; import MonetizationOnIcon from '@mui/icons-material/MonetizationOn'; import ArrowBackIcon from '@mui/icons-material/ArrowBack'; const JobDetailsPage = () => { const { id } = useParams(); const router = useRouter(); const [job, setJob] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [showApplicationForm, setShowApplicationForm] = useState(false); const [applicationSuccess, setApplicationSuccess] = useState(false); useEffect(() => { const fetchJobDetails = async () => { setLoading(true); try { const response = await apiClient(`/careers/listings/${id}`); if (response.success) { setJob(response.data); } else { setError('Failed to load job details'); } } catch (err) { console.error('Error fetching job details:', err); setError('An error occurred while loading the job. Please try again later.'); } finally { setLoading(false); } }; if (id) { fetchJobDetails(); } }, [id]); const handleApplyClick = () => { setShowApplicationForm(true); // Smooth scroll to application form setTimeout(() => { const applicationFormElement = document.getElementById('application-form'); if (applicationFormElement) { applicationFormElement.scrollIntoView({ behavior: 'smooth' }); } }, 100); }; const handleApplicationSuccess = () => { setApplicationSuccess(true); setShowApplicationForm(false); // Scroll to top window.scrollTo({ top: 0, behavior: 'smooth' }); }; if (loading) { return ( ); } if (error || !job) { return ( <> {error || 'Job not found'} ); } // Check if job is inactive if (job.status !== 'active') { return ( <> This job position is no longer accepting applications. ); } return ( <> {applicationSuccess && ( Your application has been submitted successfully! We'll review your application and contact you soon. )} {job.title} {job.location} {job.salary && ( {job.salary} )} Posted: {new Date(job.createdAt).toLocaleDateString()} Job Description {job.description} {showApplicationForm && ( Apply for this Position )} ); }; export default JobDetailsPage;