summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app/(protected)/(tabs)/home.tsx42
-rw-r--r--src/app/(protected)/(tabs)/profile/index.tsx134
-rw-r--r--src/features/profile/hooks/useProfile.ts45
-rw-r--r--src/features/profile/hooks/useProfile.ts~0
-rw-r--r--src/features/profile/hooks/useUpdateProfile.ts52
-rw-r--r--src/features/profile/hooks/useUpdateProfile.ts~0
-rw-r--r--src/features/profile/services/profileService.ts45
-rw-r--r--src/features/profile/services/profileService.ts~0
-rw-r--r--src/features/profile/types.ts8
-rw-r--r--src/features/profile/types.ts~0
10 files changed, 313 insertions, 13 deletions
diff --git a/src/app/(protected)/(tabs)/home.tsx b/src/app/(protected)/(tabs)/home.tsx
index 76a5bda..d9e64ac 100644
--- a/src/app/(protected)/(tabs)/home.tsx
+++ b/src/app/(protected)/(tabs)/home.tsx
@@ -1,8 +1,9 @@
+import { Link } from 'expo-router';
import { Pressable, StyleSheet, Text, View } from 'react-native';
import { useAuthSession } from '@/providers/AuthProvider';
export default function HomeScreen() {
- const { user, logout } = useAuthSession();
+ const { user } = useAuthSession();
return (
<View style={styles.container}>
@@ -12,9 +13,25 @@ export default function HomeScreen() {
</Text>
<Text style={styles.email}>{user?.email}</Text>
- <Pressable style={styles.button} onPress={logout}>
- <Text style={styles.buttonText}>Cerrar sesión</Text>
- </Pressable>
+ <View style={styles.actions}>
+ <Link href="/(protected)/(tabs)/offices" asChild>
+ <Pressable style={styles.button}>
+ <Text style={styles.buttonText}>Ver espacios</Text>
+ </Pressable>
+ </Link>
+
+ <Link href="/(protected)/(tabs)/reservations" asChild>
+ <Pressable style={styles.button}>
+ <Text style={styles.buttonText}>Mis reservas</Text>
+ </Pressable>
+ </Link>
+
+ <Link href="/(protected)/(tabs)/profile" asChild>
+ <Pressable style={styles.secondaryButton}>
+ <Text style={styles.buttonText}>Ir a perfil</Text>
+ </Pressable>
+ </Link>
+ </View>
</View>
);
}
@@ -22,23 +39,32 @@ export default function HomeScreen() {
const styles = StyleSheet.create({
container: {
flex: 1,
+ padding: 16,
justifyContent: 'center',
- padding: 24,
gap: 12,
},
title: {
- fontSize: 28,
+ fontSize: 30,
fontWeight: '700',
},
subtitle: {
fontSize: 18,
},
email: {
- color: '#555',
+ color: '#666',
marginBottom: 20,
},
+ actions: {
+ gap: 12,
+ },
button: {
- backgroundColor: '#c62828',
+ backgroundColor: '#1f6feb',
+ paddingVertical: 14,
+ borderRadius: 10,
+ alignItems: 'center',
+ },
+ secondaryButton: {
+ backgroundColor: '#555',
paddingVertical: 14,
borderRadius: 10,
alignItems: 'center',
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',
},
});
diff --git a/src/features/profile/hooks/useProfile.ts b/src/features/profile/hooks/useProfile.ts
new file mode 100644
index 0000000..82068f4
--- /dev/null
+++ b/src/features/profile/hooks/useProfile.ts
@@ -0,0 +1,45 @@
+// src/features/profile/hooks/useProfile.ts
+
+import { useEffect, useState } from 'react';
+import { useAuthSession } from '@/providers/AuthProvider';
+import { profileService } from '@/features/profile/services/profileService';
+import { UserProfile } from '@/features/profile/types';
+
+export function useProfile() {
+ const { user } = useAuthSession();
+
+ const [profile, setProfile] = useState<UserProfile | null>(null);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState<string | null>(null);
+
+ const loadProfile = async () => {
+ if (!user?.uid) {
+ setProfile(null);
+ setLoading(false);
+ return;
+ }
+
+ try {
+ setError(null);
+ setLoading(true);
+
+ const data = await profileService.getMyProfile(user.uid);
+ setProfile(data);
+ } catch (err: any) {
+ setError(err?.message ?? 'No se pudo cargar el perfil');
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ useEffect(() => {
+ loadProfile();
+ }, [user?.uid]);
+
+ return {
+ profile,
+ loading,
+ error,
+ reload: loadProfile,
+ };
+}
diff --git a/src/features/profile/hooks/useProfile.ts~ b/src/features/profile/hooks/useProfile.ts~
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/features/profile/hooks/useProfile.ts~
diff --git a/src/features/profile/hooks/useUpdateProfile.ts b/src/features/profile/hooks/useUpdateProfile.ts
new file mode 100644
index 0000000..505bfbb
--- /dev/null
+++ b/src/features/profile/hooks/useUpdateProfile.ts
@@ -0,0 +1,52 @@
+// src/features/profile/hooks/useUpdateProfile.ts
+
+import { useState } from 'react';
+import { profileService } from '@/features/profile/services/profileService';
+import { useAuthSession } from '@/providers/AuthProvider';
+
+export function useUpdateProfile(initialDisplayName = '') {
+ const { user } = useAuthSession();
+
+ const [displayName, setDisplayName] = useState(initialDisplayName);
+ const [isSubmitting, setIsSubmitting] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+ const [successMessage, setSuccessMessage] = useState<string | null>(null);
+
+ const submit = async () => {
+ if (!user?.uid) {
+ setError('No hay usuario autenticado');
+ return;
+ }
+
+ if (!displayName.trim()) {
+ setError('El nombre no puede estar vacío');
+ return;
+ }
+
+ try {
+ setError(null);
+ setSuccessMessage(null);
+ setIsSubmitting(true);
+
+ await profileService.updateMyProfile({
+ uid: user.uid,
+ displayName: displayName.trim(),
+ });
+
+ setSuccessMessage('Perfil actualizado correctamente');
+ } catch (err: any) {
+ setError(err?.message ?? 'No se pudo actualizar el perfil');
+ } finally {
+ setIsSubmitting(false);
+ }
+ };
+
+ return {
+ displayName,
+ setDisplayName,
+ isSubmitting,
+ error,
+ successMessage,
+ submit,
+ };
+}
diff --git a/src/features/profile/hooks/useUpdateProfile.ts~ b/src/features/profile/hooks/useUpdateProfile.ts~
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/features/profile/hooks/useUpdateProfile.ts~
diff --git a/src/features/profile/services/profileService.ts b/src/features/profile/services/profileService.ts
new file mode 100644
index 0000000..566c3fa
--- /dev/null
+++ b/src/features/profile/services/profileService.ts
@@ -0,0 +1,45 @@
+// src/features/profile/services/profileService.ts
+
+import { doc, getDoc, updateDoc } from 'firebase/firestore';
+import { updateProfile } from 'firebase/auth';
+import { db, auth } from '@/shared/lib/firebase/config';
+import { UserProfile } from '@/features/profile/types';
+
+export const profileService = {
+ async getMyProfile(uid: string): Promise<UserProfile | null> {
+ const snapshot = await getDoc(doc(db, 'users', uid));
+
+ if (!snapshot.exists()) {
+ return null;
+ }
+
+ const data = snapshot.data();
+
+ return {
+ uid,
+ email: data.email ?? '',
+ displayName: data.displayName ?? '',
+ photoURL: data.photoURL ?? '',
+ };
+ },
+
+ async updateMyProfile(params: {
+ uid: string;
+ displayName: string;
+ photoURL?: string;
+ }): Promise<void> {
+ const { uid, displayName, photoURL } = params;
+
+ await updateDoc(doc(db, 'users', uid), {
+ displayName,
+ ...(photoURL !== undefined ? { photoURL } : {}),
+ });
+
+ if (auth.currentUser) {
+ await updateProfile(auth.currentUser, {
+ displayName,
+ ...(photoURL !== undefined ? { photoURL } : {}),
+ });
+ }
+ },
+};
diff --git a/src/features/profile/services/profileService.ts~ b/src/features/profile/services/profileService.ts~
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/features/profile/services/profileService.ts~
diff --git a/src/features/profile/types.ts b/src/features/profile/types.ts
new file mode 100644
index 0000000..1c6d219
--- /dev/null
+++ b/src/features/profile/types.ts
@@ -0,0 +1,8 @@
+// src/features/profile/types.ts
+
+export type UserProfile = {
+ uid: string;
+ email: string;
+ displayName: string;
+ photoURL?: string;
+};
diff --git a/src/features/profile/types.ts~ b/src/features/profile/types.ts~
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/features/profile/types.ts~