From 7a196010214db6a1789760958eee5228374a7745 Mon Sep 17 00:00:00 2001 From: Alberto Duarte Delgado Date: Mon, 30 Mar 2026 18:12:23 +0100 Subject: logica perfil de usuario --- src/features/profile/hooks/useProfile.ts | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/features/profile/hooks/useProfile.ts (limited to 'src/features/profile/hooks/useProfile.ts') 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(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(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, + }; +} -- cgit v1.2.3-54-g00ecf