summaryrefslogtreecommitdiffstats
path: root/src/features/profile/hooks/useUpdateProfile.ts
diff options
context:
space:
mode:
authorAlberto Duarte Delgado <alberto@albertoduarte.com>2026-03-30 18:12:23 +0100
committerAlberto Duarte Delgado <alberto@albertoduarte.com>2026-03-30 18:12:23 +0100
commit7a196010214db6a1789760958eee5228374a7745 (patch)
treee8d936b04bdf72acbe9c5910fee95add0bef7e94 /src/features/profile/hooks/useUpdateProfile.ts
parent174f1acd46c4ffbde88c04465e8fa6b6810ce113 (diff)
logica perfil de usuario
Diffstat (limited to 'src/features/profile/hooks/useUpdateProfile.ts')
-rw-r--r--src/features/profile/hooks/useUpdateProfile.ts52
1 files changed, 52 insertions, 0 deletions
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,
+ };
+}