import { A, useParams } from "@solidjs/router"; import { For, Show, createResource, createSignal } from "solid-js"; import { apiClient } from "../lib/api-client"; import { useI18n } from "../providers/i18n-provider"; import type { components } from "@bookra/api-client/generated/types"; import { BookraCharacter } from "../components/bookra-character"; import { Button, Card, CardHeader, CardTitle, CardDescription, CardContent, Badge, Input, SkeletonCard, Textarea, Tooltip } from "../components/ui"; export function PublicBookingRoute() { const params = useParams(); const i18n = useI18n(); const tenantSlug = () => params.tenantSlug; const [bookingResult, setBookingResult] = createSignal(null); const [bookingError, setBookingError] = createSignal(null); const [submittingSlot, setSubmittingSlot] = createSignal(null); const [customerName, setCustomerName] = createSignal(""); const [customerEmail, setCustomerEmail] = createSignal(""); const [notes, setNotes] = createSignal(""); const [highlightContact, setHighlightContact] = createSignal(false); let contactFormRef: HTMLDivElement | undefined; const [availability, { refetch }] = createResource(() => { const slug = tenantSlug(); if (!slug) return null; return apiClient.GET("/v1/public/tenants/{tenantSlug}/availability", { params: { path: { tenantSlug: slug, }, }, }); }); const bookSlot = async (slot: components["schemas"]["TimeSlot"]) => { if (!customerName().trim() || !customerEmail().trim()) { setBookingError(i18n.t("booking.customerRequired")); setHighlightContact(true); contactFormRef?.scrollIntoView({ behavior: "smooth", block: "center" }); setTimeout(() => setHighlightContact(false), 2000); return; } setSubmittingSlot(slot.startsAt); setBookingResult(null); setBookingError(null); const slug = tenantSlug(); if (!slug) { setBookingError(i18n.locale() === 'cs' ? 'Chybí identifikátor podniku' : 'Business identifier missing'); setSubmittingSlot(null); return; } const response = await apiClient.POST("/v1/public/bookings", { body: { tenantSlug: slug, bookingMode: slot.mode, serviceId: slot.serviceId ?? undefined, classSessionId: slot.classSessionId ?? undefined, staffId: slot.staffId ?? undefined, locationId: slot.locationId ?? undefined, customerName: customerName().trim(), customerEmail: customerEmail().trim(), notes: notes().trim(), startsAt: slot.startsAt, endsAt: slot.endsAt, }, }); const payload = response as { data?: components["schemas"]["CreateBookingResponse"]; error?: unknown }; if (payload.error) { setBookingError(`${i18n.t("booking.failed")}: ${String(payload.error)}`); } else if (payload.data) { setBookingResult(`${i18n.t("booking.created")} ${payload.data.reference}`); setNotes(""); } setSubmittingSlot(null); void refetch(); }; return (
{/* Header */}

{i18n.t("booking.title")}

{i18n.t("booking.body")}

{i18n.locale() === 'cs' ? 'Podnik nenalezen' : 'Business not found'}

{i18n.locale() === 'cs' ? 'Zkontrolujte URL adresu nebo kontaktujte provozovatele.' : 'Please check the URL or contact the service provider.'}

{i18n.locale() === 'cs' ? 'Zpět na hlavní stránku' : 'Back to home'}
{/* Sidebar - Contact form - ORDER 1 on mobile, 2 on desktop */}
{ contactFormRef = el; }}> {i18n.t("booking.customer.title")} {i18n.t("booking.customer.body")} setCustomerName(event.currentTarget.value)} required value={customerName()} /> setCustomerEmail(event.currentTarget.value)} required type="email" value={customerEmail()} />