diff --git a/client/app/(patient)/appointments/[id]/page.tsx b/client/app/(patient)/appointments/[id]/page.tsx index f2ec5176..f003afbd 100644 --- a/client/app/(patient)/appointments/[id]/page.tsx +++ b/client/app/(patient)/appointments/[id]/page.tsx @@ -1,31 +1,29 @@ -"use client"; +'use client' -import { - useGetAppointmentDetailsPatient, - useUpdateAppointmentStatusAndNotesPatient, -} from "@/lib/hooks/appointment/useAppointmentPatient"; -import { notFound, useParams } from "next/navigation"; -import { format } from "date-fns"; -import { Card, CardContent, CardHeader, CardTitle, CardFooter } from "@/components/ui/card"; -import { Button } from "@/components/ui/button"; -import { Input } from "@/components/ui/input"; -import GetStatusBadge from "@/components/page-components/doctor/appointment/GetStatusBadge"; -import { Calendar, Clock, FileText, Video, User, Mail, Phone, Edit2 } from "lucide-react"; -import Image from "next/image"; -import { useState } from "react"; -import { useAuth } from "@/lib/hooks/useAuth"; -import { toast } from "@/components/ui/use-toast"; -import ConfirmCancelAppointmentModelPatient from "@/components/models/appointment/ConfirmCancelAppointmentPatient"; -import { AppointmentStatus } from "@/types"; +import { useState } from "react" +import { useParams, notFound } from "next/navigation" +import { format } from "date-fns" +import Image from "next/image" +import { Clock } from "lucide-react" +import { useGetAppointmentDetailsPatient, useUpdateAppointmentStatusAndNotesPatient } from "@/lib/hooks/appointment/useAppointmentPatient" +import { useAuth } from "@/lib/hooks/useAuth" +import { AppointmentStatus } from "@/types" +import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" +import { Textarea } from "@/components/ui/textarea" +import { toast } from "@/components/ui/use-toast" +import { Badge } from "@/components/ui/badge" +import { Separator } from "@/components/ui/separator" +import ConfirmCancelAppointmentModelPatient from "@/components/models/appointment/ConfirmCancelAppointmentPatient" +import { ButtonV2 } from "@/components/button/ButtonV2" -const Page = () => { - const id = useParams().id as string; - const [isEditingNote, setIsEditingNote] = useState(false); - const [isCancelModelOpen, setCancelModelOpen] = useState(false); - const { data: appointment, refetch } = useGetAppointmentDetailsPatient(id); - const { mutate: update, isPending } = useUpdateAppointmentStatusAndNotesPatient(); - const [newNote, setNewNote] = useState(""); - const { patientToken } = useAuth(); +export default function AppointmentDetailsPage() { + const id = useParams().id as string + const [isEditingNote, setIsEditingNote] = useState(false) + const [isCancelModelOpen, setCancelModelOpen] = useState(false) + const { data: appointment, refetch } = useGetAppointmentDetailsPatient(id) + const { mutate: update } = useUpdateAppointmentStatusAndNotesPatient() + const [newNote, setNewNote] = useState("") + const { patientToken } = useAuth() const handleUpdateNote = async () => { if (newNote.trim()) { @@ -34,30 +32,29 @@ const Page = () => { { onSuccess: () => { toast({ - title: "Note Updated 🎉", - description: "Your note has been successfully updated!", - variant: "success", - }); - setIsEditingNote(false); - refetch(); + title: "Note Updated", + description: "Your note has been successfully updated.", + }) + setIsEditingNote(false) + refetch() }, onError: () => { toast({ - title: "Error 😞", - description: "Something went wrong while updating the note. Please try again.", + title: "Error", + description: "Failed to update the note. Please try again.", variant: "destructive", - }); + }) }, } - ); + ) } else { toast({ - title: "Invalid Input 🚫", + title: "Invalid Input", description: "Note cannot be empty. Please enter some text.", - variant: "warning", - }); + variant: "destructive", + }) } - }; + } const handleCancelAppointment = async () => { update( @@ -65,111 +62,135 @@ const Page = () => { { onSuccess: () => { toast({ - title: "Appointment Cancelled 🛑", + title: "Appointment Cancelled", description: "Your appointment has been successfully cancelled.", - variant: "success", - }); - refetch(); - setCancelModelOpen(false); + }) + refetch() + setCancelModelOpen(false) }, onError: () => { toast({ - title: "Error Cancelling 😞", - description: "Something went wrong while cancelling the appointment. Please try again.", + title: "Error", + description: "Failed to cancel the appointment. Please try again.", variant: "destructive", - }); + }) }, } - ); - }; + ) + } const isCancellable = () => { - if (!appointment?.slot?.startTime || !appointment?.appointmentDate) return false; + if (!appointment?.slot?.startTime || !appointment?.appointmentDate) return false - const appointmentDate = new Date(appointment.appointmentDate); - const [hours, minutes] = appointment.slot.startTime.split(":"); - const isPM = appointment.slot.startTime.includes("PM"); + const appointmentDate = new Date(appointment.appointmentDate) + const [hours, minutes] = appointment.slot.startTime.split(":") + const isPM = appointment.slot.startTime.includes("PM") - appointmentDate.setHours(isPM ? parseInt(hours) + 12 : parseInt(hours), parseInt(minutes.split(" ")[0])); + appointmentDate.setHours(isPM ? parseInt(hours) + 12 : parseInt(hours), parseInt(minutes.split(" ")[0])) - const currentTime = new Date(); - const threeHoursBefore = new Date(appointmentDate.getTime() - 3 * 60 * 60 * 1000); - return currentTime < threeHoursBefore; - }; + const currentTime = new Date() + const threeHoursBefore = new Date(appointmentDate.getTime() - 3 * 60 * 60 * 1000) + return currentTime < threeHoursBefore + } if (!patientToken) { - notFound(); + notFound() } if (!appointment) { - return
Loading appointment details...
; + return
Loading appointment details...
} + return ( -
+

Appointment Details

-
- +
+ - - Appointment Information - - +
+ Appointment Information + + {appointment.status} + +
-
- - {format(new Date(appointment.appointmentDate!), "PPPP")} -
-
- - {format(new Date(appointment.appointmentDate!), "p")} -
-
- {appointment.appointmentType === "video-consulting" ? ( -