From 1f8ba16447135bcbf2523c296fe939426fd880c5 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Thu, 29 May 2025 17:26:07 +0530 Subject: [PATCH] changed useDirectory hook calling format --- src/hooks/useDirectory.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/hooks/useDirectory.js b/src/hooks/useDirectory.js index 0854d543..7ec08c4b 100644 --- a/src/hooks/useDirectory.js +++ b/src/hooks/useDirectory.js @@ -77,9 +77,7 @@ export const useContactProfile = (id) => { 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); @@ -94,18 +92,20 @@ export const useContactProfile = (id) => { } finally { setLoading(false); } + + }; + + useEffect( () => + { + const cached = getCachedData("Contact Profile"); + if (!cached || cached.contactId !== id) { + fetchContactProfile(id); } else { setContactProfile(cached.data); } - }; - - useEffect(() => { - if (id) { - fetchContactProfile(id); - } }, [id]); - return { contactProfile, loading, Error }; + return { contactProfile, loading, Error ,refetch:fetchContactProfile}; }; export const useContactNotes = (id, IsActive) => { @@ -113,10 +113,9 @@ export const useContactNotes = (id, IsActive) => { const [loading, setLoading] = useState(false); const [Error, setError] = useState(""); - const fetchContactNotes = async () => { - const cached = getCachedData("Contact Notes"); + const fetchContactNotes = async (id,IsActive) => { + - if (!cached || cached.contactId !== id) { setLoading(true); try { const resp = await DirectoryRepository.GetNote(id, IsActive); @@ -131,18 +130,19 @@ export const useContactNotes = (id, IsActive) => { } finally { setLoading(false); } - } else { - setContactNotes(cached.data); - } + }; useEffect(() => { - if (id) { - fetchContactNotes(id); + const cached = getCachedData("Contact Notes"); + if (!cached || cached.contactId !== id) { + fetchContactNotes(id,IsActive); + } else { + setContactNotes(cached.data); } - }, [id]); + }, [id,IsActive]); - return { contactNotes, loading, Error }; + return { contactNotes, loading, Error,refetch:fetchContactNotes }; }; export const useOrganization = () => {