2026-04-08 16:30:50 +05:30
|
|
|
import { useState, useEffect, useCallback } from "react";
|
|
|
|
|
import { AxiosError } from "axios";
|
2026-04-14 17:33:21 +05:30
|
|
|
|
|
|
|
|
import { BytescaleUploader } from "@/components/BytescaleUploader/BytescaleUploader";
|
|
|
|
|
|
2026-03-17 13:11:00 +05:30
|
|
|
import {
|
|
|
|
|
getDoctorsApi,
|
|
|
|
|
createDoctorApi,
|
|
|
|
|
updateDoctorApi,
|
|
|
|
|
getDoctorTimingApi,
|
|
|
|
|
} from "@/api/doctor";
|
2026-04-08 16:30:50 +05:30
|
|
|
import { getDepartmentsApi } from "@/api/department";
|
2026-03-17 13:11:00 +05:30
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
Table,
|
|
|
|
|
TableBody,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableHead,
|
|
|
|
|
TableHeader,
|
|
|
|
|
TableRow,
|
|
|
|
|
} from "@/components/ui/table";
|
2026-04-08 16:30:50 +05:30
|
|
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
2026-03-17 13:11:00 +05:30
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
} from "@/components/ui/dialog";
|
2026-04-08 16:30:50 +05:30
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
2026-05-11 00:04:22 +05:30
|
|
|
import { Switch } from "@/components/ui/switch";
|
|
|
|
|
import { Label } from "@/components/ui/label";
|
|
|
|
|
|
2026-04-08 16:30:50 +05:30
|
|
|
import {
|
|
|
|
|
Loader2,
|
|
|
|
|
RefreshCw,
|
|
|
|
|
Plus,
|
|
|
|
|
Pencil,
|
|
|
|
|
ChevronLeft,
|
|
|
|
|
ChevronRight,
|
|
|
|
|
} from "lucide-react";
|
2026-03-17 13:11:00 +05:30
|
|
|
|
|
|
|
|
interface Department {
|
|
|
|
|
departmentId: string;
|
|
|
|
|
name: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 17:46:31 +05:30
|
|
|
const DAYS = [
|
|
|
|
|
"monday",
|
|
|
|
|
"tuesday",
|
|
|
|
|
"wednesday",
|
|
|
|
|
"thursday",
|
|
|
|
|
"friday",
|
|
|
|
|
"saturday",
|
|
|
|
|
"sunday",
|
|
|
|
|
"additional",
|
|
|
|
|
];
|
|
|
|
|
|
2026-03-17 13:11:00 +05:30
|
|
|
export default function DoctorPage() {
|
|
|
|
|
const [doctors, setDoctors] = useState<any[]>([]);
|
|
|
|
|
const [departments, setDepartments] = useState<Department[]>([]);
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
2026-04-06 17:46:31 +05:30
|
|
|
const [error, setError] = useState("");
|
|
|
|
|
|
2026-03-17 13:11:00 +05:30
|
|
|
const [openModal, setOpenModal] = useState(false);
|
|
|
|
|
const [editing, setEditing] = useState<any>(null);
|
2026-03-17 17:08:05 +05:30
|
|
|
|
|
|
|
|
const [searchText, setSearchText] = useState("");
|
|
|
|
|
const [filterDepartment, setFilterDepartment] = useState("");
|
2026-03-17 13:11:00 +05:30
|
|
|
|
2026-04-08 16:30:50 +05:30
|
|
|
const [currentPage, setCurrentPage] = useState(1);
|
|
|
|
|
const itemsPerPage = 10;
|
|
|
|
|
|
2026-03-17 13:11:00 +05:30
|
|
|
const [form, setForm] = useState<any>({
|
|
|
|
|
doctorId: "",
|
|
|
|
|
name: "",
|
2026-04-14 17:33:21 +05:30
|
|
|
image: "",
|
2026-03-17 13:11:00 +05:30
|
|
|
designation: "",
|
|
|
|
|
workingStatus: "",
|
|
|
|
|
qualification: "",
|
2026-05-11 00:04:22 +05:30
|
|
|
isActive: true,
|
|
|
|
|
globalSortOrder: 0,
|
2026-03-17 13:11:00 +05:30
|
|
|
departments: [],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const fetchAll = useCallback(async () => {
|
|
|
|
|
setLoading(true);
|
2026-04-06 17:46:31 +05:30
|
|
|
setError("");
|
2026-03-17 13:11:00 +05:30
|
|
|
try {
|
|
|
|
|
const [docRes, depRes] = await Promise.all([
|
|
|
|
|
getDoctorsApi(),
|
|
|
|
|
getDepartmentsApi(),
|
|
|
|
|
]);
|
|
|
|
|
setDoctors(docRes?.data || []);
|
|
|
|
|
setDepartments(depRes?.data || []);
|
|
|
|
|
} catch (err) {
|
2026-04-06 17:46:31 +05:30
|
|
|
if (err instanceof AxiosError) {
|
|
|
|
|
setError(err.response?.data?.message || "Failed to load data");
|
|
|
|
|
} else {
|
|
|
|
|
setError("Something went wrong");
|
|
|
|
|
}
|
2026-03-17 13:11:00 +05:30
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchAll();
|
|
|
|
|
}, [fetchAll]);
|
|
|
|
|
|
2026-05-11 16:27:20 +05:30
|
|
|
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;
|
|
|
|
|
})
|
|
|
|
|
.sort((a, b) => {
|
|
|
|
|
if (!filterDepartment) {
|
|
|
|
|
return a.globalSortOrder - b.globalSortOrder;
|
|
|
|
|
}
|
2026-03-17 17:08:05 +05:30
|
|
|
|
2026-05-11 16:27:20 +05:30
|
|
|
const aDept = a.departments.find(
|
|
|
|
|
(d: any) => d.departmentId === filterDepartment,
|
|
|
|
|
);
|
2026-03-17 17:08:05 +05:30
|
|
|
|
2026-05-11 16:27:20 +05:30
|
|
|
const bDept = b.departments.find(
|
|
|
|
|
(d: any) => d.departmentId === filterDepartment,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
(aDept?.deptSortOrder ?? Number.MAX_SAFE_INTEGER) -
|
|
|
|
|
(bDept?.deptSortOrder ?? Number.MAX_SAFE_INTEGER)
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-03-17 17:08:05 +05:30
|
|
|
|
2026-04-08 16:30:50 +05:30
|
|
|
useEffect(() => {
|
|
|
|
|
setCurrentPage(1);
|
|
|
|
|
}, [searchText, filterDepartment]);
|
|
|
|
|
|
|
|
|
|
const totalPages = Math.ceil(filteredDoctors.length / itemsPerPage);
|
|
|
|
|
const indexOfLastItem = currentPage * itemsPerPage;
|
|
|
|
|
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
|
|
|
|
|
const currentItems = filteredDoctors.slice(indexOfFirstItem, indexOfLastItem);
|
|
|
|
|
|
2026-03-17 13:11:00 +05:30
|
|
|
function handleChange(e: any) {
|
2026-05-11 00:04:22 +05:30
|
|
|
const value =
|
|
|
|
|
e.target.type === "number" ? Number(e.target.value) : e.target.value;
|
|
|
|
|
setForm({ ...form, [e.target.name]: value });
|
2026-03-17 13:11:00 +05:30
|
|
|
}
|
|
|
|
|
|
2026-05-11 10:52:30 +05:30
|
|
|
const handleToggleStatus = async (doc: any) => {
|
|
|
|
|
try {
|
|
|
|
|
const updatedDoc = { ...doc, isActive: !doc.isActive };
|
|
|
|
|
await updateDoctorApi(doc.doctorId, updatedDoc);
|
|
|
|
|
fetchAll();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Failed to update status", err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-06 17:46:31 +05:30
|
|
|
function handleDepartmentToggle(depId: string) {
|
2026-03-17 16:22:37 +05:30
|
|
|
const exists = form.departments.find((d: any) => d.departmentId === depId);
|
|
|
|
|
if (exists) {
|
|
|
|
|
setForm({
|
|
|
|
|
...form,
|
|
|
|
|
departments: form.departments.filter(
|
|
|
|
|
(d: any) => d.departmentId !== depId,
|
|
|
|
|
),
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
setForm({
|
|
|
|
|
...form,
|
2026-05-11 00:04:22 +05:30
|
|
|
departments: [
|
|
|
|
|
...form.departments,
|
|
|
|
|
{ departmentId: depId, sortOrder: 0, timing: {} },
|
|
|
|
|
],
|
2026-03-17 16:22:37 +05:30
|
|
|
});
|
|
|
|
|
}
|
2026-03-17 13:11:00 +05:30
|
|
|
}
|
|
|
|
|
|
2026-05-11 00:04:22 +05:30
|
|
|
function handleDeptSortChange(depId: string, value: string) {
|
|
|
|
|
setForm({
|
|
|
|
|
...form,
|
|
|
|
|
departments: form.departments.map((d: any) =>
|
|
|
|
|
d.departmentId === depId ? { ...d, sortOrder: Number(value) } : d,
|
|
|
|
|
),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 16:22:37 +05:30
|
|
|
function handleTimingChange(depId: string, day: string, value: string) {
|
2026-03-17 13:11:00 +05:30
|
|
|
setForm({
|
|
|
|
|
...form,
|
2026-03-17 16:22:37 +05:30
|
|
|
departments: form.departments.map((d: any) =>
|
|
|
|
|
d.departmentId === depId
|
2026-04-08 16:30:50 +05:30
|
|
|
? { ...d, timing: { ...d.timing, [day]: value } }
|
2026-03-17 16:22:37 +05:30
|
|
|
: d,
|
|
|
|
|
),
|
2026-03-17 13:11:00 +05:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function openAdd() {
|
|
|
|
|
setEditing(null);
|
|
|
|
|
setForm({
|
|
|
|
|
doctorId: "",
|
|
|
|
|
name: "",
|
2026-04-14 17:33:21 +05:30
|
|
|
image: "",
|
2026-03-17 13:11:00 +05:30
|
|
|
designation: "",
|
|
|
|
|
workingStatus: "",
|
|
|
|
|
qualification: "",
|
2026-05-11 00:04:22 +05:30
|
|
|
isActive: true,
|
|
|
|
|
globalSortOrder: 0,
|
2026-03-17 13:11:00 +05:30
|
|
|
departments: [],
|
|
|
|
|
});
|
|
|
|
|
setOpenModal(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function openEdit(doc: any) {
|
|
|
|
|
setEditing(doc);
|
|
|
|
|
try {
|
2026-03-17 16:22:37 +05:30
|
|
|
const timingRes = await getDoctorTimingApi(doc.doctorId);
|
|
|
|
|
const timingData = timingRes?.data?.departments || [];
|
2026-05-11 00:04:22 +05:30
|
|
|
|
2026-03-17 13:11:00 +05:30
|
|
|
setForm({
|
2026-03-17 16:22:37 +05:30
|
|
|
doctorId: doc.doctorId,
|
|
|
|
|
name: doc.name,
|
2026-04-14 17:33:21 +05:30
|
|
|
image: doc.image || "",
|
2026-03-17 16:22:37 +05:30
|
|
|
designation: doc.designation,
|
|
|
|
|
workingStatus: doc.workingStatus,
|
|
|
|
|
qualification: doc.qualification,
|
2026-05-11 00:04:22 +05:30
|
|
|
isActive: doc.isActive ?? true,
|
|
|
|
|
globalSortOrder: doc.globalSortOrder ?? 0,
|
2026-04-06 17:46:31 +05:30
|
|
|
departments: timingData.map((d: any) => ({
|
|
|
|
|
departmentId: d.departmentId,
|
2026-05-11 00:04:22 +05:30
|
|
|
sortOrder: d.deptSortOrder ?? 0,
|
2026-04-06 17:46:31 +05:30
|
|
|
timing: d.timing || {},
|
|
|
|
|
})),
|
2026-03-17 13:11:00 +05:30
|
|
|
});
|
|
|
|
|
setOpenModal(true);
|
|
|
|
|
} catch (err) {
|
2026-05-11 00:04:22 +05:30
|
|
|
console.error("Error fetching doctor details:", err);
|
2026-03-17 13:11:00 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function handleSubmit() {
|
|
|
|
|
try {
|
|
|
|
|
if (editing) {
|
2026-03-17 17:08:05 +05:30
|
|
|
await updateDoctorApi(editing.doctorId, form);
|
2026-03-17 13:11:00 +05:30
|
|
|
} else {
|
2026-03-17 17:08:05 +05:30
|
|
|
await createDoctorApi(form);
|
2026-03-17 13:11:00 +05:30
|
|
|
}
|
|
|
|
|
setOpenModal(false);
|
|
|
|
|
fetchAll();
|
2026-04-06 17:46:31 +05:30
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
2026-03-17 13:11:00 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="p-6 space-y-6">
|
2026-04-08 16:30:50 +05:30
|
|
|
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-4">
|
|
|
|
|
<h1 className="text-3xl font-bold">Doctors</h1>
|
2026-03-17 13:11:00 +05:30
|
|
|
|
2026-04-06 17:46:31 +05:30
|
|
|
<div className="flex flex-wrap gap-3">
|
2026-03-17 17:08:05 +05:30
|
|
|
<Input
|
|
|
|
|
placeholder="Search doctor..."
|
|
|
|
|
value={searchText}
|
|
|
|
|
onChange={(e) => setSearchText(e.target.value)}
|
2026-04-08 16:30:50 +05:30
|
|
|
className="w-[250px] text-base"
|
2026-03-17 17:08:05 +05:30
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<select
|
|
|
|
|
value={filterDepartment}
|
|
|
|
|
onChange={(e) => setFilterDepartment(e.target.value)}
|
2026-04-08 16:30:50 +05:30
|
|
|
className="flex h-10 w-[220px] rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
2026-03-17 17:08:05 +05:30
|
|
|
>
|
|
|
|
|
<option value="">All Departments</option>
|
|
|
|
|
{departments.map((dep) => (
|
|
|
|
|
<option key={dep.departmentId} value={dep.departmentId}>
|
|
|
|
|
{dep.name}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
|
2026-04-08 16:30:50 +05:30
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
onClick={fetchAll}
|
|
|
|
|
disabled={loading}
|
|
|
|
|
className="text-base"
|
|
|
|
|
>
|
|
|
|
|
<RefreshCw className="mr-2 h-5 w-5" />
|
2026-03-17 17:08:05 +05:30
|
|
|
Refresh
|
|
|
|
|
</Button>
|
|
|
|
|
|
2026-04-08 16:30:50 +05:30
|
|
|
<Button onClick={openAdd} className="text-base">
|
|
|
|
|
<Plus className="mr-2 h-5 w-5" />
|
2026-03-17 17:08:05 +05:30
|
|
|
Add Doctor
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2026-03-17 13:11:00 +05:30
|
|
|
</div>
|
|
|
|
|
|
2026-04-06 17:46:31 +05:30
|
|
|
{error && (
|
2026-04-08 16:30:50 +05:30
|
|
|
<div className="p-4 text-red-600 bg-red-50 border rounded-md text-base">
|
2026-04-06 17:46:31 +05:30
|
|
|
{error}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-03-17 13:11:00 +05:30
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
2026-04-08 16:30:50 +05:30
|
|
|
<CardTitle className="text-xl">Doctor List</CardTitle>
|
2026-03-17 13:11:00 +05:30
|
|
|
</CardHeader>
|
|
|
|
|
|
2026-04-08 16:30:50 +05:30
|
|
|
<CardContent className="p-0 sm:p-6 space-y-4">
|
|
|
|
|
<div className="rounded-md border overflow-x-auto overflow-y-auto max-h-[650px] relative">
|
2026-05-11 00:04:22 +05:30
|
|
|
<Table className="w-full min-w-[1100px] table-fixed border-separate border-spacing-0">
|
2026-04-08 16:30:50 +05:30
|
|
|
<TableHeader className="sticky top-0 z-20 bg-background shadow-sm">
|
2026-03-17 13:11:00 +05:30
|
|
|
<TableRow>
|
2026-05-11 00:04:22 +05:30
|
|
|
<TableHead className="w-[80px] bg-background text-sm font-bold">
|
|
|
|
|
Priority{" "}
|
2026-04-08 16:30:50 +05:30
|
|
|
</TableHead>
|
2026-05-11 10:52:30 +05:30
|
|
|
<TableHead className="w-[180px] bg-background text-sm font-bold">
|
2026-05-11 00:04:22 +05:30
|
|
|
Doctor Info
|
2026-04-08 16:30:50 +05:30
|
|
|
</TableHead>
|
2026-05-11 00:04:22 +05:30
|
|
|
<TableHead className="w-[150px] bg-background text-sm font-bold">
|
|
|
|
|
Designation
|
2026-04-08 16:30:50 +05:30
|
|
|
</TableHead>
|
|
|
|
|
<TableHead className="w-[220px] bg-background text-sm font-bold">
|
2026-05-11 00:04:22 +05:30
|
|
|
Departments (Hierarchy)
|
2026-04-08 16:30:50 +05:30
|
|
|
</TableHead>
|
2026-05-11 10:52:30 +05:30
|
|
|
<TableHead className="w-[80px] bg-background text-sm font-bold">
|
|
|
|
|
Status (Active)
|
|
|
|
|
</TableHead>
|
|
|
|
|
<TableHead className="w-[80px] bg-background text-right text-sm font-bold">
|
2026-04-08 16:30:50 +05:30
|
|
|
Actions
|
|
|
|
|
</TableHead>
|
2026-03-17 13:11:00 +05:30
|
|
|
</TableRow>
|
|
|
|
|
</TableHeader>
|
|
|
|
|
|
|
|
|
|
<TableBody>
|
|
|
|
|
{loading ? (
|
|
|
|
|
<TableRow>
|
2026-04-08 16:30:50 +05:30
|
|
|
<TableCell colSpan={6} className="text-center py-10">
|
|
|
|
|
<Loader2 className="h-8 w-8 animate-spin mx-auto" />
|
2026-03-17 13:11:00 +05:30
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
2026-04-08 16:30:50 +05:30
|
|
|
) : currentItems.length === 0 ? (
|
2026-03-17 17:08:05 +05:30
|
|
|
<TableRow>
|
2026-04-06 17:46:31 +05:30
|
|
|
<TableCell
|
|
|
|
|
colSpan={6}
|
2026-04-08 16:30:50 +05:30
|
|
|
className="text-center text-muted-foreground py-10 text-base"
|
2026-04-06 17:46:31 +05:30
|
|
|
>
|
2026-03-17 17:08:05 +05:30
|
|
|
No doctors found
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
2026-03-17 13:11:00 +05:30
|
|
|
) : (
|
2026-04-08 16:30:50 +05:30
|
|
|
currentItems.map((doc) => (
|
|
|
|
|
<TableRow key={doc.doctorId} className="hover:bg-muted/50">
|
2026-05-11 00:04:22 +05:30
|
|
|
<TableCell className="font-mono text-sm">
|
|
|
|
|
{doc.globalSortOrder}
|
2026-04-06 17:46:31 +05:30
|
|
|
</TableCell>
|
2026-03-17 16:22:37 +05:30
|
|
|
|
|
|
|
|
<TableCell>
|
2026-04-08 16:30:50 +05:30
|
|
|
<div
|
|
|
|
|
className="font-semibold text-base truncate"
|
|
|
|
|
title={doc.name}
|
|
|
|
|
>
|
2026-04-06 17:46:31 +05:30
|
|
|
{doc.name}
|
|
|
|
|
</div>
|
2026-05-11 00:04:22 +05:30
|
|
|
<div className="text-xs text-muted-foreground truncate font-mono">
|
|
|
|
|
{doc.doctorId}
|
2026-04-06 17:46:31 +05:30
|
|
|
</div>
|
2026-03-17 16:22:37 +05:30
|
|
|
</TableCell>
|
2026-03-17 13:11:00 +05:30
|
|
|
|
2026-04-06 17:46:31 +05:30
|
|
|
<TableCell>
|
2026-04-08 16:30:50 +05:30
|
|
|
<div
|
2026-05-11 00:04:22 +05:30
|
|
|
className="truncate text-sm font-medium"
|
|
|
|
|
title={doc.designation}
|
2026-04-08 16:30:50 +05:30
|
|
|
>
|
2026-05-11 00:04:22 +05:30
|
|
|
{doc.designation || "-"}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-xs italic text-muted-foreground truncate">
|
|
|
|
|
{doc.workingStatus}
|
2026-04-06 17:46:31 +05:30
|
|
|
</div>
|
|
|
|
|
</TableCell>
|
|
|
|
|
|
|
|
|
|
<TableCell>
|
2026-04-08 16:30:50 +05:30
|
|
|
<div className="flex flex-wrap gap-1">
|
2026-04-06 17:46:31 +05:30
|
|
|
{doc.departments?.map((d: any) => (
|
|
|
|
|
<Badge
|
|
|
|
|
key={d.departmentId}
|
|
|
|
|
variant="secondary"
|
2026-05-11 00:04:22 +05:30
|
|
|
className="text-xs px-2 h-6 leading-none flex items-center gap-1"
|
2026-04-06 17:46:31 +05:30
|
|
|
>
|
|
|
|
|
{d.departmentName}
|
2026-05-11 00:04:22 +05:30
|
|
|
<span className="bg-primary text-primary-foreground px-1 rounded-full text-[10px]">
|
|
|
|
|
{d.deptSortOrder}
|
|
|
|
|
</span>
|
2026-04-06 17:46:31 +05:30
|
|
|
</Badge>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</TableCell>
|
|
|
|
|
|
2026-05-11 10:52:30 +05:30
|
|
|
<TableCell>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Switch
|
|
|
|
|
checked={doc.isActive}
|
|
|
|
|
onCheckedChange={() => handleToggleStatus(doc)}
|
|
|
|
|
/>
|
|
|
|
|
<Badge
|
|
|
|
|
variant={doc.isActive ? "default" : "secondary"}
|
|
|
|
|
>
|
|
|
|
|
{doc.isActive ? "Active" : "Hidden"}
|
|
|
|
|
</Badge>
|
|
|
|
|
</div>
|
|
|
|
|
</TableCell>
|
|
|
|
|
|
2026-04-06 17:46:31 +05:30
|
|
|
<TableCell className="text-right">
|
|
|
|
|
<div className="flex justify-end gap-2">
|
|
|
|
|
<Button
|
2026-04-08 16:30:50 +05:30
|
|
|
size="icon"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
className="h-9 w-9"
|
2026-04-06 17:46:31 +05:30
|
|
|
onClick={() => openEdit(doc)}
|
|
|
|
|
>
|
|
|
|
|
<Pencil className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2026-03-17 13:11:00 +05:30
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
))
|
|
|
|
|
)}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
</div>
|
2026-04-08 16:30:50 +05:30
|
|
|
|
|
|
|
|
{!loading && filteredDoctors.length > 0 && (
|
|
|
|
|
<div className="flex items-center justify-between px-2 py-6 border-t">
|
|
|
|
|
<div className="text-base text-muted-foreground">
|
|
|
|
|
Showing{" "}
|
|
|
|
|
<span className="font-semibold">{indexOfFirstItem + 1}</span> to{" "}
|
|
|
|
|
<span className="font-semibold">
|
|
|
|
|
{Math.min(indexOfLastItem, filteredDoctors.length)}
|
|
|
|
|
</span>{" "}
|
|
|
|
|
of{" "}
|
|
|
|
|
<span className="font-semibold">{filteredDoctors.length}</span>{" "}
|
|
|
|
|
doctors
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-6">
|
|
|
|
|
<div className="text-base font-semibold">
|
|
|
|
|
Page {currentPage} of {totalPages}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex gap-2">
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="h-10 w-10"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
setCurrentPage((prev) => Math.max(prev - 1, 1))
|
|
|
|
|
}
|
|
|
|
|
disabled={currentPage === 1}
|
|
|
|
|
>
|
|
|
|
|
<ChevronLeft className="h-5 w-5" />
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="h-10 w-10"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
|
|
|
|
|
}
|
|
|
|
|
disabled={currentPage === totalPages || totalPages === 0}
|
|
|
|
|
>
|
|
|
|
|
<ChevronRight className="h-5 w-5" />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-03-17 13:11:00 +05:30
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
2026-04-14 17:33:21 +05:30
|
|
|
<DialogContent className="w-full !max-w-5xl h-[90vh] flex flex-col p-0 overflow-hidden">
|
|
|
|
|
<DialogHeader className="p-6 border-b bg-background z-10">
|
2026-04-08 16:30:50 +05:30
|
|
|
<DialogTitle className="text-2xl">
|
|
|
|
|
{editing ? "Edit Doctor" : "Add Doctor"}
|
|
|
|
|
</DialogTitle>
|
2026-03-17 13:11:00 +05:30
|
|
|
</DialogHeader>
|
|
|
|
|
|
2026-04-14 17:33:21 +05:30
|
|
|
<div className="flex-1 overflow-y-auto p-6">
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
|
|
|
|
|
<div className="space-y-6">
|
|
|
|
|
<h3 className="font-bold text-base border-b pb-2">
|
2026-05-11 00:04:22 +05:30
|
|
|
Profile & Visibility
|
2026-04-14 17:33:21 +05:30
|
|
|
</h3>
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label className="text-sm font-semibold">
|
|
|
|
|
Doctor Photo
|
|
|
|
|
</label>
|
|
|
|
|
<BytescaleUploader
|
|
|
|
|
value={form.image}
|
|
|
|
|
folderPath="/doctors"
|
|
|
|
|
onChange={(url) => setForm({ ...form, image: url })}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-05-11 00:04:22 +05:30
|
|
|
<div className="flex items-center justify-between p-3 border rounded-md bg-muted/30">
|
|
|
|
|
<Label
|
|
|
|
|
htmlFor="isActive"
|
|
|
|
|
className="text-base font-semibold cursor-pointer"
|
|
|
|
|
>
|
|
|
|
|
Active
|
|
|
|
|
</Label>
|
|
|
|
|
<Switch
|
|
|
|
|
id="isActive"
|
|
|
|
|
checked={form.isActive}
|
|
|
|
|
onCheckedChange={(val) =>
|
|
|
|
|
setForm({ ...form, isActive: val })
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="space-y-1">
|
2026-05-11 10:57:52 +05:30
|
|
|
<Label
|
|
|
|
|
htmlFor="globalSortOrder"
|
|
|
|
|
className="text-sm font-semibold"
|
|
|
|
|
>
|
|
|
|
|
Sort Priority (Lower numbers show first)
|
2026-05-11 00:04:22 +05:30
|
|
|
</Label>
|
|
|
|
|
<Input
|
|
|
|
|
id="globalSortOrder"
|
|
|
|
|
name="globalSortOrder"
|
|
|
|
|
type="number"
|
|
|
|
|
value={form.globalSortOrder}
|
|
|
|
|
onChange={handleChange}
|
|
|
|
|
className="text-base"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-04-14 17:33:21 +05:30
|
|
|
<div className="space-y-1">
|
|
|
|
|
<label className="text-sm font-semibold">Doctor ID</label>
|
|
|
|
|
<Input
|
|
|
|
|
name="doctorId"
|
|
|
|
|
placeholder="GG-DOC-001"
|
|
|
|
|
value={form.doctorId}
|
|
|
|
|
onChange={handleChange}
|
|
|
|
|
disabled={!!editing}
|
|
|
|
|
className="text-base"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
<label className="text-sm font-semibold">Full Name</label>
|
|
|
|
|
<Input
|
|
|
|
|
name="name"
|
|
|
|
|
placeholder="Dr. John Doe"
|
|
|
|
|
value={form.name}
|
|
|
|
|
onChange={handleChange}
|
|
|
|
|
className="text-base"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
<label className="text-sm font-semibold">Designation</label>
|
|
|
|
|
<Input
|
|
|
|
|
name="designation"
|
|
|
|
|
placeholder="Senior Consultant"
|
|
|
|
|
value={form.designation}
|
|
|
|
|
onChange={handleChange}
|
|
|
|
|
className="text-base"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
<label className="text-sm font-semibold">
|
|
|
|
|
Working Status
|
|
|
|
|
</label>
|
|
|
|
|
<Input
|
|
|
|
|
name="workingStatus"
|
|
|
|
|
placeholder="Active / On Call"
|
|
|
|
|
value={form.workingStatus}
|
|
|
|
|
onChange={handleChange}
|
|
|
|
|
className="text-base"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
<label className="text-sm font-semibold">
|
|
|
|
|
Qualification
|
|
|
|
|
</label>
|
|
|
|
|
<Input
|
|
|
|
|
name="qualification"
|
|
|
|
|
placeholder="MBBS, MD"
|
|
|
|
|
value={form.qualification}
|
|
|
|
|
onChange={handleChange}
|
|
|
|
|
className="text-base"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-04-08 16:30:50 +05:30
|
|
|
</div>
|
|
|
|
|
|
2026-04-14 17:33:21 +05:30
|
|
|
<div className="p-5 border rounded-md bg-muted/20">
|
|
|
|
|
<p className="text-base font-bold mb-4">Assign Departments</p>
|
|
|
|
|
<div className="grid grid-cols-2 gap-3">
|
|
|
|
|
{departments.map((dep) => {
|
|
|
|
|
const isSelected = form.departments.some(
|
|
|
|
|
(d: any) => d.departmentId === dep.departmentId,
|
|
|
|
|
);
|
|
|
|
|
return (
|
|
|
|
|
<Button
|
|
|
|
|
key={dep.departmentId}
|
|
|
|
|
type="button"
|
|
|
|
|
variant={isSelected ? "default" : "outline"}
|
|
|
|
|
size="sm"
|
|
|
|
|
className="justify-start text-sm min-h-11 whitespace-normal break-words text-left py-2"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
handleDepartmentToggle(dep.departmentId)
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{dep.name}
|
|
|
|
|
</Button>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
2026-04-06 17:46:31 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-17 13:11:00 +05:30
|
|
|
|
2026-04-14 17:33:21 +05:30
|
|
|
<div className="space-y-6">
|
|
|
|
|
<h3 className="font-bold text-base border-b pb-2">
|
2026-05-11 00:04:22 +05:30
|
|
|
Department Hierarchy & Timing
|
2026-04-14 17:33:21 +05:30
|
|
|
</h3>
|
|
|
|
|
{form.departments.length === 0 ? (
|
|
|
|
|
<div className="text-base text-muted-foreground italic py-24 text-center border-2 border-dashed rounded-lg">
|
2026-05-11 00:04:22 +05:30
|
|
|
Select a department to configure hierarchy and timing
|
2026-04-14 17:33:21 +05:30
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="space-y-8">
|
|
|
|
|
{form.departments.map((dep: any) => {
|
|
|
|
|
const depName = departments.find(
|
|
|
|
|
(d) => d.departmentId === dep.departmentId,
|
|
|
|
|
)?.name;
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={dep.departmentId}
|
2026-05-11 00:04:22 +05:30
|
|
|
className="space-y-4 p-5 border rounded-lg bg-background shadow-sm border-primary/20"
|
2026-04-14 17:33:21 +05:30
|
|
|
>
|
2026-05-11 00:04:22 +05:30
|
|
|
<div className="flex items-center justify-between border-b pb-2">
|
2026-04-14 17:33:21 +05:30
|
|
|
<p className="font-bold text-base text-primary">
|
|
|
|
|
{depName}
|
|
|
|
|
</p>
|
2026-05-11 00:04:22 +05:30
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Label className="text-xs font-bold">
|
|
|
|
|
Hierarchy Order:
|
|
|
|
|
</Label>
|
|
|
|
|
<Input
|
|
|
|
|
type="number"
|
|
|
|
|
className="w-20 h-8 text-sm"
|
|
|
|
|
value={dep.sortOrder}
|
|
|
|
|
onChange={(e) =>
|
|
|
|
|
handleDeptSortChange(
|
|
|
|
|
dep.departmentId,
|
|
|
|
|
e.target.value,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-04-14 17:33:21 +05:30
|
|
|
</div>
|
|
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-3">
|
|
|
|
|
{DAYS.map((day) => (
|
|
|
|
|
<div key={day} className="space-y-1">
|
|
|
|
|
<label className="text-xs uppercase font-bold text-muted-foreground">
|
|
|
|
|
{day}
|
|
|
|
|
</label>
|
|
|
|
|
<Input
|
|
|
|
|
className="h-9 text-sm"
|
|
|
|
|
placeholder="e.g. 09:00 AM - 01:00 PM"
|
|
|
|
|
value={dep.timing?.[day] || ""}
|
|
|
|
|
onChange={(e) =>
|
|
|
|
|
handleTimingChange(
|
|
|
|
|
dep.departmentId,
|
|
|
|
|
day,
|
|
|
|
|
e.target.value,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
2026-04-06 17:46:31 +05:30
|
|
|
</div>
|
2026-04-14 17:33:21 +05:30
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-04-06 17:46:31 +05:30
|
|
|
</div>
|
2026-03-17 13:11:00 +05:30
|
|
|
</div>
|
|
|
|
|
|
2026-04-14 17:33:21 +05:30
|
|
|
<DialogFooter className="p-6 border-t bg-background z-10 mt-0">
|
2026-04-08 16:30:50 +05:30
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
onClick={() => setOpenModal(false)}
|
|
|
|
|
className="text-base"
|
|
|
|
|
>
|
2026-03-17 13:11:00 +05:30
|
|
|
Cancel
|
|
|
|
|
</Button>
|
2026-04-08 16:30:50 +05:30
|
|
|
<Button onClick={handleSubmit} className="px-10 text-base">
|
|
|
|
|
{editing ? "Save Changes" : "Create Doctor Profile"}
|
2026-03-17 13:11:00 +05:30
|
|
|
</Button>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|