diff options
| author | Anita <ana.tqtc@gmail.com> | 2026-04-04 20:52:35 +0100 |
|---|---|---|
| committer | Anita <ana.tqtc@gmail.com> | 2026-04-04 20:52:35 +0100 |
| commit | cf8afc1ee12a51251a4795d1be6414f640f9e494 (patch) | |
| tree | d942d35bb7a248e7b8de563f3a053eebe4cc8027 /src/app/(protected)/(tabs)/home.tsx | |
| parent | c4d40229201f4bc7221a90d3d458787333786131 (diff) | |
feat: menuBar, perfil y home rediseñados y sistema de estilos global creado
Diffstat (limited to 'src/app/(protected)/(tabs)/home.tsx')
| -rw-r--r-- | src/app/(protected)/(tabs)/home.tsx | 492 |
1 files changed, 357 insertions, 135 deletions
diff --git a/src/app/(protected)/(tabs)/home.tsx b/src/app/(protected)/(tabs)/home.tsx index 3ddad57..523283c 100644 --- a/src/app/(protected)/(tabs)/home.tsx +++ b/src/app/(protected)/(tabs)/home.tsx @@ -1,42 +1,51 @@ +import { useReservations } from '@/features/reservations/hooks/useReservations'; +import { useAuthSession } from '@/providers/AuthProvider'; +import theme from '@/theme'; +import { Feather, MaterialIcons } from '@expo/vector-icons'; import { Link } from 'expo-router'; 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`); -} +function formatDate(date: string): string { + const parsedDate = new Date(date); + + return parsedDate.toLocaleDateString('es-ES', { + day: '2-digit', + month: 'short', + year: 'numeric', + }); + } + +// creacion de acceso rapidos al theme de estilos +const { colors, spacing, radius, typography, fontWeight, layout, shadows } = theme; 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(); + const { reservations, activeReservations, loading, error } = useReservations(); + - return activeReservations.find((reservation) => getReservationStart(reservation.date, reservation.startTime) >= now) - ?? activeReservations[0] - ?? null; - }, [activeReservations]); + // crea el contador de reservas en el mes actual + const currentMonthReservationsCount = useMemo(() => { + const now = new Date(); + const currentMonth = now.getMonth(); + const currentYear = now.getFullYear(); - const completedReservationsCount = useMemo( - () => historyReservations.filter((reservation) => reservation.status === 'completed').length, - [historyReservations] - ); + return reservations.filter((reservation) => { + const reservationDate = new Date(reservation.date); + return ( + reservationDate.getMonth() === currentMonth && + reservationDate.getFullYear() === currentYear + ); + }).length; + }, [reservations]); - const checkedInReservationsCount = useMemo( - () => reservations.filter((reservation) => reservation.checkInAt).length, - [reservations] + // crea una lista con las 2 primeras reservas activas + const previewReservations = useMemo( + () => activeReservations.slice(0, 2), + [activeReservations] ); - if (loading || isLoadingFavorites) { + if (loading) { return ( <View style={styles.center}> <ActivityIndicator size="large" /> @@ -44,70 +53,134 @@ export default function HomeScreen() { ); } - if (error || favoritesError) { + if (error) { return ( <View style={styles.center}> - <Text style={styles.error}>{error ?? favoritesError}</Text> + <Text style={styles.error}>{error}</Text> </View> ); } return ( + // pantalla inicio <View style={styles.container}> - <Text style={styles.eyebrow}>Dashboard</Text> + {/* cabecera de bienvenida */} <Text style={styles.title}> - Bienvenido{user?.displayName ? `, ${user.displayName}` : ''} + Hola{user?.displayName ? `, ${user.displayName}` : ''} 👋 </Text> - <Text style={styles.email}>{user?.email}</Text> - - <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.subtitle}> + Bienvenido a la App Oficina + </Text> + <View style={styles.divider} /> + + {/* seccion de accesos rapidos */} + <View style={styles.quickAccessSection}> + <Text style={styles.sectionTitle}>Accesos rápidos</Text> + + <View style={styles.quickAccessRow}> + <Link href="/(protected)/reservations/create" asChild> + <Pressable style={styles.quickAccessButton}> + <View style={styles.quickAccessIconContainerLight}> + <MaterialIcons name="apartment" size={28} color="#fff" /> + </View> + <Text style={styles.quickAccessButtonText}> + Reservar{"\n"}espacio + </Text> + </Pressable> + </Link> + + <Link href="/(protected)/(tabs)/reservations" asChild> + <Pressable style={styles.quickAccessButtonDark}> + <View style={styles.quickAccessIconContainerDark}> + <Feather name="calendar" size={28} color="#fff" /> + </View> + <Text style={styles.quickAccessButtonText}> + Mis reservas{"\n"}activas + </Text> + </Pressable> + </Link> + </View> + </View> + + {/* sección de reservas activas */} + <View style={styles.reservationsHeader}> + <Text style={styles.sectionTitle}>Reservas activas</Text> + + <Link href="/(protected)/(tabs)/reservations" asChild> + <Pressable> + <View style={styles.linkRow}> + <Text style={styles.linkText}>Ver todas</Text> + <Text style={styles.chevronSmall}>{'>'}</Text> + </View> + </Pressable> + </Link> + </View> + + <View style={styles.reservationsList}> + {previewReservations.length > 0 ? ( + previewReservations.map((reservation) => ( + <View key={reservation.id} style={styles.reservationCard}> + <View style={styles.reservationContent}> + + <View style={styles.reservationIconContainer}> + <MaterialIcons name="apartment" size={22} color={colors.primary} /> + </View> + + <View style={styles.reservationInfo}> + + <View style={styles.reservationHeader}> + <Text style={styles.reservationOffice}>{reservation.officeName}</Text> + <Text style={styles.chevron}>{'>'}</Text> + </View> + + <View style={styles.reservationMetaRow}> + <MaterialIcons name="access-time" size={14} color={colors.textSecondary} /> + <Text style={styles.reservationMeta}> + {formatDate(reservation.date)} + </Text> + </View> + + <View style={styles.reservationRow}> + <Text style={styles.reservationTime}> + {reservation.startTime} - {reservation.endTime} + </Text> + + <View style={styles.statusBadge}> + <Text style={styles.statusText}> + {reservation.checkInAt ? 'Confirmada' : 'Pendiente'} + </Text> + </View> + </View> + + </View> + </View> + </View> + )) ) : ( - <> - <Text style={styles.heroTitle}>No tienes reservas próximas</Text> - <Text style={styles.heroMeta}> - Explora espacios disponibles y reserva cuando lo necesites. + <View style={styles.emptyReservationCard}> + <Text style={styles.emptyReservationText}> + No tienes reservas activas en este momento. </Text> - <Link href="/(protected)/(tabs)/offices" asChild> - <Pressable style={styles.button}> - <Text style={styles.buttonText}>Buscar espacios</Text> - </Pressable> - </Link> - </> + </View> )} </View> + {/* seccion de estadisticas */} <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> + <Text style={styles.statValue}>{currentMonthReservationsCount}</Text> + <Text style={styles.statLabel}>Este mes</Text> </View> + <View style={styles.statCard}> - <Text style={styles.statValue}>{checkedInReservationsCount}</Text> - <Text style={styles.statLabel}>Check-ins</Text> + <Text style={styles.statValue}>{reservations.length}</Text> + <Text style={styles.statLabel}>Total</Text> </View> </View> </View> @@ -115,96 +188,245 @@ export default function HomeScreen() { } const styles = StyleSheet.create({ + // el ancho del container esta acotado si se toca hacerlo en el menuBar tambien container: { flex: 1, - padding: 16, - gap: 16, + paddingHorizontal: spacing.xl, + paddingTop: spacing.lg, + paddingBottom: spacing.xl, + gap: 18, + maxWidth: layout.contentWidth, + width: '100%', + alignSelf: 'center', + backgroundColor: colors.background, }, center: { flex: 1, alignItems: 'center', justifyContent: 'center', - padding: 24, - }, - eyebrow: { - color: '#5a7188', - fontSize: 13, - fontWeight: '700', - textTransform: 'uppercase', - letterSpacing: 1, + padding: spacing.xxxl, + backgroundColor: colors.background, }, + + // estilos de cabecera title: { - fontSize: 32, - fontWeight: '700', + fontSize: typography.xxxl, + fontWeight: fontWeight.medium, + color: colors.text, + }, + subtitle: { + fontSize: typography.xl, + color: colors.muted, + }, + divider: { + height: 1, + backgroundColor: colors.divider, + marginVertical: spacing.md, + }, + + // estilos de la seccion de accesos rapidos + sectionTitle: { + fontSize: typography.xxl, + fontWeight: fontWeight.semibold, + color: colors.text, + }, + quickAccessSection: { + gap: spacing.lg, + }, + quickAccessRow: { + flexDirection: 'row', + gap: spacing.lg, + }, + quickAccessButton: { + flex: 1, + backgroundColor: colors.primary, + paddingVertical: spacing.xxxl, + borderRadius: radius.xl, + alignItems: 'center', + justifyContent: 'center', + gap: spacing.md, + minHeight: 120, + }, + quickAccessButtonDark: { + flex: 1, + backgroundColor: colors.primaryDark, + paddingVertical: spacing.xxxl, + borderRadius: radius.xl, + alignItems: 'center', + justifyContent: 'center', + gap: spacing.md, + minHeight: 112, + }, + + // --- estilos textos accesos rapidos + quickAccessButtonText: { + color: colors.white, + fontWeight: fontWeight.regular, + fontSize: typography.md, + textAlign: 'center', + lineHeight: 16, + }, + //---------------------------------- + + quickAccessIconContainerLight: { + width: 40, + height: 40, + borderRadius: radius.md, + backgroundColor: '#3b82f6', + alignItems: 'center', + justifyContent: 'center', + }, + quickAccessIconContainerDark: { + width: 40, + height: 40, + borderRadius: radius.md, + backgroundColor: '#334e68', + alignItems: 'center', + justifyContent: 'center', + }, + + // estilos de reservas activas + reservationsHeader: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + }, + linkRow: { + flexDirection: 'row', + alignItems: 'center', + gap: spacing.xs, + }, + chevronSmall: { + fontSize: typography.lg, + color: colors.primary, + fontWeight: fontWeight.semibold, + }, + linkText: { + color: colors.primary, + fontWeight: fontWeight.regular, + }, + reservationsList: { + gap: spacing.xl, + }, + + // estilos tarjetas de reservas activas + reservationCard: { + backgroundColor: colors.surface, + borderRadius: radius.xxl, + padding: spacing.xl, + gap: spacing.md, + minHeight: 100, + ...shadows.card, + }, + reservationContent: { + flexDirection: 'row', + gap: spacing.lg, + }, + reservationIconContainer: { + width: 48, + height: 48, + borderRadius: radius.lg, + backgroundColor: colors.primarySoft, + alignItems: 'center', + justifyContent: 'center', + }, + reservationInfo: { + flex: 1, + gap: spacing.sm, + }, + reservationHeader: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + }, + reservationOffice: { + fontSize: 18, + fontWeight: fontWeight.medium, + color: colors.text, + }, + chevron: { + fontSize: 18, + color: colors.textSecondary, + fontWeight: fontWeight.semibold, + }, + reservationMetaRow: { + flexDirection: 'row', + alignItems: 'center', + gap: spacing.sm, + }, + reservationMeta: { + color: colors.textSecondary, + fontSize: typography.md, + }, + reservationRow: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', }, - email: { - color: '#666', + reservationTime: { + color: colors.text, + fontSize: typography.lg, + flex: 1, + }, + statusBadge: { + alignSelf: 'flex-start', + backgroundColor: colors.successBg, + paddingHorizontal: 10, + paddingVertical: spacing.xs, + borderRadius: radius.sm, }, - heroCard: { - backgroundColor: '#eff6ff', + statusText: { + color: colors.successText, + fontWeight: fontWeight.semibold, + fontSize: typography.sm, + }, + emptyReservationCard: { 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', + borderColor: colors.border, + borderRadius: radius.xxl, + padding: spacing.xl, + backgroundColor: colors.surface, }, + emptyReservationText: { + color: colors.textSecondary, + textAlign: 'center', + }, + + //estilos estadisticas statsGrid: { flexDirection: 'row', - flexWrap: 'wrap', - gap: 12, + gap: spacing.lg, }, statCard: { - width: '47%', - minWidth: 150, + flex: 1, borderWidth: 1, - borderColor: '#dde3ea', - borderRadius: 16, - padding: 16, - backgroundColor: '#fff', - gap: 4, + borderColor: colors.border, + borderRadius: radius.xxl, + paddingVertical: 18, + paddingHorizontal: spacing.lg, + minHeight: 115, + backgroundColor: colors.surface, + gap: spacing.sm, + alignItems: 'center', + justifyContent: 'space-between', }, + + // --- estilos textos estadisticas statValue: { - fontSize: 28, - fontWeight: '700', - color: '#13293d', + fontSize: typography.xxxl, + fontWeight: fontWeight.regular, + color: colors.text, }, statLabel: { - color: '#66788a', - fontSize: 13, - fontWeight: '600', - }, - button: { - backgroundColor: '#1f6feb', - paddingVertical: 14, - borderRadius: 10, - alignItems: 'center', + color: colors.textSecondary, + fontSize: typography.sm, + fontWeight: fontWeight.regular, + textAlign: 'center', }, + //-------------------------------- + error: { - color: '#9f1d35', + color: colors.error, textAlign: 'center', }, - buttonText: { - color: '#fff', - fontWeight: '600', - }, -}); +});
\ No newline at end of file |