summaryrefslogtreecommitdiffstats
path: root/src/app/(protected)/(tabs)/profile
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/(protected)/(tabs)/profile')
-rw-r--r--src/app/(protected)/(tabs)/profile/index.tsx134
1 files changed, 129 insertions, 5 deletions
diff --git a/src/app/(protected)/(tabs)/profile/index.tsx b/src/app/(protected)/(tabs)/profile/index.tsx
index a59d568..4af1fe0 100644
--- a/src/app/(protected)/(tabs)/profile/index.tsx
+++ b/src/app/(protected)/(tabs)/profile/index.tsx
@@ -1,10 +1,88 @@
-import { StyleSheet, Text, View } from 'react-native';
+import { useEffect } from 'react';
+import {
+ ActivityIndicator,
+ Pressable,
+ StyleSheet,
+ Text,
+ TextInput,
+ View,
+} from 'react-native';
+import { useAuthSession } from '@/providers/AuthProvider';
+import { useProfile } from '@/features/profile/hooks/useProfile';
+import { useUpdateProfile } from '@/features/profile/hooks/useUpdateProfile';
+import { router } from 'expo-router';
export default function ProfileScreen() {
+ const { logout } = useAuthSession();
+ const { profile, loading, error, reload } = useProfile();
+ const {
+ displayName,
+ setDisplayName,
+ isSubmitting,
+ error: updateError,
+ successMessage,
+ submit,
+ } = useUpdateProfile(profile?.displayName ?? '');
+
+ useEffect(() => {
+ if (profile?.displayName) {
+ setDisplayName(profile.displayName);
+ }
+ }, [profile?.displayName]);
+
+ const handleLogout = async () => {
+ await logout();
+ router.replace('/(auth)/welcome');
+ };
+
+ if (loading) {
+ return (
+ <View style={styles.center}>
+ <ActivityIndicator size="large" />
+ </View>
+ );
+ }
+
+ 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>
+ </View>
+ );
+ }
+
return (
<View style={styles.container}>
<Text style={styles.title}>Perfil</Text>
- <Text style={styles.text}>Pantalla en construcción.</Text>
+
+ <View style={styles.card}>
+ <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"
+ />
+
+ {updateError ? <Text style={styles.error}>{updateError}</Text> : null}
+ {successMessage ? <Text style={styles.success}>{successMessage}</Text> : null}
+
+ <Pressable style={styles.button} onPress={submit} disabled={isSubmitting}>
+ <Text style={styles.buttonText}>
+ {isSubmitting ? 'Guardando...' : 'Guardar cambios'}
+ </Text>
+ </Pressable>
+ </View>
+
+ <Pressable style={styles.logoutButton} onPress={handleLogout}>
+ <Text style={styles.buttonText}>Cerrar sesión</Text>
+ </Pressable>
</View>
);
}
@@ -13,16 +91,62 @@ const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
- justifyContent: 'center',
+ gap: 16,
+ },
+ center: {
+ flex: 1,
alignItems: 'center',
+ justifyContent: 'center',
+ padding: 24,
gap: 12,
},
title: {
fontSize: 28,
fontWeight: '700',
},
- text: {
+ card: {
+ borderWidth: 1,
+ borderColor: '#ddd',
+ borderRadius: 12,
+ padding: 16,
+ gap: 10,
+ },
+ label: {
+ fontSize: 14,
+ fontWeight: '700',
+ color: '#444',
+ },
+ value: {
fontSize: 16,
- color: '#555',
+ color: '#111',
+ },
+ input: {
+ borderWidth: 1,
+ borderColor: '#ccc',
+ borderRadius: 10,
+ paddingHorizontal: 14,
+ paddingVertical: 12,
+ },
+ button: {
+ backgroundColor: '#1f6feb',
+ paddingVertical: 14,
+ borderRadius: 10,
+ alignItems: 'center',
+ },
+ logoutButton: {
+ backgroundColor: '#c62828',
+ paddingVertical: 14,
+ borderRadius: 10,
+ alignItems: 'center',
+ },
+ buttonText: {
+ color: '#fff',
+ fontWeight: '600',
+ },
+ error: {
+ color: 'red',
+ },
+ success: {
+ color: 'green',
},
});