Merge pull request 'Fixed mobile bottom toolbar' (#13) from mobile-fixes into development
Reviewed-on: https://gitea.2pidev.com/jselesan/playzer/pulls/13
This commit is contained in:
@@ -17,6 +17,7 @@ function statusFromError(error: AppError): ContentfulStatusCode {
|
|||||||
case 'unexpected':
|
case 'unexpected':
|
||||||
return 500;
|
return 500;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
return 500;
|
return 500;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
CircleDot,
|
CircleDot,
|
||||||
|
Download,
|
||||||
Dumbbell,
|
Dumbbell,
|
||||||
Grid2X2,
|
Grid2X2,
|
||||||
Laptop,
|
Laptop,
|
||||||
@@ -38,10 +39,13 @@ import { useBooking } from '../booking-provider';
|
|||||||
import type { BookingCourtSchedule, BookingTimelineSegment } from '../booking.types';
|
import type { BookingCourtSchedule, BookingTimelineSegment } from '../booking.types';
|
||||||
import { fromIsoDateLocal, toIsoDateLocal } from '../lib/booking-time';
|
import { fromIsoDateLocal, toIsoDateLocal } from '../lib/booking-time';
|
||||||
|
|
||||||
|
type MobileTab = 'panel' | 'status' | 'bookings' | 'more';
|
||||||
|
|
||||||
export function BookingMobile() {
|
export function BookingMobile() {
|
||||||
const { schedules, isLoading, isError, errorMessage } = useBooking();
|
const { schedules, isLoading, isError, errorMessage } = useBooking();
|
||||||
const [selectedCourtId, setSelectedCourtId] = useState<string | null>(null);
|
const [selectedCourtId, setSelectedCourtId] = useState<string | null>(null);
|
||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
|
const [activeTab, setActiveTab] = useState<MobileTab>('panel');
|
||||||
|
|
||||||
const selectedSchedule = useMemo(() => {
|
const selectedSchedule = useMemo(() => {
|
||||||
if (!selectedCourtId) return null;
|
if (!selectedCourtId) return null;
|
||||||
@@ -67,52 +71,60 @@ export function BookingMobile() {
|
|||||||
<div className="min-h-dvh pb-24">
|
<div className="min-h-dvh pb-24">
|
||||||
<MobileTopBar />
|
<MobileTopBar />
|
||||||
<div className="space-y-6 px-3 pt-5">
|
<div className="space-y-6 px-3 pt-5">
|
||||||
<MobilePanelHeader />
|
{activeTab === 'panel' && (
|
||||||
<MobileFilters />
|
<>
|
||||||
<MobileSummary />
|
<MobilePanelHeader />
|
||||||
|
<MobileFilters />
|
||||||
|
<MobileSummary />
|
||||||
|
|
||||||
<section className="space-y-4">
|
<section className="space-y-4">
|
||||||
<h2 className="text-xl font-semibold tracking-normal">Canchas</h2>
|
<h2 className="text-xl font-semibold tracking-normal">Canchas</h2>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Search className="pointer-events-none absolute left-3 top-1/2 size-5 -translate-y-1/2 text-muted-foreground" />
|
<Search className="pointer-events-none absolute left-3 top-1/2 size-5 -translate-y-1/2 text-muted-foreground" />
|
||||||
<Input
|
<Input
|
||||||
className="h-12 rounded-lg border-border/70 bg-card/75 pl-11 text-sm shadow-sm"
|
className="h-12 rounded-lg border-border/70 bg-card/75 pl-11 text-sm shadow-sm"
|
||||||
placeholder="Buscar cancha..."
|
placeholder="Buscar cancha..."
|
||||||
value={search}
|
value={search}
|
||||||
onChange={(event) => setSearch(event.target.value)}
|
onChange={(event) => setSearch(event.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{isLoading && (
|
{isLoading && (
|
||||||
<div className="rounded-lg border bg-card/75 px-4 py-8 text-sm text-muted-foreground">
|
<div className="rounded-lg border bg-card/75 px-4 py-8 text-sm text-muted-foreground">
|
||||||
Cargando reservas...
|
Cargando reservas...
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{isError && !isLoading && (
|
{isError && !isLoading && (
|
||||||
<div className="rounded-lg border bg-card/75 px-4 py-8 text-sm text-destructive">
|
<div className="rounded-lg border bg-card/75 px-4 py-8 text-sm text-destructive">
|
||||||
{errorMessage}
|
{errorMessage}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isLoading && !isError && filteredSchedules.length === 0 && (
|
{!isLoading && !isError && filteredSchedules.length === 0 && (
|
||||||
<div className="rounded-lg border bg-card/75 px-4 py-8 text-sm text-muted-foreground">
|
<div className="rounded-lg border bg-card/75 px-4 py-8 text-sm text-muted-foreground">
|
||||||
No hay canchas para los filtros seleccionados.
|
No hay canchas para los filtros seleccionados.
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isLoading &&
|
{!isLoading &&
|
||||||
!isError &&
|
!isError &&
|
||||||
filteredSchedules.map((schedule) => (
|
filteredSchedules.map((schedule) => (
|
||||||
<MobileCourtCard
|
<MobileCourtCard
|
||||||
key={schedule.court.id}
|
key={schedule.court.id}
|
||||||
schedule={schedule}
|
schedule={schedule}
|
||||||
onOpen={() => setSelectedCourtId(schedule.court.id)}
|
onOpen={() => setSelectedCourtId(schedule.court.id)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</section>
|
</section>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === 'status' && <MobileStatusTab />}
|
||||||
|
{activeTab === 'bookings' && <MobileBookingsTab />}
|
||||||
|
{activeTab === 'more' && <MobileMoreTab />}
|
||||||
</div>
|
</div>
|
||||||
<MobileBottomNav active="panel" />
|
<MobileBottomNav active={activeTab} onSelect={setActiveTab} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -406,6 +418,262 @@ function MobileSummary() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function MobileStatusTab() {
|
||||||
|
const {
|
||||||
|
courts,
|
||||||
|
selectedSportId,
|
||||||
|
selectedStatus,
|
||||||
|
visibleTimeRange,
|
||||||
|
setSelectedSportId,
|
||||||
|
setSelectedStatus,
|
||||||
|
setVisibleTimeRange,
|
||||||
|
} = useBooking();
|
||||||
|
const sports = [...new Map(courts.map((court) => [court.sport.id, court.sport])).values()];
|
||||||
|
const activeRangeValue = `${visibleTimeRange.start}-${visibleTimeRange.end}`;
|
||||||
|
const statusOptions = [
|
||||||
|
{ value: 'all', label: 'Todos' },
|
||||||
|
{ value: 'free', label: 'Libres' },
|
||||||
|
{ value: 'reserved', label: 'Reservados' },
|
||||||
|
{ value: 'maintenance', label: 'Mantenimiento' },
|
||||||
|
] as const;
|
||||||
|
const timeRangeOptions = [
|
||||||
|
{ label: '08:00 - 22:00', start: '08:00', end: '22:00' },
|
||||||
|
{ label: '06:00 - 00:00', start: '06:00', end: '23:59' },
|
||||||
|
{ label: '08:00 - 14:00', start: '08:00', end: '14:00' },
|
||||||
|
{ label: '14:00 - 22:00', start: '14:00', end: '22:00' },
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<section>
|
||||||
|
<h1 className="text-2xl font-semibold tracking-normal">Estado</h1>
|
||||||
|
<p className="mt-1 text-sm text-muted-foreground">Filtra disponibilidad por cancha.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<MobileFilters />
|
||||||
|
<MobileSummary />
|
||||||
|
|
||||||
|
<section className="space-y-3 rounded-lg border border-border/70 bg-card/70 p-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p className="text-sm font-medium">Estado</p>
|
||||||
|
<div className="grid grid-cols-2 gap-2">
|
||||||
|
{statusOptions.map((option) => (
|
||||||
|
<MobileFilterChip
|
||||||
|
key={option.value}
|
||||||
|
active={selectedStatus === option.value}
|
||||||
|
label={option.label}
|
||||||
|
onClick={() => setSelectedStatus(option.value)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p className="text-sm font-medium">Deporte</p>
|
||||||
|
<div className="flex gap-2 overflow-x-auto pb-1">
|
||||||
|
<MobileFilterChip
|
||||||
|
active={selectedSportId === 'all'}
|
||||||
|
label="Todos"
|
||||||
|
onClick={() => setSelectedSportId('all')}
|
||||||
|
/>
|
||||||
|
{sports.map((sport) => (
|
||||||
|
<MobileFilterChip
|
||||||
|
key={sport.id}
|
||||||
|
active={selectedSportId === sport.id}
|
||||||
|
label={sport.name}
|
||||||
|
onClick={() => setSelectedSportId(sport.id)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p className="text-sm font-medium">Horario visible</p>
|
||||||
|
<div className="grid grid-cols-2 gap-2">
|
||||||
|
{timeRangeOptions.map((option) => (
|
||||||
|
<MobileFilterChip
|
||||||
|
key={`${option.start}-${option.end}`}
|
||||||
|
active={activeRangeValue === `${option.start}-${option.end}`}
|
||||||
|
label={option.label}
|
||||||
|
onClick={() => setVisibleTimeRange({ start: option.start, end: option.end })}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="rounded-lg border border-border/70 bg-card/70 p-4">
|
||||||
|
<StatusLegend />
|
||||||
|
</section>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MobileFilterChip({
|
||||||
|
active,
|
||||||
|
label,
|
||||||
|
onClick,
|
||||||
|
}: {
|
||||||
|
active: boolean;
|
||||||
|
label: string;
|
||||||
|
onClick: () => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant={active ? 'default' : 'outline'}
|
||||||
|
className={cn(
|
||||||
|
'h-11 shrink-0 rounded-lg px-4 text-sm',
|
||||||
|
!active && 'border-border/70 bg-secondary/45 text-muted-foreground'
|
||||||
|
)}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MobileBookingsTab() {
|
||||||
|
const { selectedDate, schedules, openBookingTools, openCreateBooking } = useBooking();
|
||||||
|
const reservedSegments = schedules
|
||||||
|
.flatMap((schedule) =>
|
||||||
|
schedule.segments
|
||||||
|
.filter((segment) => segment.booking)
|
||||||
|
.map((segment) => ({ schedule, segment }))
|
||||||
|
)
|
||||||
|
.sort((a, b) => a.segment.startMinutes - b.segment.startMinutes);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<section className="flex items-start justify-between gap-4">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-2xl font-semibold tracking-normal">Reservas</h1>
|
||||||
|
<p className="mt-1 text-sm text-muted-foreground">{formatMobileDate(selectedDate)}</p>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
className="h-11 shrink-0 rounded-lg px-3 shadow-lg shadow-primary/20"
|
||||||
|
onClick={() => openCreateBooking()}
|
||||||
|
>
|
||||||
|
<Plus className="size-4" />
|
||||||
|
Nueva
|
||||||
|
</Button>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<MobileFilters />
|
||||||
|
|
||||||
|
<section className="space-y-3">
|
||||||
|
{reservedSegments.length === 0 ? (
|
||||||
|
<div className="rounded-lg border border-border/70 bg-card/75 px-4 py-8 text-sm text-muted-foreground">
|
||||||
|
No hay reservas para este día.
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
reservedSegments.map(({ schedule, segment }) => (
|
||||||
|
<button
|
||||||
|
key={segment.id}
|
||||||
|
type="button"
|
||||||
|
className="grid w-full grid-cols-[1fr_auto] items-center gap-3 rounded-lg border border-border/70 bg-card/75 p-4 text-left shadow-sm"
|
||||||
|
onClick={() => openBookingTools(segment)}
|
||||||
|
>
|
||||||
|
<div className="min-w-0">
|
||||||
|
<p className="truncate text-base font-semibold">{segment.booking?.customerName}</p>
|
||||||
|
<p className="mt-1 text-sm text-muted-foreground">
|
||||||
|
{schedule.court.name} · {schedule.court.sport.name}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="text-right">
|
||||||
|
<p className="text-sm font-medium">
|
||||||
|
{segment.startTime} - {segment.endTime}
|
||||||
|
</p>
|
||||||
|
<p className="mt-1 text-xs text-reserved">Reservado</p>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MobileMoreTab() {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { currentComplexSlug } = useCurrentComplexStore();
|
||||||
|
const { openCreateBooking, exportDayReport } = useBooking();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<section>
|
||||||
|
<h1 className="text-2xl font-semibold tracking-normal">Más</h1>
|
||||||
|
<p className="mt-1 text-sm text-muted-foreground">Accesos rápidos del panel.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="overflow-hidden rounded-lg border border-border/70 bg-card/75">
|
||||||
|
<MobileMenuAction
|
||||||
|
icon={<CalendarDays className="size-5" />}
|
||||||
|
label="Nueva reserva"
|
||||||
|
onClick={() => openCreateBooking()}
|
||||||
|
/>
|
||||||
|
<MobileMenuAction
|
||||||
|
icon={<Download className="size-5" />}
|
||||||
|
label="Exportar reservas del día"
|
||||||
|
onClick={exportDayReport}
|
||||||
|
/>
|
||||||
|
<MobileMenuAction
|
||||||
|
icon={<User className="size-5" />}
|
||||||
|
label="Mi perfil"
|
||||||
|
onClick={() => {
|
||||||
|
void navigate({ to: '/profile' });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{currentComplexSlug && (
|
||||||
|
<MobileMenuAction
|
||||||
|
icon={<Settings className="size-5" />}
|
||||||
|
label="Configuración del complejo"
|
||||||
|
onClick={() => {
|
||||||
|
void navigate({
|
||||||
|
to: '/complex/$slug/edit',
|
||||||
|
params: { slug: currentComplexSlug },
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MobileMenuAction({
|
||||||
|
icon,
|
||||||
|
label,
|
||||||
|
onClick,
|
||||||
|
}: {
|
||||||
|
icon: React.ReactNode;
|
||||||
|
label: string;
|
||||||
|
onClick: () => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="flex min-h-14 w-full items-center justify-between gap-3 border-b border-border/70 px-4 py-3 text-left last:border-b-0"
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
|
<span className="inline-flex items-center gap-3 font-medium">
|
||||||
|
<span className="text-muted-foreground">{icon}</span>
|
||||||
|
{label}
|
||||||
|
</span>
|
||||||
|
<ChevronRight className="size-5 text-muted-foreground" />
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatMobileDate(date: string) {
|
||||||
|
return new Intl.DateTimeFormat('es-AR', {
|
||||||
|
day: 'numeric',
|
||||||
|
month: 'long',
|
||||||
|
year: 'numeric',
|
||||||
|
}).format(new Date(`${date}T00:00:00`));
|
||||||
|
}
|
||||||
|
|
||||||
function SummaryPill({
|
function SummaryPill({
|
||||||
value,
|
value,
|
||||||
label,
|
label,
|
||||||
@@ -729,28 +997,38 @@ function MetricDots({ schedule }: { schedule: BookingCourtSchedule }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function MobileBottomNav({ active }: { active: 'panel' | 'status' | 'bookings' | 'more' }) {
|
function MobileBottomNav({
|
||||||
|
active,
|
||||||
|
onSelect,
|
||||||
|
}: {
|
||||||
|
active: MobileTab;
|
||||||
|
onSelect: (tab: MobileTab) => void;
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<nav className="fixed inset-x-0 bottom-0 z-40 grid grid-cols-4 border-t border-border/70 bg-background/90 px-2 pb-3 pt-2 backdrop-blur-xl">
|
<nav className="fixed inset-x-0 bottom-0 z-40 grid grid-cols-4 border-t border-border/70 bg-background/90 px-2 pb-3 pt-2 backdrop-blur-xl">
|
||||||
<BottomNavItem
|
<BottomNavItem
|
||||||
active={active === 'panel'}
|
active={active === 'panel'}
|
||||||
icon={<Grid2X2 className="size-5" />}
|
icon={<Grid2X2 className="size-5" />}
|
||||||
label="Panel"
|
label="Panel"
|
||||||
|
onClick={() => onSelect('panel')}
|
||||||
/>
|
/>
|
||||||
<BottomNavItem
|
<BottomNavItem
|
||||||
active={active === 'status'}
|
active={active === 'status'}
|
||||||
icon={<ListChecks className="size-5" />}
|
icon={<ListChecks className="size-5" />}
|
||||||
label="Estado"
|
label="Estado"
|
||||||
|
onClick={() => onSelect('status')}
|
||||||
/>
|
/>
|
||||||
<BottomNavItem
|
<BottomNavItem
|
||||||
active={active === 'bookings'}
|
active={active === 'bookings'}
|
||||||
icon={<CalendarDays className="size-5" />}
|
icon={<CalendarDays className="size-5" />}
|
||||||
label="Reservas"
|
label="Reservas"
|
||||||
|
onClick={() => onSelect('bookings')}
|
||||||
/>
|
/>
|
||||||
<BottomNavItem
|
<BottomNavItem
|
||||||
active={active === 'more'}
|
active={active === 'more'}
|
||||||
icon={<MoreHorizontal className="size-5" />}
|
icon={<MoreHorizontal className="size-5" />}
|
||||||
label="Más"
|
label="Más"
|
||||||
|
onClick={() => onSelect('more')}
|
||||||
/>
|
/>
|
||||||
</nav>
|
</nav>
|
||||||
);
|
);
|
||||||
@@ -760,14 +1038,17 @@ function BottomNavItem({
|
|||||||
active,
|
active,
|
||||||
icon,
|
icon,
|
||||||
label,
|
label,
|
||||||
}: { active: boolean; icon: React.ReactNode; label: string }) {
|
onClick,
|
||||||
|
}: { active: boolean; icon: React.ReactNode; label: string; onClick: () => void }) {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
aria-current={active ? 'page' : undefined}
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex flex-col items-center gap-1 rounded-lg px-2 py-1.5 text-xs text-muted-foreground',
|
'flex flex-col items-center gap-1 rounded-lg px-2 py-1.5 text-xs text-muted-foreground',
|
||||||
active && 'text-primary'
|
active && 'text-primary'
|
||||||
)}
|
)}
|
||||||
|
onClick={onClick}
|
||||||
>
|
>
|
||||||
{icon}
|
{icon}
|
||||||
<span>{label}</span>
|
<span>{label}</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user