import React, { useState } from "react"; import { useQuery, useMutation } from "@tanstack/react-query"; import { queryClient } from "@/client/rpc-client"; interface BookingStatusPageProps { token: string; } type BookingStatus = "pending" | "confirmed" | "cancelled" | "completed"; function getStatusInfo(status: BookingStatus) { switch (status) { case "pending": return { label: "Wartet auf Bestätigung", color: "yellow", icon: "⏳", bgColor: "bg-yellow-50", borderColor: "border-yellow-200", textColor: "text-yellow-800", badgeColor: "bg-yellow-100 text-yellow-800", }; case "confirmed": return { label: "Bestätigt", color: "green", icon: "✓", bgColor: "bg-green-50", borderColor: "border-green-200", textColor: "text-green-800", badgeColor: "bg-green-100 text-green-800", }; case "cancelled": return { label: "Storniert", color: "red", icon: "✕", bgColor: "bg-red-50", borderColor: "border-red-200", textColor: "text-red-800", badgeColor: "bg-red-100 text-red-800", }; case "completed": return { label: "Abgeschlossen", color: "gray", icon: "✓", bgColor: "bg-gray-50", borderColor: "border-gray-200", textColor: "text-gray-800", badgeColor: "bg-gray-100 text-gray-800", }; } } export default function BookingStatusPage({ token }: BookingStatusPageProps) { const [showCancelConfirm, setShowCancelConfirm] = useState(false); const [isCancelling, setIsCancelling] = useState(false); const [cancellationResult, setCancellationResult] = useState<{ success: boolean; message: string; formattedDate?: string } | null>(null); // Fetch booking details const { data: booking, isLoading, error, refetch } = useQuery( queryClient.cancellation.getBookingByToken.queryOptions({ input: { token } }) ); // Cancellation mutation const cancelMutation = useMutation({ ...queryClient.cancellation.cancelByToken.mutationOptions(), onSuccess: (result: any) => { setCancellationResult({ success: true, message: result.message, formattedDate: result.formattedDate, }); setIsCancelling(false); setShowCancelConfirm(false); refetch(); // Refresh booking data }, onError: (error: any) => { setCancellationResult({ success: false, message: error?.message || "Ein Fehler ist aufgetreten.", }); setIsCancelling(false); }, }); const handleCancel = () => { setIsCancelling(true); setCancellationResult(null); cancelMutation.mutate({ token }); }; if (isLoading) { return (
Buchung wird geladen...
); } if (error) { return (

Fehler

{error?.message || "Der Link ist ungültig oder abgelaufen."}

Zur Startseite
); } if (!booking) { return (

Buchung nicht gefunden

Die angeforderte Buchung konnte nicht gefunden werden.

Zur Startseite
); } const statusInfo = getStatusInfo(booking.status); return (
{/* Header */}
Stargil Nails Logo {statusInfo.icon} {statusInfo.label}

Buchungsübersicht

Hier findest du alle Details zu deinem Termin

{/* Cancellation Result */} {cancellationResult && (

{cancellationResult.message} {cancellationResult.formattedDate && ( <>
Stornierter Termin: {cancellationResult.formattedDate} )}

)} {/* Status Banner */}
{statusInfo.icon}

Status: {statusInfo.label}

{booking.status === "pending" && (

Wir haben deine Terminanfrage erhalten und werden sie in Kürze prüfen. Du erhältst eine E-Mail, sobald dein Termin bestätigt wurde.

)} {booking.status === "confirmed" && (

Dein Termin wurde bestätigt! Wir freuen uns auf dich. Du hast eine Bestätigungs-E-Mail mit Kalendereintrag erhalten.

)} {booking.status === "cancelled" && (

Dieser Termin wurde storniert. Du kannst jederzeit einen neuen Termin buchen.

)} {booking.status === "completed" && (

Dieser Termin wurde erfolgreich abgeschlossen. Vielen Dank für deinen Besuch!

)}
{/* Appointment Details */}

Termin-Details

Datum: {booking.formattedDate}
Uhrzeit: {booking.appointmentTime} Uhr
Behandlung: {booking.treatmentName}
Dauer: {booking.treatmentDuration} Minuten
{booking.treatmentPrice > 0 && (
Preis: {booking.treatmentPrice.toFixed(2)} €
)} {booking.hoursUntilAppointment > 0 && booking.status !== "cancelled" && booking.status !== "completed" && (
Verbleibende Zeit: {booking.hoursUntilAppointment} Stunde{booking.hoursUntilAppointment !== 1 ? 'n' : ''}
)}
{/* Customer Details */}

Deine Daten

Name: {booking.customerName}
E-Mail: {booking.customerEmail}
Telefon: {booking.customerPhone}
{booking.notes && (

Notizen:

{booking.notes}

)}
{/* Cancellation Section */} {booking.canCancel && !cancellationResult?.success && (

Termin stornieren

{!showCancelConfirm ? (

Du kannst diesen Termin noch bis {parseInt(process.env.MIN_STORNO_TIMESPAN || "24")} Stunden vor dem Termin kostenlos stornieren.

) : (

Bist du sicher?

Diese Aktion kann nicht rückgängig gemacht werden. Der Termin wird storniert und der Slot wird wieder für andere Kunden verfügbar.

)}
)} {!booking.canCancel && booking.status !== "cancelled" && booking.status !== "completed" && (

ℹ️ Stornierungsfrist abgelaufen: Dieser Termin liegt weniger als {parseInt(process.env.MIN_STORNO_TIMESPAN || "24")} Stunden in der Zukunft und kann nicht mehr online storniert werden. Bitte kontaktiere uns direkt.

)} {/* Footer */}
Zurück zur Startseite
); }