diff options
Diffstat (limited to 'src/app/(protected)/(tabs)/profile/index.tsx')
| -rw-r--r-- | src/app/(protected)/(tabs)/profile/index.tsx | 337 |
1 files changed, 228 insertions, 109 deletions
diff --git a/src/app/(protected)/(tabs)/profile/index.tsx b/src/app/(protected)/(tabs)/profile/index.tsx index 660d113..0439708 100644 --- a/src/app/(protected)/(tabs)/profile/index.tsx +++ b/src/app/(protected)/(tabs)/profile/index.tsx @@ -14,6 +14,7 @@ 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'; @@ -28,17 +29,30 @@ export default function ProfileScreen() { // hook para cargar datos del perfil const { profile, loading, error, reload } = useProfile(); - // hook para actualizar nombre y foto del perfil + // hook para actualizar los campos editables del perfil const { displayName, photoURL, + phone, + company, + bio, setPhotoURL, setDisplayName, + setPhone, + setCompany, + setBio, isSubmitting, error: updateError, successMessage, + maxBioLength, submit, - } = useUpdateProfile(profile?.displayName ?? '', profile?.photoURL ?? ''); + } = useUpdateProfile( + profile?.displayName ?? '', + profile?.photoURL ?? '', + profile?.phone ?? '', + profile?.company ?? '', + profile?.bio ?? '', + ); // hook de favoritos del usuario const { @@ -54,8 +68,16 @@ 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 @@ -63,6 +85,37 @@ export default function ProfileScreen() { 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) { @@ -70,7 +123,21 @@ export default function ProfileScreen() { } setPhotoURL(profile?.photoURL ?? ''); - }, [profile?.displayName, profile?.photoURL, setDisplayName, setPhotoURL]); + setPhone(profile?.phone ?? ''); + setCompany(profile?.company ?? ''); + setBio(profile?.bio ?? ''); + }, [ + profile?.displayName, + profile?.photoURL, + profile?.phone, + profile?.company, + profile?.bio, + setDisplayName, + setPhotoURL, + setPhone, + setCompany, + setBio, + ]); // cerrar sesion y redirigir a pantalla de bienvenida const handleLogout = async () => { @@ -84,6 +151,9 @@ export default function ProfileScreen() { if (isEditing) { setDisplayName(profile?.displayName ?? ''); setPhotoURL(profile?.photoURL ?? ''); + setPhone(profile?.phone ?? ''); + setCompany(profile?.company ?? ''); + setBio(profile?.bio ?? ''); } setIsEditing((current) => !current); @@ -91,8 +161,12 @@ export default function ProfileScreen() { // guardar cambios del perfil const handleSaveProfile = async () => { - await submit(); - setIsEditing(false); + const wasSaved = await submit(); + + if (wasSaved) { + setIsEditing(false); + reload(); + } }; // estado de carga inicial del perfil @@ -122,13 +196,14 @@ export default function ProfileScreen() { 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 */} + {/* avatar, nombre, correo y boton editar o cancelar */} <View style={styles.headerCard}> <View style={styles.headerRow}> {photoURL ? ( @@ -148,7 +223,7 @@ export default function ProfileScreen() { {/* correo del usuario */} <Text style={styles.profileEmail}>{profile.email}</Text> - {/* boton editar perfil / cancelar */} + {/* boton editar perfil o cancelar */} <Pressable style={styles.editButton} onPress={handleToggleEditing}> <Text style={styles.editButtonText}> {isEditing ? 'Cancelar' : 'Editar perfil'} @@ -159,23 +234,40 @@ export default function ProfileScreen() { </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.sectionTitle}>Sobre mi</Text> <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> + {isEditing ? ( + <> + {/* campo editable para la descripcion personal */} + <TextInput + style={[styles.input, styles.textArea]} + value={bio} + onChangeText={setBio} + placeholder="Cuentanos algo sobre ti" + multiline + maxLength={maxBioLength} + textAlignVertical="top" + /> + + {/* contador visual para orientar el limite de la bio */} + <Text style={styles.helperText}> + {bio.length}/{maxBioLength} caracteres + </Text> + </> + ) : ( + <Text style={styles.aboutText}> + {bio?.trim() || 'Todavia no has anadido una descripcion personal.'} + </Text> + )} </View> </View> {/* seccion informacion personal */} - {/* en modo vista muestra datos */} - {/* en modo edicion muestra formulario */} + {/* en modo vista muestra datos y en modo edicion muestra formulario */} <View style={styles.section}> - <Text style={styles.sectionTitle}>Información personal</Text> + <Text style={styles.sectionTitle}>Informacion personal</Text> <View style={styles.card}> {isEditing ? ( @@ -200,6 +292,25 @@ export default function ProfileScreen() { autoCorrect={false} /> + {/* formulario de edicion: telefono */} + <Text style={styles.label}>Telefono</Text> + <TextInput + style={styles.input} + value={phone} + onChangeText={setPhone} + placeholder="+34 600 123 456" + keyboardType="phone-pad" + /> + + {/* formulario de edicion: empresa */} + <Text style={styles.label}>Empresa</Text> + <TextInput + style={styles.input} + value={company} + onChangeText={setCompany} + placeholder="Tu empresa" + /> + {/* mensajes de error o exito al guardar */} {updateError ? <StatusMessage message={updateError} /> : null} {successMessage ? ( @@ -232,28 +343,30 @@ export default function ProfileScreen() { <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.infoLabel}>Correo electronico</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> + <Text style={styles.infoLabel}>Telefono</Text> + <Text style={styles.infoValue}> + {phone?.trim() || 'No especificado'} + </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> + <Text style={styles.infoValue}> + {company?.trim() || 'No especificada'} + </Text> </View> </View> </> @@ -261,6 +374,33 @@ export default function ProfileScreen() { </View> </View> + {/* seccion actividad */} + <View style={styles.card}> + <Text style={styles.sectionTitle}>Resumen de actividad</Text> + <View style={styles.activityItem}> + <View style={styles.activityDot} /> + <Text style={styles.activityText}> + Check in confirmados en {checkedInReservationsCount} reservas. + </Text> + </View> + + <View style={styles.activityItem}> + <View style={styles.activityDot} /> + <Text style={styles.activityText}> + Actualmente tienes {activeReservations.length} reservas activas. + </Text> + </View> + + <View style={styles.activityItem}> + <View style={styles.activityDot} /> + <Text style={styles.activityText}> + {mostUsedFavoriteOffice + ? `Top de favoritos: ${mostUsedFavoriteOffice.name}.` + : 'Aun no tienes suficiente actividad para destacar un espacio favorito.'} + </Text> + </View> + </View> + {/* seccion favoritos */} <View style={styles.section}> <Text style={styles.sectionTitle}>Favoritos</Text> @@ -274,7 +414,7 @@ export default function ProfileScreen() { </Text> ) : favoriteOffices.length === 0 ? ( <Text style={styles.aboutText}> - Todavía no has marcado oficinas como favoritas. + Todavia no has marcado oficinas como favoritas. </Text> ) : ( <> @@ -300,8 +440,8 @@ export default function ProfileScreen() { ))} </View> - {/* enlace visual para ver todos los favoritos - solo aparece si hay mas de 3 favoritos */} + {/* 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> @@ -312,43 +452,13 @@ export default function ProfileScreen() { </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> + {/* seccion cierre de sesion */} + <View style={styles.logoutSection}> + <Pressable style={styles.logoutButton} onPress={handleLogout}> + <Text style={styles.logoutButtonText}>Cerrar sesion</Text> + </Pressable> </View> - {/* boton cerrar sesion */} - <Pressable style={styles.logoutButton} onPress={handleLogout}> - <View style={styles.logoutContent}> - <Feather name="log-out" size={16} color={colors.error} /> - <Text style={styles.logoutButtonText}>Cerrar sesión</Text> - </View> - </Pressable> - {/* texto inferior de version */} <Text style={styles.footerText}>App Oficina v1.0.0</Text> </ScrollView> @@ -363,7 +473,7 @@ const styles = StyleSheet.create({ }, // contenido interno del scroll - // padding general, separacion entre bloques y el ancho maximo + // padding general, separacion entre bloques y el ancho maximo // para mantener consistencia con otras pantallas content: { padding: spacing.xl, @@ -411,7 +521,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 +532,7 @@ const styles = StyleSheet.create({ headerRow: { flexDirection: 'row', alignItems: 'center', - gap: spacing.lg, + gap: spacing.xxl, }, // bloque de informacion de la cabecera @@ -433,9 +543,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,24 +558,24 @@ 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, }, - // boton pequeno de editar / cancelar + // boton pequeno de editar o cancelar editButton: { marginTop: spacing.xs, borderWidth: 1, @@ -476,7 +586,7 @@ const styles = StyleSheet.create({ alignSelf: 'flex-start', }, - // texto del boton editar / cancelar + // texto del boton editar o cancelar editButtonText: { color: colors.primary, fontSize: typography.sm, @@ -519,12 +629,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 +657,31 @@ const styles = StyleSheet.create({ color: colors.error, }, + // bloque de actividad + // 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: { @@ -569,7 +698,7 @@ const styles = StyleSheet.create({ color: colors.text, }, - // texto pequeno junto al numero + // texto pequeno junto al numero favoriteSummaryText: { fontSize: typography.sm, color: colors.textSecondary, @@ -623,7 +752,7 @@ const styles = StyleSheet.create({ color: colors.textSecondary, }, - // boton / enlace visual para ver todos los favoritos + // boton o enlace visual para ver todos los favoritos viewAllButton: { marginTop: spacing.xs, alignSelf: 'flex-start', @@ -654,6 +783,18 @@ const styles = StyleSheet.create({ backgroundColor: colors.surface, }, + // variante del input para textos mas largos + textArea: { + minHeight: 120, + }, + + // texto de apoyo para el limite de caracteres + helperText: { + fontSize: typography.sm, + color: colors.textSecondary, + textAlign: 'right', + }, + // boton principal de guardar cambios button: { backgroundColor: colors.primary, @@ -669,32 +810,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 @@ -713,6 +831,7 @@ const styles = StyleSheet.create({ color: colors.error, fontWeight: fontWeight.regular, }, + // contenido interno del boton cerrar sesion // alinea icono y texto en horizontal logoutContent: { @@ -734,4 +853,4 @@ const styles = StyleSheet.create({ color: colors.error, textAlign: 'center', }, -});
\ No newline at end of file +}); |