summaryrefslogtreecommitdiffstats
path: root/src/features/profile/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/profile/hooks')
-rw-r--r--src/features/profile/hooks/useUpdateProfile.ts40
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,
};
}