created useContactNote hook
This commit is contained in:
parent
3738730ecf
commit
6e8bd7eef8
@ -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 };
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user