diff options
Diffstat (limited to 'src/app/(protected)/(tabs)/home.tsx')
| -rw-r--r-- | src/app/(protected)/(tabs)/home.tsx | 198 |
1 files changed, 166 insertions, 32 deletions
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 ( + <View style={styles.center}> + <ActivityIndicator size="large" /> + </View> + ); + } + + if (error || favoritesError) { + return ( + <View style={styles.center}> + <Text style={styles.error}>{error ?? favoritesError}</Text> + </View> + ); + } return ( <View style={styles.container}> - <Text style={styles.title}>Inicio</Text> - <Text style={styles.subtitle}> + <Text style={styles.eyebrow}>Dashboard</Text> + <Text style={styles.title}> Bienvenido{user?.displayName ? `, ${user.displayName}` : ''} </Text> <Text style={styles.email}>{user?.email}</Text> - <View style={styles.actions}> - <Link href="/(protected)/(tabs)/offices" asChild> - <Pressable style={styles.button}> - <Text style={styles.buttonText}>Ver espacios</Text> - </Pressable> - </Link> - - <Link href="/(protected)/(tabs)/reservations" asChild> - <Pressable style={styles.button}> - <Text style={styles.buttonText}>Mis reservas</Text> - </Pressable> - </Link> + <View style={styles.heroCard}> + <Text style={styles.cardLabel}>Próxima reserva</Text> + {nextReservation ? ( + <> + <Text style={styles.heroTitle}>{nextReservation.officeName}</Text> + <Text style={styles.heroMeta}> + {nextReservation.date} · {nextReservation.startTime} - {nextReservation.endTime} + </Text> + <Text style={styles.heroStatus}> + {nextReservation.checkInAt ? 'Llegada registrada' : 'Pendiente de check-in'} + </Text> + <Link href="/(protected)/(tabs)/reservations" asChild> + <Pressable style={styles.button}> + <Text style={styles.buttonText}>Ver mis reservas</Text> + </Pressable> + </Link> + </> + ) : ( + <> + <Text style={styles.heroTitle}>No tienes reservas próximas</Text> + <Text style={styles.heroMeta}> + Explora espacios disponibles y reserva cuando lo necesites. + </Text> + <Link href="/(protected)/(tabs)/offices" asChild> + <Pressable style={styles.button}> + <Text style={styles.buttonText}>Buscar espacios</Text> + </Pressable> + </Link> + </> + )} + </View> - <Link href="/(protected)/(tabs)/profile" asChild> - <Pressable style={styles.secondaryButton}> - <Text style={styles.buttonText}>Ir a perfil</Text> - </Pressable> - </Link> + <View style={styles.statsGrid}> + <View style={styles.statCard}> + <Text style={styles.statValue}>{activeReservations.length}</Text> + <Text style={styles.statLabel}>Reservas activas</Text> + </View> + <View style={styles.statCard}> + <Text style={styles.statValue}>{favoriteOfficeIds.length}</Text> + <Text style={styles.statLabel}>Favoritos</Text> + </View> + <View style={styles.statCard}> + <Text style={styles.statValue}>{completedReservationsCount}</Text> + <Text style={styles.statLabel}>Completadas</Text> + </View> + <View style={styles.statCard}> + <Text style={styles.statValue}>{checkedInReservationsCount}</Text> + <Text style={styles.statLabel}>Check-ins</Text> + </View> </View> </View> ); @@ -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', |