From 101c2358556c66fd747b250d8205ed9335faa9a3 Mon Sep 17 00:00:00 2001 From: ARJUN S THAMPI <61703062+arjun-thampi@users.noreply.github.com> Date: Tue, 17 Mar 2026 17:08:05 +0530 Subject: [PATCH] feat: doctor search filter functionality added --- frontend/src/pages/Doctor.tsx | 102 ++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 35 deletions(-) diff --git a/frontend/src/pages/Doctor.tsx b/frontend/src/pages/Doctor.tsx index 57c4a56..8c94639 100644 --- a/frontend/src/pages/Doctor.tsx +++ b/frontend/src/pages/Doctor.tsx @@ -17,7 +17,6 @@ import { TableHeader, TableRow, } from "@/components/ui/table"; -import {ScrollArea} from "@/components/ui/scroll-area"; import {Card, CardContent, CardHeader, CardTitle} from "@/components/ui/card"; import {Button} from "@/components/ui/button"; @@ -37,8 +36,9 @@ import { CommandItem, CommandInput, } from "@/components/ui/command"; + import {Input} from "@/components/ui/input"; -import {Loader2, Plus, Pencil, Trash} from "lucide-react"; +import {Loader2, Plus, Pencil, Trash, RefreshCw} from "lucide-react"; interface Department { departmentId: string; @@ -51,7 +51,9 @@ export default function DoctorPage() { const [loading, setLoading] = useState(true); const [openModal, setOpenModal] = useState(false); const [editing, setEditing] = useState(null); - const [search, setSearch] = useState(""); + + const [searchText, setSearchText] = useState(""); + const [filterDepartment, setFilterDepartment] = useState(""); const [form, setForm] = useState({ doctorId: "", @@ -83,6 +85,18 @@ export default function DoctorPage() { fetchAll(); }, [fetchAll]); + const filteredDoctors = doctors.filter((doc) => { + const matchesSearch = + doc.name.toLowerCase().includes(searchText.toLowerCase()) || + doc.doctorId.toLowerCase().includes(searchText.toLowerCase()); + + const matchesDepartment = filterDepartment + ? doc.departments?.some((d: any) => d.departmentId === filterDepartment) + : true; + + return matchesSearch && matchesDepartment; + }); + function handleChange(e: any) { setForm({...form, [e.target.name]: e.target.value}); } @@ -100,13 +114,7 @@ export default function DoctorPage() { } else { setForm({ ...form, - departments: [ - ...form.departments, - { - departmentId: depId, - timing: {}, - }, - ], + departments: [...form.departments, {departmentId: depId, timing: {}}], }); } } @@ -118,10 +126,7 @@ export default function DoctorPage() { d.departmentId === depId ? { ...d, - timing: { - ...d.timing, - [day]: value, - }, + timing: {...d.timing, [day]: value}, } : d, ), @@ -146,7 +151,6 @@ export default function DoctorPage() { try { const timingRes = await getDoctorTimingApi(doc.doctorId); - const timingData = timingRes?.data?.departments || []; const mappedDepartments = timingData.map((d: any) => ({ @@ -171,19 +175,10 @@ export default function DoctorPage() { async function handleSubmit() { try { - const payload = { - doctorId: form.doctorId, - name: form.name, - designation: form.designation, - workingStatus: form.workingStatus, - qualification: form.qualification, - departments: form.departments, - }; - if (editing) { - await updateDoctorApi(editing.doctorId, payload); + await updateDoctorApi(editing.doctorId, form); } else { - await createDoctorApi(payload); + await createDoctorApi(form); } setOpenModal(false); @@ -201,23 +196,52 @@ export default function DoctorPage() { return (
-
+ {/* HEADER */} +

Doctors

- +
+ setSearchText(e.target.value)} + className="w-[200px]" + /> + + + + + + +
+ {/* TABLE */} Doctor List -
- +
+
ID @@ -238,8 +262,14 @@ export default function DoctorPage() { + ) : filteredDoctors.length === 0 ? ( + + + No doctors found + + ) : ( - doctors.map((doc) => ( + filteredDoctors.map((doc) => ( {doc.doctorId} {doc.name} @@ -256,7 +286,8 @@ export default function DoctorPage() { {doc.departments?.map((d: any) => (
- {d.departmentName}: {d.timing} + {d.departmentName}:{" "} + {JSON.stringify(d.timing)}
))}
@@ -287,6 +318,7 @@ export default function DoctorPage() { + {/* MODAL */} {/* MODAL */}