From 47538e50cbad770ddeb998904253afcdd51e20f6 Mon Sep 17 00:00:00 2001 From: Alberto Duarte Delgado Date: Wed, 1 Apr 2026 17:29:30 +0100 Subject: disponibilidad de reservas, home mejorado y check-in --- src/app/(protected)/(tabs)/home.tsx | 198 ++++++++++++++++++---- src/app/(protected)/(tabs)/reservations/index.tsx | 74 ++++++++ src/app/(protected)/offices/[officeId].tsx | 98 ++++++++++- 3 files changed, 335 insertions(+), 35 deletions(-) (limited to 'src/app') diff --git a/src/app/(protected)/(tabs)/home.tsx b/src/app/(protected)/(tabs)/home.tsx index d9e64ac..3ddad57 100644 --- a/src/app/(protected)/(tabs)/home.tsx +++ b/src/app/(protected)/(tabs)/home.tsx @@ -1,36 +1,114 @@ import { Link } from 'expo-router'; -import { Pressable, StyleSheet, Text, View } from 'react-native'; +import { useMemo } from 'react'; +import { ActivityIndicator, Pressable, StyleSheet, Text, View } from 'react-native'; import { useAuthSession } from '@/providers/AuthProvider'; +import { useReservations } from '@/features/reservations/hooks/useReservations'; +import { useFavoriteOffices } from '@/features/offices/hooks/useFavoriteOffices'; + +function getReservationStart(date: string, startTime: string): Date { + return new Date(`${date}T${startTime}:00`); +} export default function HomeScreen() { const { user } = useAuthSession(); + const { reservations, activeReservations, historyReservations, loading, error } = useReservations(); + const { + favoriteOfficeIds, + isLoadingFavorites, + favoritesError, + } = useFavoriteOffices(); + + const nextReservation = useMemo(() => { + const now = new Date(); + + return activeReservations.find((reservation) => getReservationStart(reservation.date, reservation.startTime) >= now) + ?? activeReservations[0] + ?? null; + }, [activeReservations]); + + const completedReservationsCount = useMemo( + () => historyReservations.filter((reservation) => reservation.status === 'completed').length, + [historyReservations] + ); + + const checkedInReservationsCount = useMemo( + () => reservations.filter((reservation) => reservation.checkInAt).length, + [reservations] + ); + + if (loading || isLoadingFavorites) { + return ( + + + + ); + } + + if (error || favoritesError) { + return ( + + {error ?? favoritesError} + + ); + } return ( - Inicio - + Dashboard + Bienvenido{user?.displayName ? `, ${user.displayName}` : ''} {user?.email} - - - - Ver espacios - - - - - - Mis reservas - - + + Próxima reserva + {nextReservation ? ( + <> + {nextReservation.officeName} + + {nextReservation.date} · {nextReservation.startTime} - {nextReservation.endTime} + + + {nextReservation.checkInAt ? 'Llegada registrada' : 'Pendiente de check-in'} + + + + Ver mis reservas + + + + ) : ( + <> + No tienes reservas próximas + + Explora espacios disponibles y reserva cuando lo necesites. + + + + Buscar espacios + + + + )} + - - - Ir a perfil - - + + + {activeReservations.length} + Reservas activas + + + {favoriteOfficeIds.length} + Favoritos + + + {completedReservationsCount} + Completadas + + + {checkedInReservationsCount} + Check-ins + ); @@ -40,34 +118,90 @@ const styles = StyleSheet.create({ container: { flex: 1, padding: 16, + gap: 16, + }, + center: { + flex: 1, + alignItems: 'center', justifyContent: 'center', - gap: 12, + padding: 24, }, - title: { - fontSize: 30, + eyebrow: { + color: '#5a7188', + fontSize: 13, fontWeight: '700', + textTransform: 'uppercase', + letterSpacing: 1, }, - subtitle: { - fontSize: 18, + title: { + fontSize: 32, + fontWeight: '700', }, email: { color: '#666', - marginBottom: 20, }, - actions: { + heroCard: { + backgroundColor: '#eff6ff', + borderWidth: 1, + borderColor: '#c8daf7', + borderRadius: 18, + padding: 18, + gap: 10, + }, + cardLabel: { + color: '#2b5ea8', + fontSize: 13, + fontWeight: '700', + textTransform: 'uppercase', + letterSpacing: 0.8, + }, + heroTitle: { + fontSize: 24, + fontWeight: '700', + color: '#102a43', + }, + heroMeta: { + color: '#365b86', + fontSize: 15, + }, + heroStatus: { + color: '#1d4f91', + fontWeight: '600', + }, + statsGrid: { + flexDirection: 'row', + flexWrap: 'wrap', gap: 12, }, + statCard: { + width: '47%', + minWidth: 150, + borderWidth: 1, + borderColor: '#dde3ea', + borderRadius: 16, + padding: 16, + backgroundColor: '#fff', + gap: 4, + }, + statValue: { + fontSize: 28, + fontWeight: '700', + color: '#13293d', + }, + statLabel: { + color: '#66788a', + fontSize: 13, + fontWeight: '600', + }, button: { backgroundColor: '#1f6feb', paddingVertical: 14, borderRadius: 10, alignItems: 'center', }, - secondaryButton: { - backgroundColor: '#555', - paddingVertical: 14, - borderRadius: 10, - alignItems: 'center', + error: { + color: '#9f1d35', + textAlign: 'center', }, buttonText: { color: '#fff', diff --git a/src/app/(protected)/(tabs)/reservations/index.tsx b/src/app/(protected)/(tabs)/reservations/index.tsx index ccec7e9..59d2cad 100644 --- a/src/app/(protected)/(tabs)/reservations/index.tsx +++ b/src/app/(protected)/(tabs)/reservations/index.tsx @@ -9,6 +9,49 @@ import { } from 'react-native'; import { useReservations } from '@/features/reservations/hooks/useReservations'; +function getReservationWindowStart(date: string, startTime: string): Date { + return new Date(`${date}T${startTime}:00`); +} + +function getReservationWindowEnd(date: string, endTime: string): Date { + return new Date(`${date}T${endTime}:00`); +} + +function canCheckIn(date: string, startTime: string, endTime: string): boolean { + const now = new Date(); + const reservationStart = getReservationWindowStart(date, startTime); + const reservationEnd = getReservationWindowEnd(date, endTime); + const checkInOpensAt = new Date(reservationStart.getTime() - 15 * 60 * 1000); + + return now >= checkInOpensAt && now <= reservationEnd; +} + +function hasToDate(value: unknown): value is { toDate: () => Date } { + return ( + !!value && + typeof value === 'object' && + 'toDate' in value && + typeof value.toDate === 'function' + ); +} + +function formatCheckInAt(value: unknown): string { + if (!hasToDate(value)) { + return 'Registrada'; + } + + const date = value.toDate(); + + if (!(date instanceof Date) || Number.isNaN(date.getTime())) { + return 'Registrada'; + } + + return new Intl.DateTimeFormat('es-ES', { + dateStyle: 'short', + timeStyle: 'short', + }).format(date); +} + export default function ReservationsScreen() { const { activeReservations, @@ -18,6 +61,8 @@ export default function ReservationsScreen() { reload, cancelReservation, cancelingReservationId, + checkingInReservationId, + checkInReservation, } = useReservations(); const handleCancelReservation = (reservationId: string) => { @@ -83,6 +128,25 @@ export default function ReservationsScreen() { Fecha: {item.date} Inicio: {item.startTime} Fin: {item.endTime} + + Llegada: {item.checkInAt ? formatCheckInAt(item.checkInAt) : 'Pendiente'} + + + {!item.checkInAt && canCheckIn(item.date, item.startTime, item.endTime) ? ( + { + void checkInReservation(item.id); + }} + disabled={checkingInReservationId === item.id} + > + + {checkingInReservationId === item.id + ? 'Registrando llegada...' + : 'He llegado'} + + + ) : null} Fecha: {item.date} Inicio: {item.startTime} Fin: {item.endTime} + + Llegada: {item.checkInAt ? formatCheckInAt(item.checkInAt) : 'No registrada'} + )) )} @@ -220,6 +287,13 @@ const styles = StyleSheet.create({ alignItems: 'center', marginTop: 8, }, + checkInButton: { + backgroundColor: '#2e7d32', + paddingVertical: 12, + borderRadius: 10, + alignItems: 'center', + marginTop: 8, + }, empty: { color: '#666', }, diff --git a/src/app/(protected)/offices/[officeId].tsx b/src/app/(protected)/offices/[officeId].tsx index 8e3812f..c632490 100644 --- a/src/app/(protected)/offices/[officeId].tsx +++ b/src/app/(protected)/offices/[officeId].tsx @@ -1,8 +1,17 @@ import { Link, useLocalSearchParams } from 'expo-router'; -import { ActivityIndicator, Pressable, StyleSheet, Text, View } from 'react-native'; +import { + ActivityIndicator, + Pressable, + ScrollView, + StyleSheet, + Text, + TextInput, + View, +} from 'react-native'; import { useOffice } from '@/features/offices/hooks/useOffice'; import { useFavoriteOffices } from '@/features/offices/hooks/useFavoriteOffices'; import { StatusMessage } from '@/shared/ui/StatusMessage'; +import { useOfficeAvailability } from '@/features/reservations/hooks/useOfficeAvailability'; export default function OfficeDetailScreen() { const params = useLocalSearchParams<{ officeId: string }>(); @@ -15,6 +24,13 @@ export default function OfficeDetailScreen() { pendingOfficeId, toggleFavorite, } = useFavoriteOffices(); + const { + selectedDate, + reservations, + loading: loadingAvailability, + error: availabilityError, + setSelectedDate, + } = useOfficeAvailability(officeId); if (loading) { return ( @@ -43,7 +59,7 @@ export default function OfficeDetailScreen() { } return ( - + {office.name} {favoritesError ? : null} + {availabilityError ? : null} Ubicación @@ -83,6 +100,39 @@ export default function OfficeDetailScreen() { ) : null} + + Disponibilidad + + Fecha + + + Consulta los horarios ocupados para esa fecha + + {loadingAvailability ? ( + + ) : availabilityError ? null : reservations.length === 0 ? ( + No hay bloques ocupados para esta fecha + ) : ( + + {reservations.map((reservation) => ( + + + {reservation.startTime} - {reservation.endTime} + + Ocupado + + ))} + + )} + + - + ); } @@ -137,10 +187,52 @@ const styles = StyleSheet.create({ fontWeight: '700', color: '#444', }, + sectionTitle: { + fontSize: 20, + fontWeight: '700', + marginBottom: 4, + }, value: { fontSize: 16, color: '#111', }, + input: { + borderWidth: 1, + borderColor: '#ccc', + borderRadius: 10, + paddingHorizontal: 14, + paddingVertical: 12, + marginTop: 4, + }, + helper: { + color: '#666', + fontSize: 12, + }, + availabilityList: { + gap: 10, + marginTop: 8, + }, + availabilityItem: { + borderWidth: 1, + borderColor: '#d9e5d4', + backgroundColor: '#f3faf1', + borderRadius: 10, + padding: 12, + gap: 4, + }, + availabilityTime: { + fontSize: 16, + fontWeight: '600', + color: '#1f3a1a', + }, + availabilityStatus: { + color: '#336b2f', + fontSize: 13, + }, + availableText: { + color: '#2e7d32', + marginTop: 8, + }, button: { backgroundColor: '#1f6feb', paddingVertical: 14, -- cgit v1.2.3-54-g00ecf