From bb28ff4fe8d237a1b174acb1cbf3bde6acab4fea Mon Sep 17 00:00:00 2001 From: Unchanted Date: Tue, 2 Sep 2025 17:59:13 +0530 Subject: [PATCH] feat(tpo): added job listing filter --- apps/admin/app/(main)/jobs/page.tsx | 73 +++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 15 deletions(-) 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 (
@@ -52,24 +72,47 @@ export default async function JobsListPage() { {/* Search and Filters Section */}
-
-
+
+
-
- - - {jobsWithCompany.length} Jobs - +
+
-
+
+ +
+ + + Reset + + + {filteredJobs.length} / {jobsWithCompany.length} Jobs + +
@@ -91,7 +134,7 @@ export default async function JobsListPage() {
) : (
- {jobsWithCompany.map((job) => ( + {filteredJobs.map((job) => (