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 (
Hier findest du alle Details zu deinem Termin
{cancellationResult.message}
{cancellationResult.formattedDate && (
<>
Stornierter Termin: {cancellationResult.formattedDate}>
)}
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!
)}{booking.notes}
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.
ℹ️ 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.