diff options
| author | Alberto Duarte Delgado <alberto@albertoduarte.com> | 2026-04-19 21:46:46 +0100 |
|---|---|---|
| committer | Alberto Duarte Delgado <alberto@albertoduarte.com> | 2026-04-19 21:46:46 +0100 |
| commit | be90a5f202f80bb423c6e0aaf1c4d5feca668f01 (patch) | |
| tree | c91081a6c60d2f1efb4de22c324721c5d798e3ee /src/features/profile/hooks/useUpdateProfile.ts | |
| parent | 40cc6cea25d048c2e77e11bbfea0cd1e5eb784f6 (diff) | |
| parent | 4d0962a44715f71acd2fc9ea59bf87d8da70f662 (diff) | |
Merge branch 'feature/anita' into develop
Diffstat (limited to 'src/features/profile/hooks/useUpdateProfile.ts')
| -rw-r--r-- | src/features/profile/hooks/useUpdateProfile.ts | 40 |
1 files changed, 36 insertions, 4 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, }; } |