feat: doctor search filter functionality added
This commit is contained in:
@@ -17,7 +17,6 @@ import {
|
|||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import {ScrollArea} from "@/components/ui/scroll-area";
|
|
||||||
|
|
||||||
import {Card, CardContent, CardHeader, CardTitle} from "@/components/ui/card";
|
import {Card, CardContent, CardHeader, CardTitle} from "@/components/ui/card";
|
||||||
import {Button} from "@/components/ui/button";
|
import {Button} from "@/components/ui/button";
|
||||||
@@ -37,8 +36,9 @@ import {
|
|||||||
CommandItem,
|
CommandItem,
|
||||||
CommandInput,
|
CommandInput,
|
||||||
} from "@/components/ui/command";
|
} from "@/components/ui/command";
|
||||||
|
|
||||||
import {Input} from "@/components/ui/input";
|
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 {
|
interface Department {
|
||||||
departmentId: string;
|
departmentId: string;
|
||||||
@@ -51,7 +51,9 @@ export default function DoctorPage() {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [openModal, setOpenModal] = useState(false);
|
const [openModal, setOpenModal] = useState(false);
|
||||||
const [editing, setEditing] = useState<any>(null);
|
const [editing, setEditing] = useState<any>(null);
|
||||||
const [search, setSearch] = useState("");
|
|
||||||
|
const [searchText, setSearchText] = useState("");
|
||||||
|
const [filterDepartment, setFilterDepartment] = useState("");
|
||||||
|
|
||||||
const [form, setForm] = useState<any>({
|
const [form, setForm] = useState<any>({
|
||||||
doctorId: "",
|
doctorId: "",
|
||||||
@@ -83,6 +85,18 @@ export default function DoctorPage() {
|
|||||||
fetchAll();
|
fetchAll();
|
||||||
}, [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) {
|
function handleChange(e: any) {
|
||||||
setForm({...form, [e.target.name]: e.target.value});
|
setForm({...form, [e.target.name]: e.target.value});
|
||||||
}
|
}
|
||||||
@@ -100,13 +114,7 @@ export default function DoctorPage() {
|
|||||||
} else {
|
} else {
|
||||||
setForm({
|
setForm({
|
||||||
...form,
|
...form,
|
||||||
departments: [
|
departments: [...form.departments, {departmentId: depId, timing: {}}],
|
||||||
...form.departments,
|
|
||||||
{
|
|
||||||
departmentId: depId,
|
|
||||||
timing: {},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,10 +126,7 @@ export default function DoctorPage() {
|
|||||||
d.departmentId === depId
|
d.departmentId === depId
|
||||||
? {
|
? {
|
||||||
...d,
|
...d,
|
||||||
timing: {
|
timing: {...d.timing, [day]: value},
|
||||||
...d.timing,
|
|
||||||
[day]: value,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
: d,
|
: d,
|
||||||
),
|
),
|
||||||
@@ -146,7 +151,6 @@ export default function DoctorPage() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const timingRes = await getDoctorTimingApi(doc.doctorId);
|
const timingRes = await getDoctorTimingApi(doc.doctorId);
|
||||||
|
|
||||||
const timingData = timingRes?.data?.departments || [];
|
const timingData = timingRes?.data?.departments || [];
|
||||||
|
|
||||||
const mappedDepartments = timingData.map((d: any) => ({
|
const mappedDepartments = timingData.map((d: any) => ({
|
||||||
@@ -171,19 +175,10 @@ export default function DoctorPage() {
|
|||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
try {
|
try {
|
||||||
const payload = {
|
|
||||||
doctorId: form.doctorId,
|
|
||||||
name: form.name,
|
|
||||||
designation: form.designation,
|
|
||||||
workingStatus: form.workingStatus,
|
|
||||||
qualification: form.qualification,
|
|
||||||
departments: form.departments,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (editing) {
|
if (editing) {
|
||||||
await updateDoctorApi(editing.doctorId, payload);
|
await updateDoctorApi(editing.doctorId, form);
|
||||||
} else {
|
} else {
|
||||||
await createDoctorApi(payload);
|
await createDoctorApi(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
setOpenModal(false);
|
setOpenModal(false);
|
||||||
@@ -201,23 +196,52 @@ export default function DoctorPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-6 space-y-6">
|
||||||
<div className="flex justify-between items-center">
|
{/* HEADER */}
|
||||||
|
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-3">
|
||||||
<h1 className="text-2xl font-bold">Doctors</h1>
|
<h1 className="text-2xl font-bold">Doctors</h1>
|
||||||
|
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
<Input
|
||||||
|
placeholder="Search doctor..."
|
||||||
|
value={searchText}
|
||||||
|
onChange={(e) => setSearchText(e.target.value)}
|
||||||
|
className="w-[200px]"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<select
|
||||||
|
value={filterDepartment}
|
||||||
|
onChange={(e) => setFilterDepartment(e.target.value)}
|
||||||
|
className="border rounded px-2 py-1"
|
||||||
|
>
|
||||||
|
<option value="">All Departments</option>
|
||||||
|
{departments.map((dep) => (
|
||||||
|
<option key={dep.departmentId} value={dep.departmentId}>
|
||||||
|
{dep.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<Button variant="outline" onClick={fetchAll} disabled={loading}>
|
||||||
|
<RefreshCw className="mr-2 h-4 w-4" />
|
||||||
|
Refresh
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button onClick={openAdd}>
|
<Button onClick={openAdd}>
|
||||||
<Plus className="mr-2 h-4 w-4" />
|
<Plus className="mr-2 h-4 w-4" />
|
||||||
Add Doctor
|
Add Doctor
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* TABLE */}
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Doctor List</CardTitle>
|
<CardTitle>Doctor List</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="tw-overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<Table className="tw-min-w-[1000px]">
|
<Table className="min-w-[1000px]">
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead>ID</TableHead>
|
<TableHead>ID</TableHead>
|
||||||
@@ -238,8 +262,14 @@ export default function DoctorPage() {
|
|||||||
<Loader2 className="h-6 w-6 animate-spin mx-auto" />
|
<Loader2 className="h-6 w-6 animate-spin mx-auto" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
) : filteredDoctors.length === 0 ? (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={8} className="text-center">
|
||||||
|
No doctors found
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
) : (
|
) : (
|
||||||
doctors.map((doc) => (
|
filteredDoctors.map((doc) => (
|
||||||
<TableRow key={doc.doctorId}>
|
<TableRow key={doc.doctorId}>
|
||||||
<TableCell>{doc.doctorId}</TableCell>
|
<TableCell>{doc.doctorId}</TableCell>
|
||||||
<TableCell>{doc.name}</TableCell>
|
<TableCell>{doc.name}</TableCell>
|
||||||
@@ -256,7 +286,8 @@ export default function DoctorPage() {
|
|||||||
<TableCell className="max-w-[250px] whitespace-normal">
|
<TableCell className="max-w-[250px] whitespace-normal">
|
||||||
{doc.departments?.map((d: any) => (
|
{doc.departments?.map((d: any) => (
|
||||||
<div key={d.departmentId}>
|
<div key={d.departmentId}>
|
||||||
<b>{d.departmentName}:</b> {d.timing}
|
<b>{d.departmentName}:</b>{" "}
|
||||||
|
{JSON.stringify(d.timing)}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
@@ -287,6 +318,7 @@ export default function DoctorPage() {
|
|||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
{/* MODAL */}
|
||||||
{/* MODAL */}
|
{/* MODAL */}
|
||||||
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
||||||
<DialogContent className="overflow-y-auto max-h-[80vh] ">
|
<DialogContent className="overflow-y-auto max-h-[80vh] ">
|
||||||
|
|||||||
Reference in New Issue
Block a user