diff --git a/frontend/src/app/dashboard/jobs/page.tsx b/frontend/src/app/dashboard/jobs/page.tsx index 6977072..9fd7f1d 100644 --- a/frontend/src/app/dashboard/jobs/page.tsx +++ b/frontend/src/app/dashboard/jobs/page.tsx @@ -29,7 +29,11 @@ type AdminJobRow = ReturnType & { export default function AdminJobsPage() { const [searchTerm, setSearchTerm] = useState("") const [jobs, setJobs] = useState([]) - const [isDialogOpen, setIsDialogOpen] = useState(false) + const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false) + const [isViewDialogOpen, setIsViewDialogOpen] = useState(false) + const [isEditDialogOpen, setIsEditDialogOpen] = useState(false) + const [selectedJob, setSelectedJob] = useState(null) + const [editForm, setEditForm] = useState>({}) const [isLoading, setIsLoading] = useState(true) const [errorMessage, setErrorMessage] = useState(null) @@ -97,8 +101,54 @@ export default function AdminJobsPage() { [jobRows], ) - const handleDeleteJob = (id: string) => { - setJobs((prevJobs) => prevJobs.filter((job) => String(job.id) !== id)) + const handleViewJob = (job: AdminJobRow) => { + setSelectedJob(job) + setIsViewDialogOpen(true) + } + + const handleEditJob = (job: AdminJobRow) => { + setSelectedJob(job) + // Find original admin job to populate edit form correctly if needed, or just use row data + // Converting row data back to partial AdminJob for editing + setEditForm({ + title: job.title, + description: job.description, + // Add other fields as necessary + }) + setIsEditDialogOpen(true) + } + + const handleDeleteJob = async (idStr: string) => { + if (!confirm("Are you sure you want to delete this job?")) return + + const id = parseInt(idStr) + if (isNaN(id)) return + + try { + await adminJobsApi.delete(id) + setJobs((prevJobs) => prevJobs.filter((job) => job.id !== id)) + } catch (error) { + console.error("Failed to delete job:", error) + alert("Failed to delete job") + } + } + + const handleSaveEdit = async () => { + if (!selectedJob) return + const id = parseInt(selectedJob.id) + if (isNaN(id)) return + + try { + setIsLoading(true) + const updated = await adminJobsApi.update(id, editForm) + setJobs((prev) => prev.map((j) => (j.id === id ? updated : j))) + setIsEditDialogOpen(false) + } catch (error) { + console.error("Failed to update job:", error) + alert("Failed to update job") + } finally { + setIsLoading(false) + } } return ( @@ -109,7 +159,7 @@ export default function AdminJobsPage() {

Job management

Manage all jobs posted on the platform

- + - + + + + + + {/* View Job Dialog */} + + + + Job Details + + {selectedJob && ( +
+
+
+ +

{selectedJob.title}

+
+
+ +

{selectedJob.company}

+
+
+ +

{selectedJob.location}

+
+
+ +

{selectedJob.type}

+
+
+ +

{selectedJob.status}

+
+
+ +

{selectedJob.applicationsCount}

+
+
+
+ +
+ {selectedJob.description} +
+
+
+ )} + + + +
+
+ + {/* Edit Job Dialog */} + + + + Edit Job + Update job details + +
+
+ + setEditForm({ ...editForm, title: e.target.value })} + /> +
+
+ +