import type { Metadata } from "next"; import { notFound, redirect } from "next/navigation"; import { Card } from "@/components/ui/card"; import { TopNav } from "@/components/navigation/top-nav"; import { prisma } from "@/lib/db/prisma"; import { getActingStaff } from "@/lib/staff/get-acting-staff"; import { getAppointmentById } from "@/services/scheduling/appointment.service"; import { assertOwnAppointment, StaffPermissionDeniedError } from "@/features/staff/authorization"; import { rescheduleStaffAppointmentAction } from "@/features/staff/actions/appointment-actions"; import { BarberDateTimePicker } from "@/features/booking/components/barber-date-time-picker"; export const metadata: Metadata = { title: "Reschedule Appointment" }; export const dynamic = "force-dynamic"; const NON_RESCHEDULABLE = new Set(["COMPLETED", "CANCELLED", "NO_SHOW", "IN_PROGRESS"]); export default async function StaffRescheduleAppointmentPage({ params, }: { params: Promise<{ id: string }>; }) { const staff = await getActingStaff(); if (!staff) redirect("/home"); const { id } = await params; const appointment = await getAppointmentById(prisma, id); if (!appointment) notFound(); try { assertOwnAppointment(appointment, staff); } catch (error) { if (error instanceof StaffPermissionDeniedError) notFound(); throw error; } if (NON_RESCHEDULABLE.has(appointment.status)) { redirect(`/staff/appointments/${id}`); } async function handleContinue(selection: { staffId?: string; date: string; startAt: string }) { "use server"; const result = await rescheduleStaffAppointmentAction({ appointmentId: id, staffId: selection.staffId, startAt: selection.startAt, }); if (result.success) { redirect(`/staff/appointments/${id}`); } return result; } return (
{appointment.services.map((s) => s.service.name).join(" + ")} for{" "} {appointment.customer.firstName} {appointment.customer.lastName}
Currently:{" "} {appointment.startAt.toLocaleDateString("en-GB", { weekday: "short", day: "numeric", month: "short", timeZone: staff.business.timezone, })}{" "} ยท{" "} {appointment.startAt.toLocaleTimeString("en-GB", { hour: "2-digit", minute: "2-digit", timeZone: staff.business.timezone, })}