import { DashboardLayout } from "@/components/layout/dashboard-layout"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Calendar, Clock, Users, CheckCircle } from "lucide-react"; import Link from "next/link"; import { requireDentist } from "@/lib/auth-session/auth-server"; import { prisma } from "@/lib/types/prisma"; import { safeFindManyAppointments } from "@/lib/utils/appointment-helpers"; import type { Metadata } from "next"; export const metadata: Metadata = { title: "Dentist Dashboard", }; // Force dynamic rendering since this page uses authentication (headers) export const dynamic = "force-dynamic"; export default async function DentistDashboard() { // Require dentist role - will redirect to appropriate page if not dentist const { user } = await requireDentist(); // Calculate date ranges const today = new Date(); today.setHours(0, 0, 0, 0); const tomorrow = new Date(today); tomorrow.setDate(tomorrow.getDate() + 1); const now = new Date(); // Run all queries in parallel for better performance const [ todayAppointments, pendingAppointments, totalPatients, completedAppointments, upcomingAppointments, ] = await Promise.all([ // Fetch today's appointments safeFindManyAppointments({ where: { dentistId: user.id, date: { gte: today, lt: tomorrow, }, status: { in: ["pending", "confirmed"], }, }, include: { patient: true, service: true, }, orderBy: { timeSlot: "asc", }, }), // Fetch pending appointments safeFindManyAppointments({ where: { dentistId: user.id, status: "pending", date: { gte: now, }, }, include: { patient: true, service: true, }, orderBy: { date: "asc", }, take: 5, }), // Get total unique patients prisma.appointment.groupBy({ by: ["patientId"], where: { dentistId: user.id, }, }), // Get completed appointments count prisma.appointment.count({ where: { dentistId: user.id, status: "completed", }, }), // Get upcoming appointments count prisma.appointment.count({ where: { dentistId: user.id, status: { in: ["pending", "confirmed"], }, date: { gte: now, }, }, }), ]); return (

Welcome, Dr. {user.name}!

Manage your schedule and patients

{/* Statistics Cards */}
Today's Appointments
{todayAppointments.length}

Scheduled for today

Upcoming
{upcomingAppointments}

Future appointments

Total Patients
{totalPatients.length}

Unique patients

Completed
{completedAppointments}

All time

{/* Quick Actions */}
{/* Today's Schedule */} Today's Schedule {today.toLocaleDateString()} {todayAppointments.length === 0 ? (

No appointments scheduled for today

) : (
{todayAppointments.map((appointment) => (

{appointment.patient.name}

{appointment.service.name}

{appointment.timeSlot}

{appointment.status === "pending" && ( )}
))}
)}
{/* Pending Appointments */} Pending Appointments Appointments awaiting confirmation {pendingAppointments.length === 0 ? (

No pending appointments

) : (
{pendingAppointments.map((appointment) => (

{appointment.patient.name}

{appointment.service.name}

{new Date(appointment.date).toLocaleDateString()} at{" "} {appointment.timeSlot}

))}
)}
); }