From e68c8c3e71b0130b8a749cc40a2760fd71c4040c Mon Sep 17 00:00:00 2001 From: Anita Date: Sat, 18 Apr 2026 19:16:12 +0100 Subject: feat(profile): mejora cabecera y sección actividad refs #5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(protected)/(tabs)/profile/index.tsx | 206 +++++++++++++++------------ 1 file changed, 117 insertions(+), 89 deletions(-) (limited to 'src/app/(protected)/(tabs)/profile') diff --git a/src/app/(protected)/(tabs)/profile/index.tsx b/src/app/(protected)/(tabs)/profile/index.tsx index 660d113..c15db39 100644 --- a/src/app/(protected)/(tabs)/profile/index.tsx +++ b/src/app/(protected)/(tabs)/profile/index.tsx @@ -1,19 +1,12 @@ import { useEffect, useMemo, useState } from 'react'; import theme from '@/theme'; -import { - ActivityIndicator, - Pressable, - ScrollView, - StyleSheet, - Text, - TextInput, - View, -} from 'react-native'; +import {ActivityIndicator, Pressable, ScrollView, StyleSheet, Text, TextInput, View,} from 'react-native'; import { Feather } from '@expo/vector-icons'; import { Image } from 'expo-image'; import { useAuthSession } from '@/providers/AuthProvider'; import { useProfile } from '@/features/profile/hooks/useProfile'; import { useUpdateProfile } from '@/features/profile/hooks/useUpdateProfile'; +import { useReservations } from '@/features/reservations/hooks/useReservations'; import { router } from 'expo-router'; import { StatusMessage } from '@/shared/ui/StatusMessage'; import { useOffices } from '@/features/offices/hooks/useOffices'; @@ -54,15 +47,54 @@ export default function ProfileScreen() { error: officesError, } = useOffices(); - // estado local para alternar entre modo vista y modo edicion - const [isEditing, setIsEditing] = useState(false); - + // hook de reservas para mostrar actividad del usuario + const { + reservations, + activeReservations, + } = useReservations(); + + // calcula cuantas reservas tienen llegada registrada + const checkedInReservationsCount = useMemo(() => { + return reservations.filter((reservation) => reservation.checkInAt).length; + }, [reservations]); + // cruce entre ids favoritos y lista completa de oficinas // para obtener los datos reales de las oficinas favoritas const favoriteOffices = useMemo(() => { return offices.filter((office) => favoriteOfficeIds.includes(office.id)); }, [offices, favoriteOfficeIds]); + // calcula el espacio favorito mas usado entre reservas completadas + const mostUsedFavoriteOffice = useMemo(() => { + const completedReservations = reservations.filter( + (reservation) => reservation.status === 'completed' + ); + + const favoriteReservationCounts = favoriteOffices.map((office) => { + const usageCount = completedReservations.filter( + (reservation) => reservation.officeId === office.id + ).length; + + return { + office, + usageCount, + }; + }); + + const sortedFavorites = favoriteReservationCounts.sort( + (a, b) => b.usageCount - a.usageCount + ); + + if (sortedFavorites.length === 0 || sortedFavorites[0].usageCount === 0) { + return null; + } + + return sortedFavorites[0].office; + }, [reservations, favoriteOffices]); + + // estado local para alternar entre modo vista y modo edicion + const [isEditing, setIsEditing] = useState(false); + // sincroniza el formulario con los datos cargados del perfil useEffect(() => { if (profile?.displayName) { @@ -172,8 +204,7 @@ export default function ProfileScreen() { {/* seccion informacion personal */} - {/* en modo vista muestra datos */} - {/* en modo edicion muestra formulario */} + {/* en modo vista muestra datos y en modo edicion muestra formulario */} Información personal @@ -261,6 +292,33 @@ export default function ProfileScreen() { + {/* seccion actividad */} + + Resumen de actividad + + + + Check in confirmados en {checkedInReservationsCount} reservas. + + + + + + + Actualmente tienes {activeReservations.length} reservas activas. + + + + + + + {mostUsedFavoriteOffice + ? `Top de favoritos: ${mostUsedFavoriteOffice.name}.` + : 'Aún no tienes suficiente actividad para destacar un espacio favorito.'} + + + + {/* seccion favoritos */} Favoritos @@ -312,42 +370,12 @@ export default function ProfileScreen() { - {/* seccion enlaces secundarios */} - - - - - - Notificaciones - - {'>'} - - - - - - Privacidad y seguridad - - {'>'} - - - - - - Ayuda y soporte - - {'>'} - - - - - {/* boton cerrar sesion */} - - - + {/* seccion cierre de sesion */} + + Cerrar sesión - - + + {/* texto inferior de version */} App Oficina v1.0.0 @@ -411,7 +439,7 @@ const styles = StyleSheet.create({ headerCard: { backgroundColor: colors.surface, borderRadius: radius.xxl, - padding: spacing.lg, + padding: spacing.xxl, borderWidth: 1, borderColor: colors.border, ...shadows.card, @@ -422,7 +450,7 @@ const styles = StyleSheet.create({ headerRow: { flexDirection: 'row', alignItems: 'center', - gap: spacing.lg, + gap: spacing.xxl, }, // bloque de informacion de la cabecera @@ -433,9 +461,9 @@ const styles = StyleSheet.create({ // avatar del usuario avatar: { - width: 64, - height: 64, - borderRadius: 32, + width: 88, + height: 88, + borderRadius: 44, }, // avatar alternativo cuando no hay foto @@ -448,20 +476,20 @@ const styles = StyleSheet.create({ // letra dentro del avatar alternativo avatarPlaceholderText: { color: colors.white, - fontSize: 28, + fontSize: 34, fontWeight: fontWeight.semibold, }, // nombre principal del usuario profileName: { - fontSize: typography.xl, + fontSize: typography.xxxl, fontWeight: fontWeight.semibold, color: colors.text, }, // correo mostrado en cabecera profileEmail: { - fontSize: typography.md, + fontSize: typography.xl, color: colors.textSecondary, }, @@ -519,12 +547,6 @@ const styles = StyleSheet.create({ gap: spacing.xs, }, - // bloque antiguo de informacion personal - // se mantienen por si se reutiliza sino ELIMINAR - infoBlock: { - gap: spacing.xs, - }, - // etiqueta pequena de informacion personal infoLabel: { fontSize: typography.sm, @@ -553,6 +575,35 @@ const styles = StyleSheet.create({ color: colors.error, }, + // bloque de actividad + // muestra resumen narrativo del uso de la app + activityText: { + fontSize: typography.md, + color: colors.textSecondary, + lineHeight: 20, + }, + // fila individual de actividad + activityItem: { + flexDirection: 'row', + alignItems: 'flex-start', + gap: spacing.md, + }, + // punto visual de cada item de actividad + activityDot: { + width: 8, + height: 8, + borderRadius: 4, + backgroundColor: colors.primary, + marginTop: 6, + }, + // texto de la seccion actividad + activityText: { + flex: 1, + fontSize: typography.md, + color: colors.textSecondary, + lineHeight: 20, + }, + // bloque de favoritos // fila resumen de favoritos coloca numero y texto en la misma linea favoriteSummaryRow: { @@ -669,32 +720,9 @@ const styles = StyleSheet.create({ fontWeight: fontWeight.semibold, }, - // bloque de enlaces secundarios - // cada fila del bloque - linkItem: { - flexDirection: 'row', - justifyContent: 'space-between', - alignItems: 'center', - paddingVertical: spacing.md, - }, - - // parte izquierda del enlace: icono + texto - linkLeft: { - flexDirection: 'row', - alignItems: 'center', - gap: spacing.md, - }, - - // texto del enlace - linkText: { - fontSize: typography.md, - color: colors.text, - }, - - // flecha simple a la derecha - chevron: { - fontSize: typography.md, - color: colors.textSecondary, + // separacion antes del bloque de cierre de sesion + logoutSection: { + marginTop: spacing.lg, }, // boton de cerrar sesion -- cgit v1.2.3-54-g00ecf