From cf8afc1ee12a51251a4795d1be6414f640f9e494 Mon Sep 17 00:00:00 2001 From: Anita Date: Sat, 4 Apr 2026 20:52:35 +0100 Subject: feat: menuBar, perfil y home rediseñados y sistema de estilos global creado MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(protected)/(tabs)/profile/index.tsx | 701 +++++++++++++++++++++++---- 1 file changed, 620 insertions(+), 81 deletions(-) (limited to 'src/app/(protected)/(tabs)/profile/index.tsx') diff --git a/src/app/(protected)/(tabs)/profile/index.tsx b/src/app/(protected)/(tabs)/profile/index.tsx index 760b352..660d113 100644 --- a/src/app/(protected)/(tabs)/profile/index.tsx +++ b/src/app/(protected)/(tabs)/profile/index.tsx @@ -1,22 +1,34 @@ -import { useEffect } from 'react'; +import { useEffect, useMemo, useState } from 'react'; +import theme from '@/theme'; 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 { router } from 'expo-router'; import { StatusMessage } from '@/shared/ui/StatusMessage'; +import { useOffices } from '@/features/offices/hooks/useOffices'; +import { useFavoriteOffices } from '@/features/offices/hooks/useFavoriteOffices'; + +const { colors, spacing, radius, typography, fontWeight, layout, shadows } = theme; export default function ProfileScreen() { + // hook de autenticacion const { logout } = useAuthSession(); + + // hook para cargar datos del perfil const { profile, loading, error, reload } = useProfile(); + + // hook para actualizar nombre y foto del perfil const { displayName, photoURL, @@ -28,18 +40,62 @@ export default function ProfileScreen() { submit, } = useUpdateProfile(profile?.displayName ?? '', profile?.photoURL ?? ''); + // hook de favoritos del usuario + const { + favoriteOfficeIds, + isLoadingFavorites, + favoritesError, + } = useFavoriteOffices(); + + // hook con el listado completo de oficinas + const { + offices, + loading: officesLoading, + error: officesError, + } = useOffices(); + + // estado local para alternar entre modo vista y modo edicion + const [isEditing, setIsEditing] = useState(false); + + // 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]); + + // sincroniza el formulario con los datos cargados del perfil useEffect(() => { if (profile?.displayName) { setDisplayName(profile.displayName); } + setPhotoURL(profile?.photoURL ?? ''); }, [profile?.displayName, profile?.photoURL, setDisplayName, setPhotoURL]); + // cerrar sesion y redirigir a pantalla de bienvenida const handleLogout = async () => { await logout(); router.replace('/(auth)/welcome'); }; + // cambia entre modo vista y modo edicion + const handleToggleEditing = () => { + // si se pulsa cancelar, restauramos los valores actuales del perfil + if (isEditing) { + setDisplayName(profile?.displayName ?? ''); + setPhotoURL(profile?.photoURL ?? ''); + } + + setIsEditing((current) => !current); + }; + + // guardar cambios del perfil + const handleSaveProfile = async () => { + await submit(); + setIsEditing(false); + }; + + // estado de carga inicial del perfil if (loading) { return ( @@ -48,10 +104,12 @@ export default function ProfileScreen() { ); } + // estado de error general del perfil if (error || !profile) { return ( {error ?? 'No se pudo cargar el perfil'} + Reintentar @@ -60,11 +118,19 @@ export default function ProfileScreen() { } return ( - - Perfil - - - + + {/* cabecera superior visual dentro del scroll */} + + Perfil + + {/* tarjeta cabecera del perfil */} + {/* avatar, nombre, correo y boton editar / cancelar */} + + {photoURL ? ( ) : ( @@ -74,125 +140,598 @@ export default function ProfileScreen() { )} + + + {/* nombre del usuario */} + {displayName || 'Usuario'} + + {/* correo del usuario */} + {profile.email} + + {/* boton editar perfil / cancelar */} + + + {isEditing ? 'Cancelar' : 'Editar perfil'} + + + + + + {/* seccion sobre mi */} + {/* solo visual por ahora, FALTA CONEXION CON FIREBASE PARA GUARDAR INFO */} + + Sobre mí - Correo - {profile.email} - - Nombre - - - URL de la foto - - - {updateError ? : null} - {successMessage ? : null} - - - - {isSubmitting ? 'Guardando...' : 'Guardar cambios'} + + + Espacio personal del usuario para mostrar una breve descripción o + presentación dentro de la aplicación. - + + + + {/* seccion informacion personal */} + {/* en modo vista muestra datos */} + {/* en modo edicion muestra formulario */} + + Información personal + + + {isEditing ? ( + <> + {/* formulario de edicion: nombre */} + Nombre + + + {/* formulario de edicion: url de la foto */} + URL de la foto + + + {/* mensajes de error o exito al guardar */} + {updateError ? : null} + {successMessage ? ( + + ) : null} + + {/* boton guardar cambios */} + + + {isSubmitting ? 'Guardando...' : 'Guardar cambios'} + + + + ) : ( + <> + {/* fila de nombre completo */} + + + + Nombre completo + {displayName || 'Usuario'} + + + + {/* fila de correo electronico */} + + + + Correo electrónico + {profile.email} + + + + {/* fila de telefono */} + {/* por ahora es solo visual, FALTA CONEXION CON FIREBASE */} + + + + Teléfono + +34 600 123 456 + + + + {/* fila de empresa */} + {/* por ahora es solo visual, FALTA CONEXION CON FIREBASE */} + + + + Empresa + Empresa Innovadora S.L. + + + + )} + + + + {/* seccion favoritos */} + + Favoritos + + + {isLoadingFavorites || officesLoading ? ( + Cargando favoritos... + ) : favoritesError || officesError ? ( + + {favoritesError ?? officesError} + + ) : favoriteOffices.length === 0 ? ( + + Todavía no has marcado oficinas como favoritas. + + ) : ( + <> + {/* cabecera resumida de favoritos */} + + {favoriteOffices.length} + oficinas guardadas + + + {/* lista corta de favoritos, limitada a 3 */} + + {favoriteOffices.slice(0, 3).map((office) => ( + + + + + + + {office.name} + Espacio favorito + + + ))} + + + {/* enlace visual para ver todos los favoritos + solo aparece si hay mas de 3 favoritos */} + {favoriteOffices.length > 3 ? ( + + Ver todos + + ) : null} + + )} + + + + {/* seccion enlaces secundarios */} + + + + + + Notificaciones + + {'>'} + + + + + + Privacidad y seguridad + + {'>'} + + + + + + Ayuda y soporte + + {'>'} + + + {/* boton cerrar sesion */} - Cerrar sesión + + + Cerrar sesión + - + + {/* texto inferior de version */} + App Oficina v1.0.0 + ); } const styles = StyleSheet.create({ + // contenedor principal de la pantalla container: { flex: 1, - padding: 16, - gap: 16, + backgroundColor: colors.background, + }, + + // contenido interno del scroll + // padding general, separacion entre bloques y el ancho maximo + // para mantener consistencia con otras pantallas + content: { + padding: spacing.xl, + paddingTop: spacing.lg, + gap: spacing.lg, + maxWidth: layout.contentWidth, + width: '100%', + alignSelf: 'center', + paddingBottom: spacing.xxxl, }, + + // estado de carga y error general center: { flex: 1, alignItems: 'center', justifyContent: 'center', - padding: 24, - gap: 12, + padding: spacing.xxxl, + gap: spacing.md, + backgroundColor: colors.background, }, - title: { - fontSize: 28, - fontWeight: '700', + + // titulo superior de la pantalla + topBar: { + backgroundColor: colors.surface, + borderBottomWidth: 1, + borderBottomColor: colors.border, + paddingHorizontal: spacing.xl, + paddingTop: spacing.lg, + paddingBottom: spacing.lg, + marginHorizontal: -spacing.xl, + marginTop: -spacing.lg, }, - card: { + topBarTitle: { + fontSize: typography.xxl, + fontWeight: fontWeight.semibold, + color: colors.text, + textAlign: 'left', + maxWidth: layout.contentWidth, + width: '100%', + alignSelf: 'center', + paddingHorizontal: spacing.xl, + }, + + // tarjeta superior de cabecera + headerCard: { + backgroundColor: colors.surface, + borderRadius: radius.xxl, + padding: spacing.lg, borderWidth: 1, - borderColor: '#ddd', - borderRadius: 12, - padding: 16, - gap: 10, + borderColor: colors.border, + ...shadows.card, }, - avatarSection: { + + // fila interna de la cabecera + // coloca avatar a la izquierda y datos a la derecha + headerRow: { + flexDirection: 'row', alignItems: 'center', - gap: 12, - marginBottom: 8, + gap: spacing.lg, + }, + + // bloque de informacion de la cabecera + headerInfo: { + flex: 1, + gap: spacing.xs, }, + + // avatar del usuario avatar: { - width: 112, - height: 112, - borderRadius: 56, - backgroundColor: '#ddd', + width: 64, + height: 64, + borderRadius: 32, }, + + // avatar alternativo cuando no hay foto avatarPlaceholder: { + backgroundColor: colors.primary, alignItems: 'center', justifyContent: 'center', - backgroundColor: '#1f6feb', }, + + // letra dentro del avatar alternativo avatarPlaceholderText: { - color: '#fff', - fontSize: 36, - fontWeight: '700', + color: colors.white, + fontSize: 28, + fontWeight: fontWeight.semibold, }, - label: { - fontSize: 14, - fontWeight: '700', - color: '#444', + + // nombre principal del usuario + profileName: { + fontSize: typography.xl, + fontWeight: fontWeight.semibold, + color: colors.text, + }, + + // correo mostrado en cabecera + profileEmail: { + fontSize: typography.md, + color: colors.textSecondary, + }, + + // boton pequeno de editar / cancelar + editButton: { + marginTop: spacing.xs, + borderWidth: 1, + borderColor: colors.primary, + paddingVertical: spacing.xs, + paddingHorizontal: spacing.md, + borderRadius: radius.md, + alignSelf: 'flex-start', + }, + + // texto del boton editar / cancelar + editButtonText: { + color: colors.primary, + fontSize: typography.sm, + fontWeight: fontWeight.medium, + }, + + // separacion entre titulo de seccion y tarjeta + section: { + gap: spacing.sm, + }, + + // titulo de cada seccion + sectionTitle: { + fontSize: typography.xl, + fontWeight: fontWeight.semibold, + color: colors.text, + }, + + // tarjeta base reutilizable + card: { + backgroundColor: colors.surface, + borderRadius: radius.xxl, + padding: spacing.lg, + borderWidth: 1, + borderColor: colors.border, + ...shadows.card, + gap: spacing.md, + }, + + // fila de informacion personal con icono a la izquierda + infoRow: { + flexDirection: 'row', + alignItems: 'flex-start', + gap: spacing.md, + }, + + // contenido de texto dentro de cada fila de informacion + infoContent: { + flex: 1, + 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, + color: colors.textSecondary, + fontWeight: fontWeight.regular, + }, + + // valor mostrado en informacion personal + infoValue: { + fontSize: typography.md, + color: colors.text, + fontWeight: fontWeight.medium, + }, + + // texto general de apoyo + // usado en sobre mi, favoritos vacios y mensajes similares + aboutText: { + fontSize: typography.md, + color: colors.textSecondary, + lineHeight: 20, + }, + + // texto de error en secciones concretas + errorText: { + fontSize: typography.md, + color: colors.error, + }, + + // bloque de favoritos + // fila resumen de favoritos coloca numero y texto en la misma linea + favoriteSummaryRow: { + flexDirection: 'row', + alignItems: 'baseline', + gap: spacing.sm, + marginBottom: spacing.xs, + }, + + // numero grande de favoritos + favoriteCount: { + fontSize: typography.xxxl, + fontWeight: fontWeight.semibold, + color: colors.text, + }, + + // texto pequeno junto al numero + favoriteSummaryText: { + fontSize: typography.sm, + color: colors.textSecondary, + }, + + // lista interna de favoritos + favoritesList: { + gap: spacing.sm, + marginTop: spacing.xs, + }, + + // fila individual de favorito + favoriteRow: { + flexDirection: 'row', + alignItems: 'center', + gap: spacing.md, + paddingVertical: spacing.sm, + paddingHorizontal: spacing.sm, + borderRadius: radius.md, + backgroundColor: colors.background, + borderWidth: 1, + borderColor: colors.border, + }, + + // contenedor del icono del favorito + favoriteIconWrap: { + width: 28, + height: 28, + borderRadius: 14, + backgroundColor: colors.primarySoft, + alignItems: 'center', + justifyContent: 'center', + }, + + // bloque de texto del favorito + favoriteTextBlock: { + flex: 1, + gap: 2, + }, + + // texto del nombre de la oficina favorita + favoriteItemText: { + fontSize: typography.md, + color: colors.text, + fontWeight: fontWeight.medium, + }, + + // texto secundario pequeno del favorito + favoriteItemMeta: { + fontSize: typography.sm, + color: colors.textSecondary, + }, + + // boton / enlace visual para ver todos los favoritos + viewAllButton: { + marginTop: spacing.xs, + alignSelf: 'flex-start', + }, + + // texto del enlace ver todos + viewAllText: { + fontSize: typography.sm, + color: colors.primary, + fontWeight: fontWeight.medium, }, - value: { - fontSize: 16, - color: '#111', + + // formulario de edicion + // etiqueta de cada input + label: { + fontSize: typography.md, + fontWeight: fontWeight.semibold, + color: colors.text, }, + + // input de texto para campos editables input: { borderWidth: 1, - borderColor: '#ccc', - borderRadius: 10, - paddingHorizontal: 14, - paddingVertical: 12, + borderColor: colors.border, + borderRadius: radius.md, + paddingHorizontal: spacing.lg, + paddingVertical: spacing.md, + backgroundColor: colors.surface, }, + + // boton principal de guardar cambios button: { - backgroundColor: '#1f6feb', - paddingVertical: 14, - borderRadius: 10, + backgroundColor: colors.primary, + paddingVertical: spacing.lg, + borderRadius: radius.md, + alignItems: 'center', + marginTop: spacing.sm, + }, + + // texto del boton principal + buttonText: { + color: colors.white, + 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, }, + + // boton de cerrar sesion logoutButton: { - backgroundColor: '#c62828', - paddingVertical: 14, - borderRadius: 10, + borderWidth: 1, + borderColor: '#f3b4b4', + backgroundColor: colors.surface, + paddingVertical: spacing.md, + borderRadius: radius.md, alignItems: 'center', + marginTop: spacing.sm, }, - buttonText: { - color: '#fff', - fontWeight: '600', + + // texto del boton cerrar sesion + logoutButtonText: { + color: colors.error, + fontWeight: fontWeight.regular, + }, + // contenido interno del boton cerrar sesion + // alinea icono y texto en horizontal + logoutContent: { + flexDirection: 'row', + alignItems: 'center', + gap: spacing.sm, }, + + // texto inferior de version + footerText: { + textAlign: 'center', + color: colors.muted, + fontSize: typography.sm, + marginTop: spacing.sm, + }, + + // error general de pantalla error: { - color: '#9f1d35', + color: colors.error, textAlign: 'center', }, -}); +}); \ No newline at end of file -- cgit v1.2.3-54-g00ecf