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,455 @@
"use client";
import { useState } from "react";
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, User, DollarSign, Eye } from "lucide-react";
import { toast } from "sonner";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
type Appointment = {
id: string;
date: Date;
timeSlot: string;
status: string;
notes: string | null;
dentist: {
name: string;
image: string | null;
};
service: {
name: string;
price: number | string;
};
payment: {
status: string;
amount: number;
} | null;
};
type AppointmentsListProps = {
appointments: Appointment[];
};
export function AppointmentsList({ appointments }: AppointmentsListProps) {
const [isLoading, setIsLoading] = useState<string | null>(null);
const [selectedAppointment, setSelectedAppointment] =
useState<Appointment | null>(null);
const upcomingAppointments = appointments.filter(
(apt) => new Date(apt.date) >= new Date() && apt.status !== "cancelled"
);
const pastAppointments = appointments.filter(
(apt) => new Date(apt.date) < new Date() || apt.status === "cancelled"
);
const handleCancelAppointment = async (appointmentId: string) => {
if (!confirm("Are you sure you want to cancel 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: "Cancelled by patient",
}),
});
if (!response.ok) {
throw new Error("Failed to cancel appointment");
}
toast.success("Appointment cancelled successfully");
window.location.reload();
} catch (error) {
console.error(error);
toast.error("Failed to cancel 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 getPaymentBadge = (status: string) => {
const variants: Record<
string,
"default" | "secondary" | "destructive" | "outline"
> = {
paid: "default",
pending: "secondary",
failed: "destructive",
refunded: "outline",
};
return (
<Badge variant={variants[status] || "default"}>
{status.toUpperCase()}
</Badge>
);
};
const formatPrice = (price: number | string): string => {
if (typeof price === "string") {
return price;
}
if (isNaN(price)) {
return "Contact for pricing";
}
return `${price.toLocaleString()}`;
};
const renderAppointmentCard = (appointment: Appointment) => (
<Card key={appointment.id}>
<CardHeader>
<div className="flex items-start justify-between">
<div>
<CardTitle className="text-lg">
{appointment.service.name}
</CardTitle>
<CardDescription className="flex items-center gap-1 mt-1">
<User className="h-3 w-3" />
Dr. {appointment.dentist.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>
<div className="flex items-center gap-2">
<DollarSign className="h-4 w-4 text-muted-foreground" />
<span>{formatPrice(appointment.service.price)}</span>
</div>
{appointment.payment && (
<div className="flex items-center gap-2">
<span className="text-muted-foreground">Payment:</span>
{getPaymentBadge(appointment.payment.status)}
</div>
)}
</div>
{appointment.notes && (
<div className="text-sm">
<p className="font-medium">Notes:</p>
<p className="text-muted-foreground">{appointment.notes}</p>
</div>
)}
{appointment.status === "pending" ||
appointment.status === "confirmed" ? (
<div className="flex gap-2">
<Button
variant="outline"
size="sm"
className="flex-1"
onClick={() => setSelectedAppointment(appointment)}
>
<Eye className="h-4 w-4 mr-2" />
View Details
</Button>
<Button
variant="outline"
size="sm"
onClick={() => toast.info("Reschedule feature coming soon")}
>
Reschedule
</Button>
<Button
variant="destructive"
size="sm"
onClick={() => handleCancelAppointment(appointment.id)}
disabled={isLoading === appointment.id}
>
{isLoading === appointment.id ? "Cancelling..." : "Cancel"}
</Button>
</div>
) : (
<Button
variant="outline"
size="sm"
className="w-full"
onClick={() => setSelectedAppointment(appointment)}
>
<Eye className="h-4 w-4 mr-2" />
View Details
</Button>
)}
{appointment.status === "completed" &&
appointment.payment?.status === "pending" && (
<Button className="w-full" size="sm">
Pay Now
</Button>
)}
</CardContent>
</Card>
);
return (
<>
<Tabs defaultValue="upcoming" className="w-full">
<TabsList className="grid w-full max-w-md grid-cols-2">
<TabsTrigger value="upcoming">
Upcoming ({upcomingAppointments.length})
</TabsTrigger>
<TabsTrigger value="past">
Past ({pastAppointments.length})
</TabsTrigger>
</TabsList>
<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>
<Button
className="mt-4"
onClick={() =>
(window.location.href = "/patient/book-appointment")
}
>
Book an Appointment
</Button>
</CardContent>
</Card>
) : (
upcomingAppointments.map(renderAppointmentCard)
)}
</TabsContent>
<TabsContent value="past" className="space-y-4 mt-6">
{pastAppointments.length === 0 ? (
<Card>
<CardContent className="py-12 text-center">
<p className="text-muted-foreground">No past appointments</p>
</CardContent>
</Card>
) : (
pastAppointments.map(renderAppointmentCard)
)}
</TabsContent>
</Tabs>
{/* Appointment Details Dialog */}
<Dialog
open={!!selectedAppointment}
onOpenChange={() => setSelectedAppointment(null)}
>
<DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto">
<DialogHeader>
<div className="flex items-start justify-between">
<div>
<DialogTitle className="text-2xl">
Appointment Details
</DialogTitle>
<DialogDescription>
Booking ID: {selectedAppointment?.id}
</DialogDescription>
</div>
{selectedAppointment &&
getStatusBadge(selectedAppointment.status)}
</div>
</DialogHeader>
{selectedAppointment && (
<div className="space-y-6">
{/* Service Information */}
<div className="space-y-3">
<h3 className="font-semibold text-lg border-b pb-2">
Service Information
</h3>
<div className="grid grid-cols-2 gap-4">
<div>
<p className="text-sm text-muted-foreground">Service</p>
<p className="font-medium">
{selectedAppointment.service.name}
</p>
</div>
<div>
<p className="text-sm text-muted-foreground">Price</p>
<p className="font-medium">
{formatPrice(selectedAppointment.service.price)}
</p>
</div>
</div>
</div>
{/* Appointment Details */}
<div className="space-y-3">
<h3 className="font-semibold text-lg border-b pb-2">
Appointment Schedule
</h3>
<div className="grid grid-cols-2 gap-4">
<div className="flex items-start gap-2">
<Calendar className="h-5 w-5 text-muted-foreground mt-0.5" />
<div>
<p className="text-sm text-muted-foreground">Date</p>
<p className="font-medium">
{new Date(selectedAppointment.date).toLocaleDateString(
"en-US",
{
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
}
)}
</p>
</div>
</div>
<div className="flex items-start gap-2">
<Clock className="h-5 w-5 text-muted-foreground mt-0.5" />
<div>
<p className="text-sm text-muted-foreground">Time</p>
<p className="font-medium">
{selectedAppointment.timeSlot}
</p>
</div>
</div>
</div>
</div>
{/* Dentist Information */}
<div className="space-y-3">
<h3 className="font-semibold text-lg border-b pb-2">
Dentist Information
</h3>
<div className="flex items-center gap-2">
<User className="h-5 w-5 text-muted-foreground" />
<div>
<p className="text-sm text-muted-foreground">
Your Dentist
</p>
<p className="font-medium">
Dr. {selectedAppointment.dentist.name}
</p>
</div>
</div>
</div>
{/* Payment Information */}
{selectedAppointment.payment && (
<div className="space-y-3">
<h3 className="font-semibold text-lg border-b pb-2">
Payment Information
</h3>
<div className="grid grid-cols-2 gap-4">
<div>
<p className="text-sm text-muted-foreground">
Payment Status
</p>
<div className="mt-1">
{getPaymentBadge(selectedAppointment.payment.status)}
</div>
</div>
<div>
<p className="text-sm text-muted-foreground">Amount</p>
<p className="font-medium">
{selectedAppointment.payment.amount.toLocaleString()}
</p>
</div>
</div>
</div>
)}
{/* Notes */}
{selectedAppointment.notes && (
<div className="space-y-3">
<h3 className="font-semibold text-lg border-b pb-2">
Special Requests / Notes
</h3>
<p className="text-sm bg-muted p-3 rounded-lg">
{selectedAppointment.notes}
</p>
</div>
)}
{/* Action Buttons */}
<div className="flex gap-2 pt-4 border-t">
{selectedAppointment.status === "pending" ||
selectedAppointment.status === "confirmed" ? (
<>
<Button
variant="outline"
className="flex-1"
onClick={() => {
setSelectedAppointment(null);
toast.info("Reschedule feature coming soon");
}}
>
Reschedule
</Button>
<Button
variant="destructive"
className="flex-1"
onClick={() => {
const id = selectedAppointment.id;
setSelectedAppointment(null);
handleCancelAppointment(id);
}}
disabled={isLoading === selectedAppointment.id}
>
Cancel Appointment
</Button>
</>
) : selectedAppointment.status === "completed" &&
selectedAppointment.payment?.status === "pending" ? (
<Button className="w-full">Pay Now</Button>
) : null}
</div>
</div>
)}
</DialogContent>
</Dialog>
</>
);
}

View File

@@ -0,0 +1,404 @@
"use client"
import * as React from "react"
import {
IconChevronDown,
IconChevronLeft,
IconChevronRight,
IconChevronsLeft,
IconChevronsRight,
IconDotsVertical,
IconLayoutColumns,
IconSearch,
} from "@tabler/icons-react"
import {
ColumnDef,
ColumnFiltersState,
flexRender,
getCoreRowModel,
getFacetedRowModel,
getFacetedUniqueValues,
getFilteredRowModel,
getPaginationRowModel,
getSortedRowModel,
SortingState,
useReactTable,
VisibilityState,
} from "@tanstack/react-table"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
type PatientAppointment = {
id: string
date: Date
timeSlot: string
status: string
notes: string | null
dentist: {
name: string
specialization: string | null
}
service: {
name: string
price: number
}
}
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"} className="text-xs">
{status.toUpperCase()}
</Badge>
)
}
const columns: ColumnDef<PatientAppointment>[] = [
{
id: "select",
header: ({ table }) => (
<div className="flex items-center justify-center">
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && "indeterminate")
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
</div>
),
cell: ({ row }) => (
<div className="flex items-center justify-center">
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Select row"
/>
</div>
),
enableSorting: false,
enableHiding: false,
},
{
id: "serviceName",
accessorFn: (row) => row.service.name,
header: "Service",
cell: ({ row }) => (
<div>
<p className="font-medium">{row.original.service.name}</p>
<p className="text-xs text-muted-foreground">{row.original.service.price.toFixed(2)}</p>
</div>
),
enableHiding: false,
},
{
id: "dentistName",
accessorFn: (row) => row.dentist.name,
header: "Dentist",
cell: ({ row }) => (
<div>
<p className="font-medium">Dr. {row.original.dentist.name}</p>
{row.original.dentist.specialization && (
<p className="text-xs text-muted-foreground">{row.original.dentist.specialization}</p>
)}
</div>
),
},
{
accessorKey: "date",
header: "Date & Time",
cell: ({ row }) => (
<div>
<p>{new Date(row.original.date).toLocaleDateString()}</p>
<p className="text-xs text-muted-foreground">{row.original.timeSlot}</p>
</div>
),
},
{
accessorKey: "status",
header: "Status",
cell: ({ row }) => getStatusBadge(row.original.status),
},
{
accessorKey: "notes",
header: "Notes",
cell: ({ row }) => (
<div className="max-w-[200px] truncate">
{row.original.notes || "-"}
</div>
),
},
{
id: "actions",
cell: ({ row }) => {
const canModify = row.original.status === "pending" || row.original.status === "confirmed"
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
className="data-[state=open]:bg-muted text-muted-foreground flex size-8"
size="icon"
>
<IconDotsVertical />
<span className="sr-only">Open menu</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-40">
<DropdownMenuItem>View Details</DropdownMenuItem>
{canModify && (
<>
<DropdownMenuItem>Reschedule</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem variant="destructive">Cancel</DropdownMenuItem>
</>
)}
</DropdownMenuContent>
</DropdownMenu>
)
},
},
]
type PatientAppointmentsTableProps = {
appointments: PatientAppointment[]
}
export function PatientAppointmentsTable({ appointments }: PatientAppointmentsTableProps) {
const [rowSelection, setRowSelection] = React.useState({})
const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({})
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
const [sorting, setSorting] = React.useState<SortingState>([])
const [pagination, setPagination] = React.useState({
pageIndex: 0,
pageSize: 10,
})
const table = useReactTable({
data: appointments,
columns,
state: {
sorting,
columnVisibility,
rowSelection,
columnFilters,
pagination,
},
enableRowSelection: true,
onRowSelectionChange: setRowSelection,
onSortingChange: setSorting,
onColumnFiltersChange: setColumnFilters,
onColumnVisibilityChange: setColumnVisibility,
onPaginationChange: setPagination,
getCoreRowModel: getCoreRowModel(),
getFilteredRowModel: getFilteredRowModel(),
getPaginationRowModel: getPaginationRowModel(),
getSortedRowModel: getSortedRowModel(),
getFacetedRowModel: getFacetedRowModel(),
getFacetedUniqueValues: getFacetedUniqueValues(),
})
return (
<div className="flex flex-col gap-4">
<div className="flex items-center justify-between">
<div className="relative w-full max-w-sm">
<IconSearch className="absolute left-2 top-2.5 size-4 text-muted-foreground" />
<Input
placeholder="Search appointments..."
value={(table.getColumn("serviceName")?.getFilterValue() as string) ?? ""}
onChange={(event) =>
table.getColumn("serviceName")?.setFilterValue(event.target.value)
}
className="pl-8"
/>
</div>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="sm">
<IconLayoutColumns />
<span className="hidden lg:inline">Columns</span>
<IconChevronDown />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-56">
{table
.getAllColumns()
.filter(
(column) =>
typeof column.accessorFn !== "undefined" && column.getCanHide()
)
.map((column) => {
return (
<DropdownMenuCheckboxItem
key={column.id}
className="capitalize"
checked={column.getIsVisible()}
onCheckedChange={(value) => column.toggleVisibility(!!value)}
>
{column.id}
</DropdownMenuCheckboxItem>
)
})}
</DropdownMenuContent>
</DropdownMenu>
</div>
<div className="overflow-hidden rounded-lg border">
<Table>
<TableHeader className="bg-muted">
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => {
return (
<TableHead key={header.id} colSpan={header.colSpan}>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
)}
</TableHead>
)
})}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
data-state={row.getIsSelected() && "selected"}
>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
))}
</TableRow>
))
) : (
<TableRow>
<TableCell colSpan={columns.length} className="h-24 text-center">
No appointments found.
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
</div>
<div className="flex items-center justify-between">
<div className="text-muted-foreground hidden flex-1 text-sm lg:flex">
{table.getFilteredSelectedRowModel().rows.length} of{" "}
{table.getFilteredRowModel().rows.length} row(s) selected.
</div>
<div className="flex w-full items-center gap-8 lg:w-fit">
<div className="hidden items-center gap-2 lg:flex">
<Label htmlFor="rows-per-page" className="text-sm font-medium">
Rows per page
</Label>
<Select
value={`${table.getState().pagination.pageSize}`}
onValueChange={(value) => {
table.setPageSize(Number(value))
}}
>
<SelectTrigger size="sm" className="w-20" id="rows-per-page">
<SelectValue placeholder={table.getState().pagination.pageSize} />
</SelectTrigger>
<SelectContent side="top">
{[10, 20, 30, 40, 50].map((pageSize) => (
<SelectItem key={pageSize} value={`${pageSize}`}>
{pageSize}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="flex w-fit items-center justify-center text-sm font-medium">
Page {table.getState().pagination.pageIndex + 1} of{" "}
{table.getPageCount()}
</div>
<div className="ml-auto flex items-center gap-2 lg:ml-0">
<Button
variant="outline"
className="hidden h-8 w-8 p-0 lg:flex"
onClick={() => table.setPageIndex(0)}
disabled={!table.getCanPreviousPage()}
>
<span className="sr-only">Go to first page</span>
<IconChevronsLeft />
</Button>
<Button
variant="outline"
className="size-8"
size="icon"
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
>
<span className="sr-only">Go to previous page</span>
<IconChevronLeft />
</Button>
<Button
variant="outline"
className="size-8"
size="icon"
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}
>
<span className="sr-only">Go to next page</span>
<IconChevronRight />
</Button>
<Button
variant="outline"
className="hidden size-8 lg:flex"
size="icon"
onClick={() => table.setPageIndex(table.getPageCount() - 1)}
disabled={!table.getCanNextPage()}
>
<span className="sr-only">Go to last page</span>
<IconChevronsRight />
</Button>
</div>
</div>
</div>
</div>
)
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,186 @@
"use client";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { CreditCard, Download } from "lucide-react";
type Payment = {
id: string;
amount: number;
method: string;
status: string;
transactionId: string | null;
paidAt: Date | null;
createdAt: Date;
appointment: {
date: Date;
timeSlot: string;
service: {
name: string;
};
dentist: {
name: string;
};
};
};
type PaymentHistoryProps = {
payments: Payment[];
};
export function PaymentHistory({ payments }: PaymentHistoryProps) {
const getStatusBadge = (status: string) => {
const variants: Record<
string,
"default" | "secondary" | "destructive" | "outline"
> = {
paid: "default",
pending: "secondary",
failed: "destructive",
refunded: "outline",
};
return (
<Badge variant={variants[status] || "default"}>
{status.toUpperCase()}
</Badge>
);
};
const getMethodIcon = () => {
return <CreditCard className="h-4 w-4" />;
};
const totalPaid = payments
.filter((p) => p.status === "paid")
.reduce((sum, p) => sum + p.amount, 0);
const pendingAmount = payments
.filter((p) => p.status === "pending")
.reduce((sum, p) => sum + p.amount, 0);
return (
<div className="space-y-4">
{/* Summary Cards */}
<div className="grid gap-4 md:grid-cols-3">
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-sm font-medium">Total Paid</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{totalPaid.toFixed(2)}</div>
<p className="text-xs text-muted-foreground">All time</p>
</CardContent>
</Card>
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-sm font-medium">
Pending Payments
</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">
{pendingAmount.toFixed(2)}
</div>
<p className="text-xs text-muted-foreground">Outstanding balance</p>
</CardContent>
</Card>
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-sm font-medium">
Total Transactions
</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{payments.length}</div>
<p className="text-xs text-muted-foreground">All payments</p>
</CardContent>
</Card>
</div>
{/* Payment List */}
<Card>
<CardHeader>
<CardTitle>Transaction History</CardTitle>
<CardDescription>All your payment transactions</CardDescription>
</CardHeader>
<CardContent>
{payments.length === 0 ? (
<p className="text-muted-foreground text-center py-8">
No payment history
</p>
) : (
<div className="space-y-4">
{payments.map((payment) => (
<div
key={payment.id}
className="flex items-center justify-between border-b pb-4 last:border-0"
>
<div className="flex items-start gap-4">
<div className="mt-1">{getMethodIcon()}</div>
<div>
<p className="font-medium">
{payment.appointment.service.name}
</p>
<p className="text-sm text-muted-foreground">
Dr. {payment.appointment.dentist.name}
</p>
<p className="text-sm text-muted-foreground">
{new Date(
payment.appointment.date
).toLocaleDateString()}{" "}
at {payment.appointment.timeSlot}
</p>
<div className="flex items-center gap-2 mt-1">
<p className="text-xs text-muted-foreground">
{payment.paidAt
? `Paid on ${new Date(payment.paidAt).toLocaleDateString()}`
: `Created on ${new Date(payment.createdAt).toLocaleDateString()}`}
</p>
{payment.transactionId && (
<p className="text-xs text-muted-foreground">
ID: {payment.transactionId}
</p>
)}
</div>
</div>
</div>
<div className="text-right space-y-2">
<p className="font-bold text-lg">
{payment.amount.toFixed(2)}
</p>
{getStatusBadge(payment.status)}
{payment.status === "pending" && (
<Button size="sm" className="w-full mt-2">
Pay Now
</Button>
)}
{payment.status === "paid" && (
<Button
variant="outline"
size="sm"
className="w-full mt-2"
>
<Download className="h-3 w-3 mr-1" />
Receipt
</Button>
)}
</div>
</div>
))}
</div>
)}
</CardContent>
</Card>
</div>
);
}

View File

@@ -0,0 +1,424 @@
"use client"
import * as React from "react"
import {
IconChevronDown,
IconChevronLeft,
IconChevronRight,
IconChevronsLeft,
IconChevronsRight,
IconDotsVertical,
IconLayoutColumns,
IconSearch,
} from "@tabler/icons-react"
import {
ColumnDef,
ColumnFiltersState,
flexRender,
getCoreRowModel,
getFacetedRowModel,
getFacetedUniqueValues,
getFilteredRowModel,
getPaginationRowModel,
getSortedRowModel,
SortingState,
useReactTable,
VisibilityState,
} from "@tanstack/react-table"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
type PatientPayment = {
id: string
amount: number
method: string
status: string
transactionId: string | null
paidAt: Date | null
createdAt: Date
appointment: {
service: {
name: string
}
date: Date
dentist: {
name: string
}
}
}
const getPaymentBadge = (status: string) => {
const variants: Record<string, "default" | "secondary" | "destructive" | "outline"> = {
paid: "default",
pending: "secondary",
failed: "destructive",
refunded: "outline",
}
return (
<Badge variant={variants[status] || "default"} className="text-xs">
{status.toUpperCase()}
</Badge>
)
}
const getMethodBadge = (method: string) => {
const labels: Record<string, string> = {
card: "Card",
e_wallet: "E-Wallet",
bank_transfer: "Bank Transfer",
cash: "Cash",
}
return (
<Badge variant="outline" className="text-xs">
{labels[method] || method}
</Badge>
)
}
const columns: ColumnDef<PatientPayment>[] = [
{
id: "select",
header: ({ table }) => (
<div className="flex items-center justify-center">
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && "indeterminate")
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
</div>
),
cell: ({ row }) => (
<div className="flex items-center justify-center">
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Select row"
/>
</div>
),
enableSorting: false,
enableHiding: false,
},
{
id: "serviceName",
accessorFn: (row) => row.appointment.service.name,
header: "Service",
cell: ({ row }) => (
<div>
<p className="font-medium">{row.original.appointment.service.name}</p>
<p className="text-xs text-muted-foreground">
Dr. {row.original.appointment.dentist.name}
</p>
</div>
),
enableHiding: false,
},
{
accessorKey: "amount",
header: () => <div className="text-right">Amount</div>,
cell: ({ row }) => (
<div className="text-right font-medium">
{row.original.amount.toFixed(2)}
</div>
),
},
{
accessorKey: "method",
header: "Payment Method",
cell: ({ row }) => getMethodBadge(row.original.method),
},
{
accessorKey: "status",
header: "Status",
cell: ({ row }) => getPaymentBadge(row.original.status),
},
{
accessorKey: "transactionId",
header: "Transaction ID",
cell: ({ row }) => (
<div className="max-w-[150px] truncate font-mono text-xs">
{row.original.transactionId || "-"}
</div>
),
},
{
accessorKey: "paidAt",
header: "Payment Date",
cell: ({ row }) => (
<div>
{row.original.paidAt ? (
<>
<p>{new Date(row.original.paidAt).toLocaleDateString()}</p>
<p className="text-xs text-muted-foreground">
{new Date(row.original.paidAt).toLocaleTimeString()}
</p>
</>
) : (
<span className="text-muted-foreground">-</span>
)}
</div>
),
},
{
id: "actions",
cell: ({ row }) => (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
className="data-[state=open]:bg-muted text-muted-foreground flex size-8"
size="icon"
>
<IconDotsVertical />
<span className="sr-only">Open menu</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-40">
<DropdownMenuItem>View Receipt</DropdownMenuItem>
<DropdownMenuItem>Download Invoice</DropdownMenuItem>
{row.original.status === "pending" && (
<DropdownMenuItem>Pay Now</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
),
},
]
type PatientPaymentsTableProps = {
payments: PatientPayment[]
}
export function PatientPaymentsTable({ payments }: PatientPaymentsTableProps) {
const [rowSelection, setRowSelection] = React.useState({})
const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({})
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
const [sorting, setSorting] = React.useState<SortingState>([])
const [pagination, setPagination] = React.useState({
pageIndex: 0,
pageSize: 10,
})
const table = useReactTable({
data: payments,
columns,
state: {
sorting,
columnVisibility,
rowSelection,
columnFilters,
pagination,
},
enableRowSelection: true,
onRowSelectionChange: setRowSelection,
onSortingChange: setSorting,
onColumnFiltersChange: setColumnFilters,
onColumnVisibilityChange: setColumnVisibility,
onPaginationChange: setPagination,
getCoreRowModel: getCoreRowModel(),
getFilteredRowModel: getFilteredRowModel(),
getPaginationRowModel: getPaginationRowModel(),
getSortedRowModel: getSortedRowModel(),
getFacetedRowModel: getFacetedRowModel(),
getFacetedUniqueValues: getFacetedUniqueValues(),
})
return (
<div className="flex flex-col gap-4">
<div className="flex items-center justify-between">
<div className="relative w-full max-w-sm">
<IconSearch className="absolute left-2 top-2.5 size-4 text-muted-foreground" />
<Input
placeholder="Search payments..."
value={(table.getColumn("serviceName")?.getFilterValue() as string) ?? ""}
onChange={(event) =>
table.getColumn("serviceName")?.setFilterValue(event.target.value)
}
className="pl-8"
/>
</div>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="sm">
<IconLayoutColumns />
<span className="hidden lg:inline">Columns</span>
<IconChevronDown />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-56">
{table
.getAllColumns()
.filter(
(column) =>
typeof column.accessorFn !== "undefined" && column.getCanHide()
)
.map((column) => {
return (
<DropdownMenuCheckboxItem
key={column.id}
className="capitalize"
checked={column.getIsVisible()}
onCheckedChange={(value) => column.toggleVisibility(!!value)}
>
{column.id}
</DropdownMenuCheckboxItem>
)
})}
</DropdownMenuContent>
</DropdownMenu>
</div>
<div className="overflow-hidden rounded-lg border">
<Table>
<TableHeader className="bg-muted">
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => {
return (
<TableHead key={header.id} colSpan={header.colSpan}>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
)}
</TableHead>
)
})}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
data-state={row.getIsSelected() && "selected"}
>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
))}
</TableRow>
))
) : (
<TableRow>
<TableCell colSpan={columns.length} className="h-24 text-center">
No payments found.
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
</div>
<div className="flex items-center justify-between">
<div className="text-muted-foreground hidden flex-1 text-sm lg:flex">
{table.getFilteredSelectedRowModel().rows.length} of{" "}
{table.getFilteredRowModel().rows.length} row(s) selected.
</div>
<div className="flex w-full items-center gap-8 lg:w-fit">
<div className="hidden items-center gap-2 lg:flex">
<Label htmlFor="rows-per-page" className="text-sm font-medium">
Rows per page
</Label>
<Select
value={`${table.getState().pagination.pageSize}`}
onValueChange={(value) => {
table.setPageSize(Number(value))
}}
>
<SelectTrigger size="sm" className="w-20" id="rows-per-page">
<SelectValue placeholder={table.getState().pagination.pageSize} />
</SelectTrigger>
<SelectContent side="top">
{[10, 20, 30, 40, 50].map((pageSize) => (
<SelectItem key={pageSize} value={`${pageSize}`}>
{pageSize}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="flex w-fit items-center justify-center text-sm font-medium">
Page {table.getState().pagination.pageIndex + 1} of{" "}
{table.getPageCount()}
</div>
<div className="ml-auto flex items-center gap-2 lg:ml-0">
<Button
variant="outline"
className="hidden h-8 w-8 p-0 lg:flex"
onClick={() => table.setPageIndex(0)}
disabled={!table.getCanPreviousPage()}
>
<span className="sr-only">Go to first page</span>
<IconChevronsLeft />
</Button>
<Button
variant="outline"
className="size-8"
size="icon"
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
>
<span className="sr-only">Go to previous page</span>
<IconChevronLeft />
</Button>
<Button
variant="outline"
className="size-8"
size="icon"
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}
>
<span className="sr-only">Go to next page</span>
<IconChevronRight />
</Button>
<Button
variant="outline"
className="hidden size-8 lg:flex"
size="icon"
onClick={() => table.setPageIndex(table.getPageCount() - 1)}
disabled={!table.getCanNextPage()}
>
<span className="sr-only">Go to last page</span>
<IconChevronsRight />
</Button>
</div>
</div>
</div>
</div>
)
}

View File

@@ -0,0 +1,112 @@
import { IconCalendar, IconClock, IconCreditCard, IconCircleCheck } from "@tabler/icons-react"
import { Badge } from "@/components/ui/badge"
import {
Card,
CardAction,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card"
type PatientStats = {
upcomingAppointments: number
completedAppointments: number
totalSpent: number
pendingPayments: number
}
export function PatientSectionCards({ stats }: { stats: PatientStats }) {
return (
<div className="*:data-[slot=card]:from-primary/5 *:data-[slot=card]:to-card dark:*:data-[slot=card]:bg-card grid grid-cols-1 gap-4 px-4 *:data-[slot=card]:bg-gradient-to-t *:data-[slot=card]:shadow-xs lg:px-6 @xl/main:grid-cols-2 @5xl/main:grid-cols-4">
<Card className="@container/card">
<CardHeader>
<CardDescription>Upcoming Appointments</CardDescription>
<CardTitle className="text-2xl font-semibold tabular-nums @[250px]/card:text-3xl">
{stats.upcomingAppointments}
</CardTitle>
<CardAction>
<Badge variant="outline">
<IconCalendar className="size-3" />
Scheduled
</Badge>
</CardAction>
</CardHeader>
<CardFooter className="flex-col items-start gap-1.5 text-sm">
<div className="line-clamp-1 flex gap-2 font-medium">
Your scheduled visits <IconClock className="size-4" />
</div>
<div className="text-muted-foreground">
Appointments waiting for you
</div>
</CardFooter>
</Card>
<Card className="@container/card">
<CardHeader>
<CardDescription>Completed Visits</CardDescription>
<CardTitle className="text-2xl font-semibold tabular-nums @[250px]/card:text-3xl">
{stats.completedAppointments}
</CardTitle>
<CardAction>
<Badge variant="outline">
<IconCircleCheck className="size-3" />
Done
</Badge>
</CardAction>
</CardHeader>
<CardFooter className="flex-col items-start gap-1.5 text-sm">
<div className="line-clamp-1 flex gap-2 font-medium">
Total completed appointments <IconCircleCheck className="size-4" />
</div>
<div className="text-muted-foreground">
Your dental care history
</div>
</CardFooter>
</Card>
<Card className="@container/card">
<CardHeader>
<CardDescription>Total Spent</CardDescription>
<CardTitle className="text-2xl font-semibold tabular-nums @[250px]/card:text-3xl">
{stats.totalSpent.toLocaleString('en-PH', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
</CardTitle>
<CardAction>
<Badge variant="outline">
<IconCreditCard className="size-3" />
Paid
</Badge>
</CardAction>
</CardHeader>
<CardFooter className="flex-col items-start gap-1.5 text-sm">
<div className="line-clamp-1 flex gap-2 font-medium">
Total payments made <IconCreditCard className="size-4" />
</div>
<div className="text-muted-foreground">Lifetime spending on dental care</div>
</CardFooter>
</Card>
<Card className="@container/card">
<CardHeader>
<CardDescription>Pending Payments</CardDescription>
<CardTitle className="text-2xl font-semibold tabular-nums @[250px]/card:text-3xl">
{stats.pendingPayments.toLocaleString('en-PH', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
</CardTitle>
<CardAction>
<Badge variant="secondary">
<IconClock className="size-3" />
Pending
</Badge>
</CardAction>
</CardHeader>
<CardFooter className="flex-col items-start gap-1.5 text-sm">
<div className="line-clamp-1 flex gap-2 font-medium">
Outstanding balance <IconCreditCard className="size-4" />
</div>
<div className="text-muted-foreground">Payments awaiting settlement</div>
</CardFooter>
</Card>
</div>
)
}

View File

@@ -0,0 +1,139 @@
"use client"
import { Check, Calendar } from "lucide-react"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
type Service = {
id: string
name: string
description: string
duration: number
price: number
category: string
isActive: boolean
}
type ServicesDisplayProps = {
services: Service[]
onSelectService?: (serviceId: string) => void
scrollToBooking?: boolean
}
export function ServicesDisplay({ services, onSelectService, scrollToBooking = true }: ServicesDisplayProps) {
const handleServiceSelect = (serviceId: string) => {
if (onSelectService) {
onSelectService(serviceId)
}
if (scrollToBooking) {
// Scroll to booking form
setTimeout(() => {
const bookingSection = document.getElementById('booking-form-section')
if (bookingSection) {
bookingSection.scrollIntoView({ behavior: 'smooth', block: 'start' })
}
}, 100)
}
}
// Group services by category
const servicesByCategory = services.reduce((acc, service) => {
if (!acc[service.category]) {
acc[service.category] = []
}
acc[service.category].push(service)
return acc
}, {} as Record<string, Service[]>)
const categories = Object.keys(servicesByCategory)
const defaultCategory = categories[0] || ""
// Map category names to badges
const categoryBadges: Record<string, string> = {
"Preventive Care": "Essential",
"Restorative": "Popular",
"Cosmetic": "Premium",
"Orthodontics": "Advanced",
"Emergency": "Urgent",
}
return (
<div className="space-y-6">
<Tabs defaultValue={defaultCategory} className="w-full">
<TabsList className="grid w-full h-auto gap-2" style={{ gridTemplateColumns: `repeat(${Math.min(categories.length, 5)}, minmax(0, 1fr))` }}>
{categories.map((category) => (
<TabsTrigger
key={category}
value={category}
className="text-sm sm:text-base"
>
{category}
</TabsTrigger>
))}
</TabsList>
{categories.map((category) => (
<TabsContent
key={category}
value={category}
className="mt-6 animate-in fade-in-50 slide-in-from-bottom-4 duration-500"
>
<Card>
<CardHeader>
<div className="flex items-center justify-between">
<CardTitle className="text-2xl">{category}</CardTitle>
<Badge className="uppercase">
{categoryBadges[category] || "Service"}
</Badge>
</div>
<CardDescription>
Professional dental services with transparent pricing
</CardDescription>
</CardHeader>
<CardContent>
<div className="grid gap-4 md:grid-cols-2">
{servicesByCategory[category].map((service, index) => (
<div
key={service.id}
className="flex flex-col p-4 rounded-lg border hover:border-primary transition-all duration-300 hover:shadow-md animate-in fade-in-50 slide-in-from-left-4"
style={{ animationDelay: `${index * 100}ms` }}
>
<div className="flex items-start gap-3 mb-3">
<Check className="size-5 text-primary mt-1 shrink-0" />
<div className="flex-1">
<h3 className="font-semibold text-lg mb-1">{service.name}</h3>
<p className="text-muted-foreground text-sm mb-2">
{service.description}
</p>
<div className="flex items-center gap-4 text-sm text-muted-foreground">
<span> {service.duration} mins</span>
</div>
</div>
</div>
<div className="flex items-center justify-between mt-auto pt-3 border-t">
<span className="text-2xl font-bold text-primary">
{service.price.toLocaleString()}
</span>
{onSelectService && (
<Button
size="sm"
onClick={() => handleServiceSelect(service.id)}
>
<Calendar className="size-4 mr-2" />
Book Now
</Button>
)}
</div>
</div>
))}
</div>
</CardContent>
</Card>
</TabsContent>
))}
</Tabs>
</div>
)
}