import React, { useState, useMemo } from 'react';
import { Head, Link, router } from '@inertiajs/react';
import EmployerLayout from '@/Layouts/EmployerLayout';
import {
Plus,
Search,
Filter,
Download,
MoreHorizontal,
MapPin,
DollarSign,
Users,
Calendar,
Briefcase,
CheckCircle2,
XCircle,
Clock,
Eye,
Edit2,
Trash2,
LayoutGrid,
List,
Shield,
Navigation,
Layers
} from 'lucide-react';
import { Badge } from '@/components/ui/badge';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { toast } from 'sonner';
// Helper function to map jobs dynamically to categories and skills based on title
const getJobMetadata = (title = '') => {
const t = title.toLowerCase();
if (t.includes('electrician') || t.includes('electrical')) {
return {
category: 'Skilled Worker',
skills: ['Electrical Wiring', 'Maintenance', 'Safety Inspection', 'Wiring Diagrams']
};
}
if (t.includes('clean') || t.includes('housekeep') || t.includes('maid') || t.includes('laundry')) {
return {
category: 'General Worker',
skills: ['Cleaning', 'Housekeeping', 'Laundry', 'Sanitization']
};
}
if (t.includes('plumb')) {
return {
category: 'Skilled Worker',
skills: ['Plumbing', 'Pipe Fitting', 'Leak Repair', 'Blueprint Reading']
};
}
if (t.includes('security') || t.includes('guard') || t.includes('watchman')) {
return {
category: 'Security',
skills: ['Security', 'Surveillance', 'Access Control', 'Patrolling']
};
}
if (t.includes('driver') || t.includes('chauffeur') || t.includes('delivery')) {
return {
category: 'Driver',
skills: ['Driving', 'Route Knowledge', 'Vehicle Safety', 'Navigation']
};
}
if (t.includes('mason') || t.includes('carpenter') || t.includes('woodwork') || t.includes('construction')) {
return {
category: 'Skilled Worker',
skills: ['Carpentry', 'Woodwork', 'Masonry', 'Tool Operation']
};
}
if (t.includes('store') || t.includes('warehouse') || t.includes('inventory') || t.includes('keeper')) {
return {
category: 'Logistics',
skills: ['Inventory', 'Stock Management', 'Packaging', 'Labeling']
};
}
if (t.includes('helper') || t.includes('labor') || t.includes('assistant')) {
return {
category: 'General Worker',
skills: ['Loading', 'Unloading', 'Physical Labor', 'Material Handling']
};
}
// Fallback
return {
category: 'Skilled Worker',
skills: ['General Support', 'Task Execution', 'Operations']
};
};
export default function Index({ initialJobs }) {
const [searchTerm, setSearchTerm] = useState('');
const [statusFilter, setStatusFilter] = useState('All');
const [categoryFilter, setCategoryFilter] = useState('All');
const [skillFilter, setSkillFilter] = useState('All');
const [viewMode, setViewMode] = useState('grid');
const [jobs, setJobs] = useState(initialJobs || []);
const handleDelete = (jobId) => {
if (confirm('Are you sure you want to delete this job posting? This action cannot be undone.')) {
router.delete(`/employer/jobs/${jobId}`, {
onSuccess: () => {
toast.success('Job deleted successfully.');
},
onError: () => {
toast.error('Failed to delete job.');
}
});
}
};
// Derived category list
const categories = ['All', 'Skilled Worker', 'General Worker', 'Security', 'Driver', 'Logistics'];
// Derived skills list
const skills = [
'All',
'Electrical Wiring',
'Cleaning',
'Housekeeping',
'Plumbing',
'Pipe Fitting',
'Security',
'Surveillance',
'Driving',
'Route Knowledge',
'Carpentry',
'Woodwork',
'Inventory',
'Stock Management',
'Loading',
'Unloading'
];
const filteredJobs = useMemo(() => {
return jobs.filter(job => {
const meta = getJobMetadata(job.title);
const matchesSearch = job.title.toLowerCase().includes(searchTerm.toLowerCase()) ||
job.location.toLowerCase().includes(searchTerm.toLowerCase());
const matchesStatus = statusFilter === 'All' || job.status.toLowerCase() === statusFilter.toLowerCase();
const matchesCategory = categoryFilter === 'All' || meta.category === categoryFilter;
const matchesSkill = skillFilter === 'All' || meta.skills.includes(skillFilter);
return matchesSearch && matchesStatus && matchesCategory && matchesSkill;
});
}, [jobs, searchTerm, statusFilter, categoryFilter, skillFilter]);
return (
Manage and track your recruitment status