import React, { useState } from 'react'; import { Head, Link, useForm } from '@inertiajs/react'; import EmployerLayout from '@/Layouts/EmployerLayout'; import { Plus, ArrowLeft, Briefcase, MapPin, DollarSign, Calendar, LayoutGrid, Users, FileText, Sparkles, ShieldCheck, Save } from 'lucide-react'; import { toast } from 'sonner'; export default function Edit({ job }) { const { data, setData, post, processing, errors } = useForm({ title: job.title || '', workers_needed: job.workers_needed || 1, location: job.location || '', salary: job.salary ? Math.round(job.salary) : '', job_type: job.job_type || 'Full Time', start_date: job.start_date || '', description: job.description || '', requirements: job.requirements || '', status: job.status || 'active' }); const [clientErrors, setClientErrors] = useState({}); const handleSubmit = (e) => { e.preventDefault(); // Client-side validation const newErrors = {}; if (!data.title.trim()) { newErrors.title = 'Job title is required.'; } if (!data.workers_needed || data.workers_needed < 1) { newErrors.workers_needed = 'Workers needed must be at least 1.'; } if (!data.location.trim()) { newErrors.location = 'Job location is required.'; } if (!data.salary || data.salary < 0) { newErrors.salary = 'Monthly salary must be a positive number.'; } if (!data.start_date) { newErrors.start_date = 'Start date is required.'; } if (!data.description.trim()) { newErrors.description = 'Job description is required.'; } if (!data.status) { newErrors.status = 'Status is required.'; } if (Object.keys(newErrors).length > 0) { setClientErrors(newErrors); toast.error('Validation failed. Please correct the fields in red.'); return; } setClientErrors({}); post(`/employer/jobs/${job.id}/edit`, { onSuccess: () => { toast.success('Job updated successfully.'); }, onError: () => { toast.error('Failed to update job. Please check the inputs.'); } }); }; return (
Back to My Jobs

Edit Job Posting

Update details for "{job.title}"

{/* Section 1: Basic Info */}

Basic Information

setData('title', e.target.value)} />
{(clientErrors.title || errors.title) && (

{clientErrors.title || errors.title}

)}
setData('workers_needed', e.target.value)} />
{(clientErrors.workers_needed || errors.workers_needed) && (

{clientErrors.workers_needed || errors.workers_needed}

)}
{['Full Time', 'Part Time', 'Contract'].map(type => ( ))}
{[ { key: 'active', label: 'Active' }, { key: 'closed', label: 'Closed' }, { key: 'draft', label: 'Draft' } ].map(s => ( ))}
{/* Section 2: Logistics & Pay */}

Logistics & Compensation

setData('location', e.target.value)} />
{(clientErrors.location || errors.location) && (

{clientErrors.location || errors.location}

)}
setData('salary', e.target.value)} />
{(clientErrors.salary || errors.salary) && (

{clientErrors.salary || errors.salary}

)}
setData('start_date', e.target.value)} />
{(clientErrors.start_date || errors.start_date) && (

{clientErrors.start_date || errors.start_date}

)}
{/* Section 3: Details */}

Detailed Requirements