diff --git a/apps/admin/app/(main)/jobs/page.tsx b/apps/admin/app/(main)/jobs/page.tsx index cf6fe0f..652fbc6 100644 --- a/apps/admin/app/(main)/jobs/page.tsx +++ b/apps/admin/app/(main)/jobs/page.tsx @@ -26,8 +26,28 @@ async function getAllJobsWithCompany() { }); } -export default async function JobsListPage() { +export default async function JobsListPage({ + searchParams, +}: { + searchParams?: { q?: string; status?: string; companyId?: string }; +}) { const jobsWithCompany = await getAllJobsWithCompany(); + const companiesList = await db.query.companies.findMany({ columns: { id: true, name: true } }); + + const q = (searchParams?.q ?? '').toLowerCase(); + const status = searchParams?.status ?? 'all'; + const companyId = Number(searchParams?.companyId ?? '0'); + + const filteredJobs = jobsWithCompany.filter((job) => { + if (status === 'active' && !job.active) return false; + if (status === 'inactive' && job.active) return false; + if (!Number.isNaN(companyId) && companyId > 0 && job.companyId !== companyId) return false; + if (q) { + const hay = `${job.title} ${job.company?.name ?? ''} ${job.location}`.toLowerCase(); + if (!hay.includes(q)) return false; + } + return true; + }); return (