From a481d4fad3b5b35f4579bb12d845de0d56208b07 Mon Sep 17 00:00:00 2001 From: Maaxxs Date: Mon, 16 Nov 2026 00:08:19 +0000 Subject: [PATCH] Beratung: Monatskalender statt Tagesleiste bei der Terminwahl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tage ohne freie Zeiten sind ausgegraut, freie Tage mit Goldpunkt, gewählter Tag schwarz; Monatswechsel nur im buchbaren Zeitraum. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HsJ4RGtkeDbKNuzNFfPPiH --- src/components/shop/BookingCalendar.tsx | 84 +++++++++++++++++++++++++ src/components/shop/BookingForm.tsx | 9 +-- src/styles/shop.css | 30 ++++++++- 3 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 src/components/shop/BookingCalendar.tsx diff --git a/src/components/shop/BookingCalendar.tsx b/src/components/shop/BookingCalendar.tsx new file mode 100644 index 0000000..fd162d7 --- /dev/null +++ b/src/components/shop/BookingCalendar.tsx @@ -0,0 +1,84 @@ +"use client"; +import { useEffect, useMemo, useState } from "react"; + +type Day = { date: string; slots: string[] }; + +const BERLIN = "Europe/Berlin"; +const WEEKDAYS = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"]; +const monthFmt = new Intl.DateTimeFormat("de-DE", { month: "long", year: "numeric", timeZone: "UTC" }); +const longFmt = new Intl.DateTimeFormat("de-DE", { weekday: "long", day: "numeric", month: "long", timeZone: "UTC" }); + +const iso = (y: number, m: number, d: number) => `${y}-${String(m + 1).padStart(2, "0")}-${String(d).padStart(2, "0")}`; +const monthOf = (date: string) => date.slice(0, 7); +const shiftMonth = (ym: string, by: number) => { + const [y, m] = ym.split("-").map(Number); + const d = new Date(Date.UTC(y, m - 1 + by, 1)); + return `${d.getUTCFullYear()}-${String(d.getUTCMonth() + 1).padStart(2, "0")}`; +}; + +/** Monatskalender für die Terminwahl: nur Tage mit freien Zeiten sind wählbar. */ +export function BookingCalendar({ days, value, onChange }: { days: Day[]; value: string; onChange: (date: string) => void }) { + const free = useMemo(() => new Map(days.map((d) => [d.date, d.slots.length])), [days]); + const first = days[0]?.date ?? ""; + const last = days[days.length - 1]?.date ?? ""; + const [month, setMonth] = useState(monthOf(value || first)); + // Bei Wechsel des Angebots oder Datums den passenden Monat zeigen + useEffect(() => { if (value) setMonth(monthOf(value)); }, [value]); + // "Heute" erst im Browser bestimmen, damit Server und Browser gleich rendern + const [today, setToday] = useState(""); + useEffect(() => setToday(new Intl.DateTimeFormat("en-CA", { timeZone: BERLIN }).format(new Date())), []); + + const [y, m] = month.split("-").map(Number); + const lead = (new Date(Date.UTC(y, m - 1, 1)).getUTCDay() + 6) % 7; // Montag zuerst + const count = new Date(Date.UTC(y, m, 0)).getUTCDate(); + const cells: (string | null)[] = [...Array(lead).fill(null), ...Array.from({ length: count }, (_, i) => iso(y, m - 1, i + 1))]; + while (cells.length % 7) cells.push(null); + + const canPrev = first !== "" && month > monthOf(first); + const canNext = last !== "" && month < monthOf(last); + const freeInMonth = days.filter((d) => monthOf(d.date) === month).length; + + return ( +
+
+ +
+ {monthFmt.format(new Date(`${month}-01T12:00:00Z`))} + {freeInMonth === 0 ? "keine freien Tage" : freeInMonth === 1 ? "1 freier Tag" : `${freeInMonth} freie Tage`} +
+ +
+
+ {WEEKDAYS.map((w) => )} + {cells.map((d, i) => { + if (!d) return
+ +
+ ); +} + +export const longDate = (d: string) => longFmt.format(new Date(`${d}T12:00:00Z`)); diff --git a/src/components/shop/BookingForm.tsx b/src/components/shop/BookingForm.tsx index f96b3a0..b203418 100644 --- a/src/components/shop/BookingForm.tsx +++ b/src/components/shop/BookingForm.tsx @@ -5,6 +5,7 @@ import { requestAppointment } from "@/app/(shop)/beratung/actions"; import { Field, TextareaField } from "../Field"; import { Icon } from "../Icon"; import { Alert } from "./Blocks"; +import { BookingCalendar, longDate } from "./BookingCalendar"; type Offer = { id: string; name: string; description: string; duration: number; price: number; mode: string }; type Days = { date: string; slots: string[] }[]; @@ -34,7 +35,6 @@ export function BookingForm(props: { useEffect(() => setZone(Intl.DateTimeFormat().resolvedOptions().timeZone || BERLIN), []); const time = useMemo(() => new Intl.DateTimeFormat("de-DE", { timeZone: zone, hour: "2-digit", minute: "2-digit" }), [zone]); const berlinTime = useMemo(() => new Intl.DateTimeFormat("de-DE", { timeZone: BERLIN, hour: "2-digit", minute: "2-digit" }), []); - const dayLabel = (d: string) => new Intl.DateTimeFormat("de-DE", { weekday: "short", day: "2-digit", month: "2-digit", timeZone: "UTC" }).format(new Date(`${d}T12:00:00Z`)); const errors = state?.errors ?? {}; const pickOffer = (id: string) => { @@ -89,11 +89,8 @@ export function BookingForm(props: {

Für dieses Angebot sind gerade keine Zeiten frei. Schau bald wieder vorbei.

) : ( <> -
- {days.map((d) => ( - - ))} -
+ { setDate(d); setStart(""); }} /> + {date &&

{longDate(date)}

}
{slotsOfDay.map((s) => ( diff --git a/src/styles/shop.css b/src/styles/shop.css index c1c840a..1b4d2ca 100644 --- a/src/styles/shop.css +++ b/src/styles/shop.css @@ -352,8 +352,34 @@ button.sm-pdp__main { display: block; width: 100%; padding: 0; border: 0; cursor .sm-booking__offers .sm-option strong { display: block; } .sm-option__price { font-weight: 500; white-space: nowrap; } .sm-booking__modes { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); } -.sm-booking__days { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: var(--space-2); scrollbar-width: thin; } -.sm-booking__days .sm-chip { flex: none; } +.sm-booking__dayhead { margin: var(--space-5) 0 0; font-family: var(--font-serif); font-size: 22px; line-height: 28px; font-weight: 500; color: var(--ink); } + +/* Terminkalender (Monatsansicht) */ +.sm-cal { padding: var(--space-4) var(--space-4) var(--space-3); border: var(--hairline) solid var(--line); border-radius: var(--radius-md); background: linear-gradient(180deg, var(--surface) 0%, var(--surface-raised) 72px); } +.sm-cal__head { display: grid; grid-template-columns: 36px 1fr 36px; align-items: center; gap: var(--space-2); margin-bottom: var(--space-4); } +.sm-cal__title { display: flex; flex-direction: column; align-items: center; text-align: center; } +.sm-cal__title span { font-family: var(--font-serif); font-size: 24px; line-height: 28px; font-weight: 500; letter-spacing: 0.01em; color: var(--ink); } +.sm-cal__title small { margin-top: 2px; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold-deep); } +.sm-cal__nav { display: grid; place-content: center; width: 36px; height: 36px; padding: 0; border: var(--hairline) solid var(--line); border-radius: var(--radius-pill); background: var(--surface-raised); color: var(--ink); cursor: pointer; transition: border-color 200ms, background-color 200ms, color 200ms; } +.sm-cal__nav svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; } +.sm-cal__nav:hover:not(:disabled) { border-color: var(--gold-deep); color: var(--gold-deep); } +.sm-cal__nav:disabled { opacity: 0.3; cursor: default; } +.sm-cal__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; } +.sm-cal__wd { padding-bottom: var(--space-2); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; text-align: center; color: var(--ink-subtle); } +.sm-cal__day { position: relative; display: grid; place-content: center; aspect-ratio: 1; min-height: 36px; max-height: 48px; padding: 0; border: var(--hairline) solid transparent; border-radius: var(--radius-pill); background: none; font-family: var(--font-sans); font-size: 15px; line-height: 1; font-variant-numeric: tabular-nums; color: var(--ink); transition: background-color 180ms, border-color 180ms, color 180ms, transform 180ms; } +.sm-cal__day.is-free { cursor: pointer; font-weight: 500; } +.sm-cal__day.is-free::after { content: ""; position: absolute; left: 50%; bottom: 18%; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--gold); } +.sm-cal__day.is-free:hover { border-color: var(--gold); background: var(--gold-soft); } +.sm-cal__day.is-off { color: var(--ink-subtle); opacity: 0.45; cursor: default; } +.sm-cal__day.is-today { border-color: var(--line-strong); } +.sm-cal__day.is-selected, .sm-cal__day.is-selected:hover { border-color: var(--ink); background: var(--ink); color: var(--surface); transform: scale(1.04); box-shadow: var(--shadow-md); } +.sm-cal__day.is-selected::after { background: var(--gold); } +.sm-cal__day:focus-visible, .sm-cal__nav:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; } +.sm-cal__legend { display: flex; justify-content: center; gap: var(--space-5); margin-top: var(--space-3); padding-top: var(--space-3); border-top: var(--hairline) solid var(--line); font-size: 12px; color: var(--ink-muted); } +.sm-cal__legend span { display: inline-flex; align-items: center; gap: 6px; } +.sm-cal__dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); } +.sm-cal__dot.is-off { background: var(--line-strong); opacity: 0.45; } +@media (max-width: 380px) { .sm-cal { padding: var(--space-3) var(--space-2) var(--space-2); } .sm-cal__day { font-size: 14px; } } .sm-booking__times { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: var(--space-2); margin: var(--space-3) 0 var(--space-2); } .sm-booking__times .sm-chip { justify-content: center; padding: 0; } .sm-booking__summary { margin: 0 0 var(--space-4); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); background: var(--gold-soft); color: var(--ink); font-size: 15px; line-height: 22px; }