added new hook - useContactProfile

This commit is contained in:
Pramod Mahajan 2025-05-20 13:11:59 +05:30
parent 8a53e2d8de
commit 39ea50115f

View File

@ -61,3 +61,41 @@ export const useBuckets = () => {
return { buckets, loading, error };
};
export const useContactProfile = (id) =>
{
const [ conatProfile, setContactProfile ] = useState( null );
const [ loading, setLoading ] = useState( false );
const [ Error, setError ] = useState( "" );
const fetchContactProfile = async () => {
const cached = getCachedData("Contact Profile");
if (!cached || cached.contactId !== id) {
setLoading(true);
try {
const resp = await DirectoryRepository.GetContactProfile(id);
setContactProfile(resp.data);
cacheData("Contact Profile", { data: resp.data, contactId: id });
} catch (err) {
const msg =
err?.response?.data?.message || err?.message || "Something went wrong";
setError(msg);
} finally {
setLoading(false);
}
} else {
setContactProfile(cached.data);
}
};
useEffect(() => {
if ( id )
{
fetchContactProfile(id);
}
}, [id]);
return { conatProfile, loading, Error };
}