Dental Care

This commit is contained in:
Iliyan Angelov
2025-11-16 14:29:51 +02:00
commit 39077550ef
194 changed files with 43197 additions and 0 deletions

View File

@@ -0,0 +1,316 @@
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Calendar, Clock, Phone, Mail } from "lucide-react";
import { toast } from "sonner";
type Appointment = {
id: string;
date: Date;
timeSlot: string;
status: string;
notes: string | null;
patient: {
name: string;
email: string;
phone: string | null;
medicalHistory: string | null;
};
service: {
name: string;
duration: number;
price: number;
};
payment: {
status: string;
} | null;
};
type DentistAppointmentsListProps = {
appointments: Appointment[];
};
export function DentistAppointmentsList({
appointments,
}: DentistAppointmentsListProps) {
const router = useRouter();
const [isLoading, setIsLoading] = useState<string | null>(null);
const pendingAppointments = appointments.filter(
(apt) => apt.status === "pending"
);
const upcomingAppointments = appointments.filter(
(apt) => new Date(apt.date) >= new Date() && apt.status === "confirmed"
);
const completedAppointments = appointments.filter(
(apt) => apt.status === "completed"
);
const handleConfirmAppointment = async (appointmentId: string) => {
setIsLoading(appointmentId);
try {
const response = await fetch(`/api/appointments/${appointmentId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
status: "confirmed",
}),
});
if (!response.ok) {
throw new Error("Failed to confirm appointment");
}
toast.success("Appointment confirmed successfully");
router.refresh();
} catch (error) {
console.error(error);
toast.error("Failed to confirm appointment");
} finally {
setIsLoading(null);
}
};
const handleDeclineAppointment = async (appointmentId: string) => {
if (!confirm("Are you sure you want to decline this appointment?")) {
return;
}
setIsLoading(appointmentId);
try {
const response = await fetch(`/api/appointments/${appointmentId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
status: "cancelled",
cancelReason: "Declined by dentist",
}),
});
if (!response.ok) {
throw new Error("Failed to decline appointment");
}
toast.success("Appointment declined");
router.refresh();
} catch (error) {
console.error(error);
toast.error("Failed to decline appointment");
} finally {
setIsLoading(null);
}
};
const handleCompleteAppointment = async (appointmentId: string) => {
setIsLoading(appointmentId);
try {
const response = await fetch(`/api/appointments/${appointmentId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
status: "completed",
}),
});
if (!response.ok) {
throw new Error("Failed to complete appointment");
}
toast.success("Appointment marked as completed");
router.refresh();
} catch (error) {
console.error(error);
toast.error("Failed to complete appointment");
} finally {
setIsLoading(null);
}
};
const getStatusBadge = (status: string) => {
const variants: Record<
string,
"default" | "secondary" | "destructive" | "outline"
> = {
pending: "secondary",
confirmed: "default",
cancelled: "destructive",
completed: "outline",
rescheduled: "secondary",
};
return (
<Badge variant={variants[status] || "default"}>
{status.toUpperCase()}
</Badge>
);
};
const renderAppointmentCard = (
appointment: Appointment,
showActions: boolean = true
) => (
<Card key={appointment.id}>
<CardHeader>
<div className="flex items-start justify-between">
<div>
<CardTitle className="text-lg">
{appointment.patient.name}
</CardTitle>
<CardDescription className="mt-1">
{appointment.service.name}
</CardDescription>
</div>
{getStatusBadge(appointment.status)}
</div>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid grid-cols-2 gap-4 text-sm">
<div className="flex items-center gap-2">
<Calendar className="h-4 w-4 text-muted-foreground" />
<span>{new Date(appointment.date).toLocaleDateString()}</span>
</div>
<div className="flex items-center gap-2">
<Clock className="h-4 w-4 text-muted-foreground" />
<span>{appointment.timeSlot}</span>
</div>
{appointment.patient.phone && (
<div className="flex items-center gap-2">
<Phone className="h-4 w-4 text-muted-foreground" />
<span>{appointment.patient.phone}</span>
</div>
)}
<div className="flex items-center gap-2">
<Mail className="h-4 w-4 text-muted-foreground" />
<span className="truncate">{appointment.patient.email}</span>
</div>
</div>
{appointment.patient.medicalHistory && (
<div className="text-sm">
<p className="font-medium">Medical History:</p>
<p className="text-muted-foreground">
{appointment.patient.medicalHistory}
</p>
</div>
)}
{appointment.notes && (
<div className="text-sm">
<p className="font-medium">Patient Notes:</p>
<p className="text-muted-foreground">{appointment.notes}</p>
</div>
)}
{showActions && (
<div className="flex gap-2">
{appointment.status === "pending" && (
<>
<Button
size="sm"
className="flex-1"
onClick={() => handleConfirmAppointment(appointment.id)}
disabled={isLoading === appointment.id}
>
{isLoading === appointment.id ? "Confirming..." : "Confirm"}
</Button>
<Button
variant="destructive"
size="sm"
className="flex-1"
onClick={() => handleDeclineAppointment(appointment.id)}
disabled={isLoading === appointment.id}
>
Decline
</Button>
</>
)}
{appointment.status === "confirmed" && (
<Button
size="sm"
className="w-full"
onClick={() => handleCompleteAppointment(appointment.id)}
disabled={isLoading === appointment.id}
>
{isLoading === appointment.id
? "Completing..."
: "Mark as Completed"}
</Button>
)}
</div>
)}
</CardContent>
</Card>
);
return (
<Tabs defaultValue="pending" className="w-full">
<TabsList className="grid w-full max-w-2xl grid-cols-3">
<TabsTrigger value="pending">
Pending ({pendingAppointments.length})
</TabsTrigger>
<TabsTrigger value="upcoming">
Upcoming ({upcomingAppointments.length})
</TabsTrigger>
<TabsTrigger value="completed">
Completed ({completedAppointments.length})
</TabsTrigger>
</TabsList>
<TabsContent value="pending" className="space-y-4 mt-6">
{pendingAppointments.length === 0 ? (
<Card>
<CardContent className="py-12 text-center">
<p className="text-muted-foreground">No pending appointments</p>
</CardContent>
</Card>
) : (
pendingAppointments.map((apt) => renderAppointmentCard(apt))
)}
</TabsContent>
<TabsContent value="upcoming" className="space-y-4 mt-6">
{upcomingAppointments.length === 0 ? (
<Card>
<CardContent className="py-12 text-center">
<p className="text-muted-foreground">No upcoming appointments</p>
</CardContent>
</Card>
) : (
upcomingAppointments.map((apt) => renderAppointmentCard(apt))
)}
</TabsContent>
<TabsContent value="completed" className="space-y-4 mt-6">
{completedAppointments.length === 0 ? (
<Card>
<CardContent className="py-12 text-center">
<p className="text-muted-foreground">No completed appointments</p>
</CardContent>
</Card>
) : (
completedAppointments.map((apt) => renderAppointmentCard(apt, false))
)}
</TabsContent>
</Tabs>
);
}

View File

@@ -0,0 +1,139 @@
"use client"
import { useState } from "react"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
import { Search, Mail, Phone } from "lucide-react"
type Patient = {
id: string
name: string
email: string
phone: string | null
medicalHistory: string | null
appointments: Array<{
id: string
date: Date
status: string
service: {
name: string
}
}>
}
type DentistPatientsTableProps = {
patients: Patient[]
}
export function DentistPatientsTable({ patients }: DentistPatientsTableProps) {
const [searchQuery, setSearchQuery] = useState("")
const filteredPatients = patients.filter((patient) => {
const query = searchQuery.toLowerCase()
return (
patient.name.toLowerCase().includes(query) ||
patient.email.toLowerCase().includes(query)
)
})
return (
<Card>
<CardHeader>
<CardTitle>My Patients</CardTitle>
<CardDescription>
Total: {patients.length} patients
</CardDescription>
<div className="relative">
<Search className="absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" />
<Input
placeholder="Search by name or email..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="pl-8"
/>
</div>
</CardHeader>
<CardContent>
<div className="rounded-md border">
<Table>
<TableHeader>
<TableRow>
<TableHead>Patient Name</TableHead>
<TableHead>Contact</TableHead>
<TableHead>Total Visits</TableHead>
<TableHead>Last Visit</TableHead>
<TableHead>Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{filteredPatients.length === 0 ? (
<TableRow>
<TableCell colSpan={5} className="text-center py-8 text-muted-foreground">
No patients found
</TableCell>
</TableRow>
) : (
filteredPatients.map((patient) => {
const completedVisits = patient.appointments.filter(
(apt) => apt.status === "completed"
).length
const lastVisit = patient.appointments[0]
return (
<TableRow key={patient.id}>
<TableCell className="font-medium">{patient.name}</TableCell>
<TableCell>
<div className="space-y-1">
<div className="flex items-center gap-1 text-sm">
<Mail className="h-3 w-3" />
<span className="text-xs">{patient.email}</span>
</div>
{patient.phone && (
<div className="flex items-center gap-1 text-sm">
<Phone className="h-3 w-3" />
<span className="text-xs">{patient.phone}</span>
</div>
)}
</div>
</TableCell>
<TableCell>
<div>
<p>{patient.appointments.length} total</p>
<p className="text-xs text-muted-foreground">{completedVisits} completed</p>
</div>
</TableCell>
<TableCell>
{lastVisit ? (
<div>
<p>{new Date(lastVisit.date).toLocaleDateString()}</p>
<p className="text-xs text-muted-foreground">{lastVisit.service.name}</p>
</div>
) : (
"-"
)}
</TableCell>
<TableCell>
<Button variant="outline" size="sm">
View History
</Button>
</TableCell>
</TableRow>
)
})
)}
</TableBody>
</Table>
</div>
</CardContent>
</Card>
)
}