summaryrefslogtreecommitdiffstats
path: root/src/features/profile
diff options
context:
space:
mode:
authorAlberto Duarte Delgado <alberto@albertoduarte.com>2026-04-19 21:46:46 +0100
committerAlberto Duarte Delgado <alberto@albertoduarte.com>2026-04-19 21:46:46 +0100
commitbe90a5f202f80bb423c6e0aaf1c4d5feca668f01 (patch)
treec91081a6c60d2f1efb4de22c324721c5d798e3ee /src/features/profile
parent40cc6cea25d048c2e77e11bbfea0cd1e5eb784f6 (diff)
parent4d0962a44715f71acd2fc9ea59bf87d8da70f662 (diff)
Merge branch 'feature/anita' into develop
Diffstat (limited to 'src/features/profile')
-rw-r--r--src/features/profile/hooks/useUpdateProfile.ts40
-rw-r--r--src/features/profile/services/profileService.ts67
-rw-r--r--src/features/profile/types.ts3
3 files changed, 92 insertions, 18 deletions
diff --git a/src/features/profile/hooks/useUpdateProfile.ts b/src/features/profile/hooks/useUpdateProfile.ts
index cd4a39a..f8f20f9 100644
--- a/src/features/profile/hooks/useUpdateProfile.ts
+++ b/src/features/profile/hooks/useUpdateProfile.ts
@@ -5,11 +5,22 @@ import { profileService } from '@/features/profile/services/profileService';
import { useAuthSession } from '@/providers/AuthProvider';
import { getErrorMessage } from '@/shared/lib/errors/getErrorMessage';
-export function useUpdateProfile(initialDisplayName = '', initialPhotoURL = '') {
+const MAX_BIO_LENGTH = 200;
+
+export function useUpdateProfile(
+ initialDisplayName = '',
+ initialPhotoURL = '',
+ initialPhone = '',
+ initialCompany = '',
+ initialBio = '',
+) {
const { user } = useAuthSession();
const [displayName, setDisplayName] = useState(initialDisplayName);
const [photoURL, setPhotoURL] = useState(initialPhotoURL);
+ const [phone, setPhone] = useState(initialPhone);
+ const [company, setCompany] = useState(initialCompany);
+ const [bio, setBio] = useState(initialBio);
const [isSubmitting, setIsSubmitting] = useState(false);
const [error, setError] = useState<string | null>(null);
const [successMessage, setSuccessMessage] = useState<string | null>(null);
@@ -17,12 +28,18 @@ export function useUpdateProfile(initialDisplayName = '', initialPhotoURL = '')
const submit = async () => {
if (!user?.uid) {
setError('No hay usuario autenticado');
- return;
+ return false;
}
if (!displayName.trim()) {
- setError('El nombre no puede estar vacĂ­o');
- return;
+ setError('El nombre no puede estar vacio');
+ return false;
+ }
+
+ // validacion del campo bio antes de enviar los cambios
+ if (bio.trim().length > MAX_BIO_LENGTH) {
+ setError(`La bio no puede superar los ${MAX_BIO_LENGTH} caracteres`);
+ return false;
}
try {
@@ -34,12 +51,20 @@ export function useUpdateProfile(initialDisplayName = '', initialPhotoURL = '')
uid: user.uid,
displayName: displayName.trim(),
photoURL: photoURL.trim(),
+ phone: phone.trim(),
+ company: company.trim(),
+ bio: bio.trim(),
});
setPhotoURL(photoURL.trim());
+ setPhone(phone.trim());
+ setCompany(company.trim());
+ setBio(bio.trim());
setSuccessMessage('Perfil actualizado correctamente');
+ return true;
} catch (err) {
setError(getErrorMessage(err, 'No se pudo actualizar el perfil'));
+ return false;
} finally {
setIsSubmitting(false);
}
@@ -48,11 +73,18 @@ export function useUpdateProfile(initialDisplayName = '', initialPhotoURL = '')
return {
displayName,
photoURL,
+ phone,
+ company,
+ bio,
setDisplayName,
setPhotoURL,
+ setPhone,
+ setCompany,
+ setBio,
isSubmitting,
error,
successMessage,
+ maxBioLength: MAX_BIO_LENGTH,
submit,
};
}
diff --git a/src/features/profile/services/profileService.ts b/src/features/profile/services/profileService.ts
index f7e89b4..c202c18 100644
--- a/src/features/profile/services/profileService.ts
+++ b/src/features/profile/services/profileService.ts
@@ -1,13 +1,21 @@
// src/features/profile/services/profileService.ts
-import { doc, getDoc, setDoc } from 'firebase/firestore';
-import { updateProfile } from 'firebase/auth';
-import { db, auth } from '@/shared/lib/firebase/config';
-import { UserProfile } from '@/features/profile/types';
+import { UserProfile } from "@/features/profile/types";
+import { auth, db } from "@/shared/lib/firebase/config";
+import { mockDelay, mockUserProfile } from "@/shared/lib/mockData";
+import { updateProfile } from "firebase/auth";
+import { doc, getDoc, setDoc } from "firebase/firestore";
+
+const USE_MOCK = process.env.EXPO_PUBLIC_USE_MOCK_DATA === "true";
export const profileService = {
async getMyProfile(uid: string): Promise<UserProfile | null> {
- const snapshot = await getDoc(doc(db, 'users', uid));
+ if (USE_MOCK) {
+ await mockDelay();
+ return mockUserProfile.uid === uid ? mockUserProfile : null;
+ }
+
+ const snapshot = await getDoc(doc(db, "users", uid));
if (!snapshot.exists()) {
return null;
@@ -17,9 +25,12 @@ export const profileService = {
return {
uid,
- email: data.email ?? '',
- displayName: data.displayName ?? '',
- photoURL: data.photoURL ?? '',
+ email: data.email ?? "",
+ displayName: data.displayName ?? "",
+ photoURL: data.photoURL ?? "",
+ phone: data.phone ?? "",
+ company: data.company ?? "",
+ bio: data.bio ?? "",
};
},
@@ -27,15 +38,43 @@ export const profileService = {
uid: string;
displayName: string;
photoURL?: string;
+ phone?: string;
+ company?: string;
+ bio?: string;
}): Promise<void> {
- const { uid, displayName, photoURL } = params;
+ if (USE_MOCK) {
+ await mockDelay();
+ mockUserProfile.displayName = params.displayName;
+ if (params.photoURL !== undefined) {
+ mockUserProfile.photoURL = params.photoURL;
+ }
+ if (params.phone !== undefined) {
+ mockUserProfile.phone = params.phone;
+ }
+ if (params.company !== undefined) {
+ mockUserProfile.company = params.company;
+ }
+ if (params.bio !== undefined) {
+ mockUserProfile.bio = params.bio;
+ }
+ return;
+ }
+
+ const { uid, displayName, photoURL, phone, company, bio } = params;
const currentUser = auth.currentUser;
- await setDoc(doc(db, 'users', uid), {
- email: currentUser?.email ?? '',
- displayName,
- ...(photoURL !== undefined ? { photoURL } : {}),
- }, { merge: true });
+ await setDoc(
+ doc(db, "users", uid),
+ {
+ email: currentUser?.email ?? "",
+ displayName,
+ ...(photoURL !== undefined ? { photoURL } : {}),
+ ...(phone !== undefined ? { phone } : {}),
+ ...(company !== undefined ? { company } : {}),
+ ...(bio !== undefined ? { bio } : {}),
+ },
+ { merge: true },
+ );
if (currentUser) {
await updateProfile(currentUser, {
diff --git a/src/features/profile/types.ts b/src/features/profile/types.ts
index 1c6d219..579d5db 100644
--- a/src/features/profile/types.ts
+++ b/src/features/profile/types.ts
@@ -5,4 +5,7 @@ export type UserProfile = {
email: string;
displayName: string;
photoURL?: string;
+ phone?: string; // numero de telefono del usuario
+ company?: string; // empresa donde trabaja el usuario
+ bio?: string; // descripcion personal o "acerca de mi" (max 200 caracteres)
};