diff --git a/apps/frontend/src/features/public-booking/public-booking-page.tsx b/apps/frontend/src/features/public-booking/public-booking-page.tsx index 6587a83..eec3fab 100644 --- a/apps/frontend/src/features/public-booking/public-booking-page.tsx +++ b/apps/frontend/src/features/public-booking/public-booking-page.tsx @@ -108,6 +108,8 @@ type BookingShellProps = { onSelectDate: (date: string) => void; onPreviousDays: () => void; onNextDays: () => void; + onPreviousDay: () => void; + onNextDay: () => void; onSelectSport: (sportId: string) => void; onSelectCourt: (courtId: string) => void; onSelectSlot: (slot: SelectedSlot) => void; @@ -527,9 +529,6 @@ function PublicBookingDesktop(props: BookingShellProps) { sportSelectionRequired, errorMessage, autoAdjustedDateNotice, - onPreviousDays, - onNextDays, - onSelectDate, onSelectSport, onSelectCourt, onSelectSlot, @@ -538,6 +537,8 @@ function PublicBookingDesktop(props: BookingShellProps) { const currentStep = getStep(selectedSlot, props.form.formState.isValid); const completedSteps = getCompletedSteps(selectedSlot, props.form.formState.isValid); const selectedDay = dayOptions.find((option) => option.value === selectedDate); + const currentDayIndex = dayOptions.findIndex((option) => option.value === selectedDate); + const canGoBackButton = canGoBack || currentDayIndex > 0; return ( @@ -648,8 +649,8 @@ function PublicBookingDesktop(props: BookingShellProps) { @@ -670,44 +671,6 @@ function PublicBookingDesktop(props: BookingShellProps) { - - - Cambiá de día - - - - - {dayOptions.map((option) => ( - onSelectDate(option.value)} - className={`rounded-md border px-3 py-3 text-center transition ${ - selectedDate === option.value - ? 'border-emerald-500 bg-emerald-500/18 text-white' - : 'border-white/10 bg-white/[0.035] text-white/76 hover:bg-white/[0.06]' - }`} - > - {option.weekday} - {option.dayMonth} - - ))} - - - - - @@ -757,10 +720,10 @@ function PublicBookingMobile(props: BookingShellProps) { Fecha @@ -770,9 +733,9 @@ function PublicBookingMobile(props: BookingShellProps) { @@ -804,43 +767,6 @@ function PublicBookingMobile(props: BookingShellProps) { - - - - - - - {props.dayOptions.map((option) => ( - props.onSelectDate(option.value)} - className={`rounded-md border px-1 py-2 text-center transition ${ - props.selectedDate === option.value - ? 'border-emerald-500 bg-emerald-500/18 text-white' - : 'border-white/10 bg-white/[0.035] text-white/70' - }`} - > - {option.weekday} - {option.shortDay} - - ))} - - - - - ); @@ -1298,6 +1224,7 @@ export function PublicBookingPage({ complexSlug }: PublicBookingPageProps) { const availabilityQuery = useQuery({ queryKey: ['public-booking-availability', complexSlug, selectedDate, selectedSportId], enabled: Boolean(selectedDate), + placeholderData: (previousData) => previousData, queryFn: () => apiClient.publicBookings.getAvailability(complexSlug, { date: selectedDate, @@ -1516,6 +1443,42 @@ export function PublicBookingPage({ complexSlug }: PublicBookingPageProps) { }); }; + const goToPreviousDay = () => { + const currentIndex = dayOptions.findIndex((o) => o.value === selectedDate); + if (currentIndex > 0) { + const prevDate = dayOptions[currentIndex - 1].value; + setSelectedDate(prevDate); + setSelectedSlot(null); + setAutoAdjustedDateNotice(null); + return; + } + if (windowStartOffset > 0) { + const newOffset = windowStartOffset - 1; + const newStartDate = toIsoDateLocal(addDays(today, newOffset)); + setWindowStartOffset(newOffset); + setSelectedDate(newStartDate); + setSelectedSlot(null); + setAutoAdjustedDateNotice(null); + } + }; + + const goToNextDay = () => { + const currentIndex = dayOptions.findIndex((o) => o.value === selectedDate); + if (currentIndex < dayOptions.length - 1) { + const nextDate = dayOptions[currentIndex + 1].value; + setSelectedDate(nextDate); + setSelectedSlot(null); + setAutoAdjustedDateNotice(null); + return; + } + const newOffset = windowStartOffset + 1; + const nextDate = toIsoDateLocal(addDays(today, newOffset)); + setWindowStartOffset(newOffset); + setSelectedDate(nextDate); + setSelectedSlot(null); + setAutoAdjustedDateNotice(null); + }; + const shellProps: BookingShellProps = { complexName: availabilityQuery.data?.complexName, complexAddress: availabilityQuery.data?.complexAddress, @@ -1543,6 +1506,8 @@ export function PublicBookingPage({ complexSlug }: PublicBookingPageProps) { onSelectDate: selectDate, onPreviousDays: goToPreviousDays, onNextDays: goToNextDays, + onPreviousDay: goToPreviousDay, + onNextDay: goToNextDay, onSelectSport: (sportId) => { setSelectedSportId(sportId); setSelectedCourtId(undefined);