fix(frontend): enable job delete/update API calls and add logging
- Added update() and delete() methods to jobsApi in api.ts - Fixed handleDeleteJob to call jobsApi.delete() instead of just local state - Fixed handleSaveEdit to call jobsApi.update() instead of being commented out - Added console logging to all CRUD operations for debugging
This commit is contained in:
parent
930c57a9c7
commit
cb6afe9583
2 changed files with 34 additions and 6 deletions
|
|
@ -20,7 +20,7 @@ import { Label } from "@/components/ui/label"
|
||||||
import { Textarea } from "@/components/ui/textarea"
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
|
||||||
import { Plus, Search, Edit, Trash2, Eye, ChevronLeft, ChevronRight } from "lucide-react"
|
import { Plus, Search, Edit, Trash2, Eye, ChevronLeft, ChevronRight } from "lucide-react"
|
||||||
import { adminJobsApi, adminCompaniesApi, type AdminJob, type AdminCompany } from "@/lib/api"
|
import { adminJobsApi, adminCompaniesApi, jobsApi, type AdminJob, type AdminCompany } from "@/lib/api"
|
||||||
|
|
||||||
type AdminJobRow = {
|
type AdminJobRow = {
|
||||||
id: string
|
id: string
|
||||||
|
|
@ -174,33 +174,45 @@ export default function AdminJobsPage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDeleteJob = async (id: string) => {
|
const handleDeleteJob = async (id: string) => {
|
||||||
|
console.log("[JOBS_PAGE] handleDeleteJob called with id:", id)
|
||||||
if (!confirm("Are you sure you want to delete this job?")) return
|
if (!confirm("Are you sure you want to delete this job?")) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// await adminJobsApi.delete(id)
|
console.log("[JOBS_PAGE] Calling jobsApi.delete...")
|
||||||
|
await jobsApi.delete(id)
|
||||||
|
console.log("[JOBS_PAGE] Job deleted successfully, updating local state")
|
||||||
setJobs((prevJobs) => prevJobs.filter((job) => job.id !== id))
|
setJobs((prevJobs) => prevJobs.filter((job) => job.id !== id))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to delete job:", error)
|
console.error("[JOBS_PAGE] Failed to delete job:", error)
|
||||||
alert("Failed to delete job")
|
alert("Failed to delete job")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const handleSaveEdit = async () => {
|
const handleSaveEdit = async () => {
|
||||||
if (!selectedJob) return
|
if (!selectedJob) return
|
||||||
|
|
||||||
|
console.log("[JOBS_PAGE] handleSaveEdit called for job:", selectedJob.id)
|
||||||
|
console.log("[JOBS_PAGE] Edit form data:", editForm)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
// const updated = await adminJobsApi.update(selectedJob.id, editForm)
|
console.log("[JOBS_PAGE] Calling jobsApi.update...")
|
||||||
// setJobs((prev) => prev.map((j) => (j.id === selectedJob.id ? updated : j)))
|
const updated = await jobsApi.update(selectedJob.id, editForm)
|
||||||
|
console.log("[JOBS_PAGE] Job updated successfully:", updated)
|
||||||
|
// Reload jobs to get fresh data
|
||||||
|
const jobsData = await adminJobsApi.list({ limit: 10, page: 1 })
|
||||||
|
setJobs(jobsData.data ?? [])
|
||||||
setIsEditDialogOpen(false)
|
setIsEditDialogOpen(false)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to update job:", error)
|
console.error("[JOBS_PAGE] Failed to update job:", error)
|
||||||
alert("Failed to update job")
|
alert("Failed to update job")
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const handlePreviousPage = () => {
|
const handlePreviousPage = () => {
|
||||||
if (page > 1) setPage(page - 1)
|
if (page > 1) setPage(page - 1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -349,8 +349,24 @@ export const jobsApi = {
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
update: (id: string, data: Partial<CreateJobPayload>) => {
|
||||||
|
logCrudAction("update", "jobs", { id, ...data });
|
||||||
|
console.log("[JOBS_API] Updating job:", id, data);
|
||||||
|
return apiRequest<ApiJob>(`/api/v1/jobs/${id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
delete: (id: string) => {
|
||||||
|
logCrudAction("delete", "jobs", { id });
|
||||||
|
console.log("[JOBS_API] Deleting job:", id);
|
||||||
|
return apiRequest<void>(`/api/v1/jobs/${id}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const applicationsApi = {
|
export const applicationsApi = {
|
||||||
create: (data: any) =>
|
create: (data: any) =>
|
||||||
apiRequest<void>("/api/v1/applications", {
|
apiRequest<void>("/api/v1/applications", {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue