created useContactNote hook

This commit is contained in:
Pramod Mahajan 2025-05-20 18:09:18 +05:30
parent 3738730ecf
commit 6e8bd7eef8

View File

@ -99,3 +99,42 @@ const fetchContactProfile = async () => {
return { conatProfile, loading, Error };
}
export const useContactNotes = (id) =>
{
const [ conatNotes, setContactNotes ] = useState( [] );
const [ loading, setLoading ] = useState( false );
const [ Error, setError ] = useState( "" );
const fetchContactNotes = async () => {
const cached = getCachedData("Contact Notes");
if (!cached || cached.contactId !== id) {
setLoading(true);
try {
const resp = await DirectoryRepository.GetNote(id);
setContactNotes(resp.data);
cacheData("Contact Notes", { data: resp.data, contactId: id });
} catch (err) {
const msg =
err?.response?.data?.message || err?.message || "Something went wrong";
setError(msg);
} finally {
setLoading(false);
}
} else {
setContactNotes(cached.data);
}
};
useEffect(() => {
if ( id )
{
fetchContactNotes(id);
}
}, [id]);
return { conatProfile, loading, Error };
}