91 lines
4.5 KiB
TypeScript
91 lines
4.5 KiB
TypeScript
// AK-P16b · public booking page (M06 Block G) — minimal FUNCTIONAL UI (reachable +
|
|
// i18n + states), NOT the bespoke Calendly-polish screen (that waits on David D-P16).
|
|
// Single-page flow: pick a slot → fill the mini-form (GDPR required) → confirmation
|
|
// with an "add to calendar" (.ics) download. The component reads route-injected data
|
|
// only (no DB import); it is in apps/web so useLoaderData is allowed here.
|
|
|
|
import { Form, useActionData, useLoaderData, useNavigation } from "react-router";
|
|
import { useTranslation } from "react-i18next";
|
|
import type { PublicBookingLoaderData, PublicBookingActionData } from "../routes/PublicBooking.server";
|
|
|
|
export default function PublicBookingRoute(): JSX.Element {
|
|
const vm = useLoaderData<PublicBookingLoaderData>();
|
|
const actionData = useActionData<PublicBookingActionData>();
|
|
const navigation = useNavigation();
|
|
const { t } = useTranslation();
|
|
const submitting = navigation.state === "submitting";
|
|
|
|
if (actionData?.ok) {
|
|
const icsHref = `data:text/calendar;base64,${actionData.icsBase64}`;
|
|
return (
|
|
<main data-ui-id="ui.booking.public" className={vm.isEmbed ? "p-4" : "mx-auto max-w-xl p-6"}>
|
|
<h1 className="text-xl font-semibold">{t("bookings.public.confirmedHeadline")}</h1>
|
|
<p className="mt-2">
|
|
{t("bookings.public.confirmedBody", { title: actionData.titleLabel, date: actionData.dateLabel, time: actionData.timeLabel })}
|
|
</p>
|
|
<a data-ui-id="ui.booking.public.ics" href={icsHref} download="termin.ics" className="mt-4 inline-block underline">
|
|
{t("bookings.public.addToCalendar")}
|
|
</a>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<main data-ui-id="ui.booking.public" className={vm.isEmbed ? "p-4" : "mx-auto max-w-xl p-6"}>
|
|
<header>
|
|
<p className="text-sm text-muted-foreground">{vm.tenantName}</p>
|
|
<h1 className="text-xl font-semibold">{vm.title}</h1>
|
|
{vm.description ? <p className="mt-1 text-muted-foreground">{vm.description}</p> : null}
|
|
<p className="mt-1 text-sm">{t("bookings.public.duration", { minutes: vm.durationMinutes })}</p>
|
|
</header>
|
|
|
|
{actionData && !actionData.ok ? (
|
|
<p data-ui-id="ui.booking.public.error" role="alert" className="mt-4 text-red-600">
|
|
{t(actionData.errorKey)}
|
|
</p>
|
|
) : null}
|
|
|
|
{vm.slots.length === 0 ? (
|
|
<p data-ui-id="ui.booking.public.empty" className="mt-6">
|
|
{t("bookings.public.noSlots")}
|
|
</p>
|
|
) : (
|
|
<Form method="post" className="mt-6 space-y-4" data-ui-id="ui.booking.public.form">
|
|
<input type="hidden" name="date" value={vm.date} />
|
|
<input type="hidden" name="tz" value={vm.timezone} />
|
|
{/* Honeypot — hidden from real users (M06 abuse guard). */}
|
|
<input type="text" name="company" tabIndex={-1} autoComplete="off" className="hidden" aria-hidden="true" />
|
|
|
|
<fieldset>
|
|
<legend className="text-sm font-medium">{t("bookings.public.chooseSlot", { date: vm.date })}</legend>
|
|
<div className="mt-2 flex flex-wrap gap-2">
|
|
{vm.slots.map((slot, index) => (
|
|
<label key={slot.startAtIso} className="cursor-pointer rounded border px-3 py-1">
|
|
<input type="radio" name="startAt" value={slot.startAtIso} defaultChecked={index === 0} className="mr-1" />
|
|
{slot.label}
|
|
</label>
|
|
))}
|
|
</div>
|
|
</fieldset>
|
|
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<input name="vorname" placeholder={t("bookings.public.firstName")} className="rounded border px-3 py-2" required />
|
|
<input name="nachname" placeholder={t("bookings.public.lastName")} className="rounded border px-3 py-2" required />
|
|
</div>
|
|
<input name="email" type="email" placeholder={t("bookings.public.email")} className="w-full rounded border px-3 py-2" required />
|
|
<input name="telefon" placeholder={t("bookings.public.phone")} className="w-full rounded border px-3 py-2" />
|
|
|
|
<label className="flex items-start gap-2 text-sm">
|
|
<input type="checkbox" name="gdpr" required className="mt-1" />
|
|
<span>{t("bookings.public.gdpr")}</span>
|
|
</label>
|
|
|
|
<button type="submit" disabled={submitting} data-ui-id="ui.booking.public.submit" className="rounded bg-primary px-4 py-2 text-primary-foreground disabled:opacity-50">
|
|
{submitting ? t("bookings.public.submitting") : t("bookings.public.submit")}
|
|
</button>
|
|
</Form>
|
|
)}
|
|
</main>
|
|
);
|
|
}
|