diff options
Diffstat (limited to 'src/app/(protected)/(tabs)/profile')
| -rw-r--r-- | src/app/(protected)/(tabs)/profile/index.tsx | 701 |
1 files changed, 620 insertions, 81 deletions
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 ( <View style={styles.center}> @@ -48,10 +104,12 @@ export default function ProfileScreen() { ); } + // estado de error general del perfil if (error || !profile) { return ( <View style={styles.center}> <Text style={styles.error}>{error ?? 'No se pudo cargar el perfil'}</Text> + <Pressable style={styles.button} onPress={reload}> <Text style={styles.buttonText}>Reintentar</Text> </Pressable> @@ -60,11 +118,19 @@ export default function ProfileScreen() { } return ( - <View style={styles.container}> - <Text style={styles.title}>Perfil</Text> - - <View style={styles.card}> - <View style={styles.avatarSection}> + <ScrollView + style={styles.container} + contentContainerStyle={styles.content} + showsVerticalScrollIndicator={false} + > + {/* cabecera superior visual dentro del scroll */} + <View style={styles.topBar}> + <Text style={styles.topBarTitle}>Perfil</Text> + </View> + {/* tarjeta cabecera del perfil */} + {/* avatar, nombre, correo y boton editar / cancelar */} + <View style={styles.headerCard}> + <View style={styles.headerRow}> {photoURL ? ( <Image source={{ uri: photoURL }} style={styles.avatar} contentFit="cover" /> ) : ( @@ -74,125 +140,598 @@ export default function ProfileScreen() { </Text> </View> )} + + <View style={styles.headerInfo}> + {/* nombre del usuario */} + <Text style={styles.profileName}>{displayName || 'Usuario'}</Text> + + {/* correo del usuario */} + <Text style={styles.profileEmail}>{profile.email}</Text> + + {/* boton editar perfil / cancelar */} + <Pressable style={styles.editButton} onPress={handleToggleEditing}> + <Text style={styles.editButtonText}> + {isEditing ? 'Cancelar' : 'Editar perfil'} + </Text> + </Pressable> + </View> </View> + </View> + + {/* seccion sobre mi */} + {/* solo visual por ahora, FALTA CONEXION CON FIREBASE PARA GUARDAR INFO */} + <View style={styles.section}> + <Text style={styles.sectionTitle}>Sobre mí</Text> - <Text style={styles.label}>Correo</Text> - <Text style={styles.value}>{profile.email}</Text> - - <Text style={styles.label}>Nombre</Text> - <TextInput - style={styles.input} - value={displayName} - onChangeText={setDisplayName} - placeholder="Tu nombre" - /> - - <Text style={styles.label}>URL de la foto</Text> - <TextInput - style={styles.input} - value={photoURL} - onChangeText={setPhotoURL} - placeholder="https://ejemplo.com/foto.jpg" - autoCapitalize="none" - autoCorrect={false} - /> - - {updateError ? <StatusMessage message={updateError} /> : null} - {successMessage ? <StatusMessage message={successMessage} tone="success" /> : null} - - <Pressable style={styles.button} onPress={submit} disabled={isSubmitting}> - <Text style={styles.buttonText}> - {isSubmitting ? 'Guardando...' : 'Guardar cambios'} + <View style={styles.card}> + <Text style={styles.aboutText}> + Espacio personal del usuario para mostrar una breve descripción o + presentación dentro de la aplicación. </Text> - </Pressable> + </View> + </View> + + {/* seccion informacion personal */} + {/* en modo vista muestra datos */} + {/* en modo edicion muestra formulario */} + <View style={styles.section}> + <Text style={styles.sectionTitle}>Información personal</Text> + + <View style={styles.card}> + {isEditing ? ( + <> + {/* formulario de edicion: nombre */} + <Text style={styles.label}>Nombre</Text> + <TextInput + style={styles.input} + value={displayName} + onChangeText={setDisplayName} + placeholder="Tu nombre" + /> + + {/* formulario de edicion: url de la foto */} + <Text style={styles.label}>URL de la foto</Text> + <TextInput + style={styles.input} + value={photoURL} + onChangeText={setPhotoURL} + placeholder="https://ejemplo.com/foto.jpg" + autoCapitalize="none" + autoCorrect={false} + /> + + {/* mensajes de error o exito al guardar */} + {updateError ? <StatusMessage message={updateError} /> : null} + {successMessage ? ( + <StatusMessage message={successMessage} tone="success" /> + ) : null} + + {/* boton guardar cambios */} + <Pressable + style={styles.button} + onPress={handleSaveProfile} + disabled={isSubmitting} + > + <Text style={styles.buttonText}> + {isSubmitting ? 'Guardando...' : 'Guardar cambios'} + </Text> + </Pressable> + </> + ) : ( + <> + {/* fila de nombre completo */} + <View style={styles.infoRow}> + <Feather name="user" size={16} color={colors.textSecondary} /> + <View style={styles.infoContent}> + <Text style={styles.infoLabel}>Nombre completo</Text> + <Text style={styles.infoValue}>{displayName || 'Usuario'}</Text> + </View> + </View> + + {/* fila de correo electronico */} + <View style={styles.infoRow}> + <Feather name="mail" size={16} color={colors.textSecondary} /> + <View style={styles.infoContent}> + <Text style={styles.infoLabel}>Correo electrónico</Text> + <Text style={styles.infoValue}>{profile.email}</Text> + </View> + </View> + + {/* fila de telefono */} + {/* por ahora es solo visual, FALTA CONEXION CON FIREBASE */} + <View style={styles.infoRow}> + <Feather name="phone" size={16} color={colors.textSecondary} /> + <View style={styles.infoContent}> + <Text style={styles.infoLabel}>Teléfono</Text> + <Text style={styles.infoValue}>+34 600 123 456</Text> + </View> + </View> + + {/* fila de empresa */} + {/* por ahora es solo visual, FALTA CONEXION CON FIREBASE */} + <View style={styles.infoRow}> + <Feather name="briefcase" size={16} color={colors.textSecondary} /> + <View style={styles.infoContent}> + <Text style={styles.infoLabel}>Empresa</Text> + <Text style={styles.infoValue}>Empresa Innovadora S.L.</Text> + </View> + </View> + </> + )} + </View> + </View> + + {/* seccion favoritos */} + <View style={styles.section}> + <Text style={styles.sectionTitle}>Favoritos</Text> + + <View style={styles.card}> + {isLoadingFavorites || officesLoading ? ( + <Text style={styles.aboutText}>Cargando favoritos...</Text> + ) : favoritesError || officesError ? ( + <Text style={styles.errorText}> + {favoritesError ?? officesError} + </Text> + ) : favoriteOffices.length === 0 ? ( + <Text style={styles.aboutText}> + Todavía no has marcado oficinas como favoritas. + </Text> + ) : ( + <> + {/* cabecera resumida de favoritos */} + <View style={styles.favoriteSummaryRow}> + <Text style={styles.favoriteCount}>{favoriteOffices.length}</Text> + <Text style={styles.favoriteSummaryText}>oficinas guardadas</Text> + </View> + + {/* lista corta de favoritos, limitada a 3 */} + <View style={styles.favoritesList}> + {favoriteOffices.slice(0, 3).map((office) => ( + <View key={office.id} style={styles.favoriteRow}> + <View style={styles.favoriteIconWrap}> + <Feather name="star" size={14} color={colors.primary} /> + </View> + + <View style={styles.favoriteTextBlock}> + <Text style={styles.favoriteItemText}>{office.name}</Text> + <Text style={styles.favoriteItemMeta}>Espacio favorito</Text> + </View> + </View> + ))} + </View> + + {/* enlace visual para ver todos los favoritos + solo aparece si hay mas de 3 favoritos */} + {favoriteOffices.length > 3 ? ( + <Pressable style={styles.viewAllButton}> + <Text style={styles.viewAllText}>Ver todos</Text> + </Pressable> + ) : null} + </> + )} + </View> + </View> + + {/* seccion enlaces secundarios */} + <View style={styles.section}> + <View style={styles.card}> + <View style={styles.linkItem}> + <View style={styles.linkLeft}> + <Feather name="bell" size={16} color={colors.textSecondary} /> + <Text style={styles.linkText}>Notificaciones</Text> + </View> + <Text style={styles.chevron}>{'>'}</Text> + </View> + + <View style={styles.linkItem}> + <View style={styles.linkLeft}> + <Feather name="shield" size={16} color={colors.textSecondary} /> + <Text style={styles.linkText}>Privacidad y seguridad</Text> + </View> + <Text style={styles.chevron}>{'>'}</Text> + </View> + + <View style={styles.linkItem}> + <View style={styles.linkLeft}> + <Feather name="help-circle" size={16} color={colors.textSecondary} /> + <Text style={styles.linkText}>Ayuda y soporte</Text> + </View> + <Text style={styles.chevron}>{'>'}</Text> + </View> + </View> </View> + {/* boton cerrar sesion */} <Pressable style={styles.logoutButton} onPress={handleLogout}> - <Text style={styles.buttonText}>Cerrar sesión</Text> + <View style={styles.logoutContent}> + <Feather name="log-out" size={16} color={colors.error} /> + <Text style={styles.logoutButtonText}>Cerrar sesión</Text> + </View> </Pressable> - </View> + + {/* texto inferior de version */} + <Text style={styles.footerText}>App Oficina v1.0.0</Text> + </ScrollView> ); } 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 |