feat: remove delete action and add status toggle to tables
This commit is contained in:
@@ -7,7 +7,6 @@ import {
|
||||
getDoctorsApi,
|
||||
createDoctorApi,
|
||||
updateDoctorApi,
|
||||
deleteDoctorApi,
|
||||
getDoctorTimingApi,
|
||||
} from "@/api/doctor";
|
||||
import { getDepartmentsApi } from "@/api/department";
|
||||
@@ -39,7 +38,6 @@ import {
|
||||
RefreshCw,
|
||||
Plus,
|
||||
Pencil,
|
||||
Trash,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
} from "lucide-react";
|
||||
@@ -139,6 +137,16 @@ export default function DoctorPage() {
|
||||
setForm({ ...form, [e.target.name]: value });
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
function handleDepartmentToggle(depId: string) {
|
||||
const exists = form.departments.find((d: any) => d.departmentId === depId);
|
||||
if (exists) {
|
||||
@@ -236,16 +244,6 @@ export default function DoctorPage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(id: string) {
|
||||
if (!confirm("Delete this doctor?")) return;
|
||||
try {
|
||||
await deleteDoctorApi(id);
|
||||
fetchAll();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-6">
|
||||
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-4">
|
||||
@@ -308,19 +306,19 @@ export default function DoctorPage() {
|
||||
<TableHead className="w-[80px] bg-background text-sm font-bold">
|
||||
Priority{" "}
|
||||
</TableHead>
|
||||
<TableHead className="w-[200px] bg-background text-sm font-bold">
|
||||
<TableHead className="w-[180px] bg-background text-sm font-bold">
|
||||
Doctor Info
|
||||
</TableHead>
|
||||
<TableHead className="w-[100px] bg-background text-sm font-bold">
|
||||
Status
|
||||
</TableHead>
|
||||
<TableHead className="w-[150px] bg-background text-sm font-bold">
|
||||
Designation
|
||||
</TableHead>
|
||||
<TableHead className="w-[220px] bg-background text-sm font-bold">
|
||||
Departments (Hierarchy)
|
||||
</TableHead>
|
||||
<TableHead className="w-[120px] bg-background text-right text-sm font-bold">
|
||||
<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">
|
||||
Actions
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
@@ -361,12 +359,6 @@ export default function DoctorPage() {
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
<Badge variant={doc.isActive ? "default" : "secondary"}>
|
||||
{doc.isActive ? "Active" : "Hidden"}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
<div
|
||||
className="truncate text-sm font-medium"
|
||||
@@ -396,6 +388,20 @@ export default function DoctorPage() {
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
<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>
|
||||
|
||||
<TableCell className="text-right">
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button
|
||||
@@ -406,14 +412,6 @@ export default function DoctorPage() {
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-9 w-9 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
onClick={() => handleDelete(doc.doctorId)}
|
||||
>
|
||||
<Trash className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
@@ -622,8 +620,6 @@ export default function DoctorPage() {
|
||||
const depName = departments.find(
|
||||
(d) => d.departmentId === dep.departmentId,
|
||||
)?.name;
|
||||
console.log("doctor department sortOrder", dep.sortOrder);
|
||||
console.log("dep", dep);
|
||||
return (
|
||||
<div
|
||||
key={dep.departmentId}
|
||||
|
||||
Reference in New Issue
Block a user