chore: file formatting

This commit is contained in:
Kailasdevdas
2026-05-26 15:48:01 +05:30
parent 8a21e0bf38
commit 78e2618a29
117 changed files with 12775 additions and 14638 deletions
+57 -166
View File
@@ -1,47 +1,26 @@
import { useState, useEffect, useCallback } from "react";
import { useState, useEffect, useCallback } from 'react';
import { getAppointmentsApi, deleteAppointmentApi } from "@/api/appointment";
import { exportToExcel } from "@/utils/exportToExcel";
import { getAppointmentsApi, deleteAppointmentApi } from '@/api/appointment';
import { exportToExcel } from '@/utils/exportToExcel';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogFooter,
} from "@/components/ui/dialog";
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog';
import {
Loader2,
Trash,
RefreshCw,
Download,
ChevronLeft,
ChevronRight,
Eye,
} from "lucide-react";
import { Loader2, Trash, RefreshCw, Download, ChevronLeft, ChevronRight, Eye } from 'lucide-react';
export default function AppointmentPage() {
const [appointments, setAppointments] = useState<any[]>([]);
const [loading, setLoading] = useState(true);
const [searchText, setSearchText] = useState("");
const [filterDoctor, setFilterDoctor] = useState("");
const [filterDate, setFilterDate] = useState("");
const [startDate, setStartDate] = useState("");
const [endDate, setEndDate] = useState("");
const [searchText, setSearchText] = useState('');
const [filterDoctor, setFilterDoctor] = useState('');
const [filterDate, setFilterDate] = useState('');
const [startDate, setStartDate] = useState('');
const [endDate, setEndDate] = useState('');
const [viewOpen, setViewOpen] = useState(false);
const [viewData, setViewData] = useState<any>(null);
@@ -53,14 +32,7 @@ export default function AppointmentPage() {
const fetchAll = useCallback(async () => {
setLoading(true);
try {
const res = await getAppointmentsApi(
currentPage,
itemsPerPage,
filterDate,
startDate,
endDate,
searchText,
);
const res = await getAppointmentsApi(currentPage, itemsPerPage, filterDate, startDate, endDate, searchText);
setAppointments(res?.data || []);
setTotalPages(res?.pagination?.totalPages || 1);
setTotalItems(res?.pagination?.total || 0);
@@ -76,9 +48,7 @@ export default function AppointmentPage() {
}, [fetchAll]);
const filteredAppointments = appointments.filter((item) => {
const matchesDoctor = filterDoctor
? item.doctor?.name?.toLowerCase().includes(filterDoctor.toLowerCase())
: true;
const matchesDoctor = filterDoctor ? item.doctor?.name?.toLowerCase().includes(filterDoctor.toLowerCase()) : true;
return matchesDoctor;
});
@@ -95,7 +65,7 @@ export default function AppointmentPage() {
}
async function handleDelete(id: number) {
if (!confirm("Delete appointment?")) return;
if (!confirm('Delete appointment?')) return;
await deleteAppointmentApi(id);
fetchAll();
}
@@ -111,7 +81,7 @@ export default function AppointmentPage() {
Date: new Date(item.date).toLocaleDateString(),
Message: item.message,
}));
exportToExcel(exportData, "appointments");
exportToExcel(exportData, 'appointments');
};
return (
@@ -121,9 +91,7 @@ export default function AppointmentPage() {
<div className="flex flex-wrap gap-4 items-end">
<div className="flex flex-col gap-1">
<label className="text-xs font-medium text-muted-foreground">
Search
</label>
<label className="text-xs font-medium text-muted-foreground">Search</label>
<Input
placeholder="Search name / phone..."
value={searchText}
@@ -136,9 +104,7 @@ export default function AppointmentPage() {
</div>
<div className="flex flex-col gap-1">
<label className="text-xs font-medium text-muted-foreground">
Date
</label>
<label className="text-xs font-medium text-muted-foreground">Date</label>
<Input
type="date"
value={filterDate}
@@ -152,9 +118,7 @@ export default function AppointmentPage() {
</div>
<div className="flex flex-col gap-1">
<label className="text-xs font-medium text-muted-foreground">
From
</label>
<label className="text-xs font-medium text-muted-foreground">From</label>
<Input
type="date"
value={startDate}
@@ -168,9 +132,7 @@ export default function AppointmentPage() {
</div>
<div className="flex flex-col gap-1">
<label className="text-xs font-medium text-muted-foreground">
To
</label>
<label className="text-xs font-medium text-muted-foreground">To</label>
<Input
type="date"
value={endDate}
@@ -184,9 +146,7 @@ export default function AppointmentPage() {
</div>
<div className="flex flex-col gap-1">
<label className="text-xs font-medium text-muted-foreground">
Rows
</label>
<label className="text-xs font-medium text-muted-foreground">Rows</label>
<select
value={itemsPerPage}
onChange={(e) => {
@@ -201,12 +161,7 @@ export default function AppointmentPage() {
</select>
</div>
<Button
variant="outline"
onClick={fetchAll}
disabled={loading}
className="text-base"
>
<Button variant="outline" onClick={fetchAll} disabled={loading} className="text-base">
<RefreshCw className="mr-2 h-5 w-5" />
Refresh
</Button>
@@ -228,24 +183,12 @@ export default function AppointmentPage() {
<Table className="w-full min-w-[1000px] table-fixed border-separate border-spacing-0">
<TableHeader className="sticky top-0 z-20 bg-background shadow-sm">
<TableRow>
<TableHead className="w-[60px] bg-background font-bold text-sm">
ID
</TableHead>
<TableHead className="w-[200px] bg-background font-bold text-sm">
Patient
</TableHead>
<TableHead className="w-[180px] bg-background font-bold text-sm">
Doctor
</TableHead>
<TableHead className="w-[150px] bg-background font-bold text-sm">
Date
</TableHead>
<TableHead className="w-[250px] bg-background font-bold text-sm">
Message
</TableHead>
<TableHead className="w-[120px] bg-background font-bold text-right text-sm">
Actions
</TableHead>
<TableHead className="w-[60px] bg-background font-bold text-sm">ID</TableHead>
<TableHead className="w-[200px] bg-background font-bold text-sm">Patient</TableHead>
<TableHead className="w-[180px] bg-background font-bold text-sm">Doctor</TableHead>
<TableHead className="w-[150px] bg-background font-bold text-sm">Date</TableHead>
<TableHead className="w-[250px] bg-background font-bold text-sm">Message</TableHead>
<TableHead className="w-[120px] bg-background font-bold text-right text-sm">Actions</TableHead>
</TableRow>
</TableHeader>
@@ -258,53 +201,31 @@ export default function AppointmentPage() {
</TableRow>
) : filteredAppointments.length === 0 ? (
<TableRow>
<TableCell
colSpan={6}
className="text-center text-muted-foreground py-10 text-base"
>
<TableCell colSpan={6} className="text-center text-muted-foreground py-10 text-base">
No appointments found
</TableCell>
</TableRow>
) : (
filteredAppointments.map((item) => (
<TableRow key={item.id} className="hover:bg-muted/50">
<TableCell className="font-mono text-xs">
{item.id}
<TableCell className="font-mono text-xs">{item.id}</TableCell>
<TableCell>
<div className="font-semibold text-base truncate">{item.name}</div>
<div className="text-xs text-muted-foreground">{item.mobileNumber}</div>
</TableCell>
<TableCell>
<div className="font-semibold text-base truncate">
{item.name}
</div>
<div className="text-xs text-muted-foreground">
{item.mobileNumber}
</div>
<div className="text-sm font-medium">{item.doctor?.name || '-'}</div>
<div className="text-[10px] text-muted-foreground truncate">{item.department?.name}</div>
</TableCell>
<TableCell>
<div className="text-sm font-medium">
{item.doctor?.name || "-"}
</div>
<div className="text-[10px] text-muted-foreground truncate">
{item.department?.name}
</div>
<div className="text-sm">{new Date(item.date).toLocaleDateString()}</div>
</TableCell>
<TableCell>
<div className="text-sm">
{new Date(item.date).toLocaleDateString()}
</div>
</TableCell>
<TableCell>
<div className="text-sm line-clamp-2 text-muted-foreground italic">
{item.message || "-"}
</div>
<div className="text-sm line-clamp-2 text-muted-foreground italic">{item.message || '-'}</div>
</TableCell>
<TableCell className="text-right">
<div className="flex justify-end gap-2">
<Button
size="icon"
variant="ghost"
className="h-9 w-9"
onClick={() => openView(item)}
>
<Button size="icon" variant="ghost" className="h-9 w-9" onClick={() => openView(item)}>
<Eye className="h-4 w-4" />
</Button>
<Button
@@ -327,12 +248,9 @@ export default function AppointmentPage() {
{!loading && totalItems > 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(currentPage * itemsPerPage, totalItems)}
</span>{" "}
of <span className="font-semibold">{totalItems}</span>
Showing <span className="font-semibold">{indexOfFirstItem + 1}</span> to{' '}
<span className="font-semibold">{Math.min(currentPage * itemsPerPage, totalItems)}</span> of{' '}
<span className="font-semibold">{totalItems}</span>
</div>
<div className="flex items-center gap-6">
<div className="text-base font-semibold">
@@ -343,9 +261,7 @@ export default function AppointmentPage() {
variant="outline"
size="icon"
className="h-10 w-10"
onClick={() =>
setCurrentPage((prev) => Math.max(prev - 1, 1))
}
onClick={() => setCurrentPage((prev) => Math.max(prev - 1, 1))}
disabled={currentPage === 1}
>
<ChevronLeft className="h-5 w-5" />
@@ -354,9 +270,7 @@ export default function AppointmentPage() {
variant="outline"
size="icon"
className="h-10 w-10"
onClick={() =>
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
}
onClick={() => setCurrentPage((prev) => Math.min(prev + 1, totalPages))}
disabled={currentPage === totalPages || totalPages === 0}
>
<ChevronRight className="h-5 w-5" />
@@ -371,33 +285,21 @@ export default function AppointmentPage() {
<Dialog open={viewOpen} onOpenChange={setViewOpen}>
<DialogContent className="w-full !max-w-3xl max-h-[85vh] overflow-y-auto">
<DialogHeader>
<DialogTitle className="text-2xl border-b pb-2">
Appointment Details
</DialogTitle>
<DialogTitle className="text-2xl border-b pb-2">Appointment Details</DialogTitle>
</DialogHeader>
{viewData && (
<div className="space-y-6 py-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div className="space-y-4">
<div>
<p className="text-xs uppercase font-bold text-muted-foreground">
Patient Information
</p>
<p className="text-lg font-bold text-primary">
{viewData.name}
</p>
<p className="text-xs uppercase font-bold text-muted-foreground">Patient Information</p>
<p className="text-lg font-bold text-primary">{viewData.name}</p>
<p className="text-sm">{viewData.mobileNumber}</p>
<p className="text-sm">
{viewData.email || "No email provided"}
</p>
<p className="text-sm">{viewData.email || 'No email provided'}</p>
</div>
<div>
<p className="text-xs uppercase font-bold text-muted-foreground">
Appointment Date
</p>
<p className="text-base font-semibold">
{new Date(viewData.date).toLocaleDateString()}
</p>
<p className="text-xs uppercase font-bold text-muted-foreground">Appointment Date</p>
<p className="text-base font-semibold">{new Date(viewData.date).toLocaleDateString()}</p>
<p className="text-[10px] text-muted-foreground">
Booked on: {new Date(viewData.createdAt).toLocaleString()}
</p>
@@ -405,22 +307,14 @@ export default function AppointmentPage() {
</div>
<div className="space-y-4">
<div>
<p className="text-xs uppercase font-bold text-muted-foreground">
Doctor / Department
</p>
<p className="text-base font-bold">
{viewData.doctor?.name || "Not Assigned"}
</p>
<p className="text-sm text-muted-foreground">
{viewData.department?.name || "General"}
</p>
<p className="text-xs uppercase font-bold text-muted-foreground">Doctor / Department</p>
<p className="text-base font-bold">{viewData.doctor?.name || 'Not Assigned'}</p>
<p className="text-sm text-muted-foreground">{viewData.department?.name || 'General'}</p>
</div>
<div className="p-4 bg-muted/30 rounded-lg">
<p className="text-xs uppercase font-bold text-muted-foreground mb-2">
Message from Patient
</p>
<p className="text-xs uppercase font-bold text-muted-foreground mb-2">Message from Patient</p>
<p className="text-sm italic leading-relaxed whitespace-pre-wrap">
{viewData.message || "No message provided."}
{viewData.message || 'No message provided.'}
</p>
</div>
</div>
@@ -428,10 +322,7 @@ export default function AppointmentPage() {
</div>
)}
<DialogFooter>
<Button
onClick={() => setViewOpen(false)}
className="w-full md:w-auto"
>
<Button onClick={() => setViewOpen(false)} className="w-full md:w-auto">
Close
</Button>
</DialogFooter>