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 (
);
}
if (error || !profile) {
return (
{error ?? 'No se pudo cargar el perfil'}
Reintentar
);
}
return (
Perfil
Correo
{profile.email}
Nombre
{updateError ? {updateError} : null}
{successMessage ? {successMessage} : null}
{isSubmitting ? 'Guardando...' : 'Guardar cambios'}
Cerrar sesión
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
gap: 16,
},
center: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
padding: 24,
gap: 12,
},
title: {
fontSize: 28,
fontWeight: '700',
},
card: {
borderWidth: 1,
borderColor: '#ddd',
borderRadius: 12,
padding: 16,
gap: 10,
},
label: {
fontSize: 14,
fontWeight: '700',
color: '#444',
},
value: {
fontSize: 16,
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',
},
});