From 42b769c1b51e1683a8c303eeabbf248282e86c03 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Sun, 18 May 2025 02:24:10 +0530 Subject: [PATCH] created separate contactCategory and contactTag hook for managing contacts creation and edition --- src/hooks/masterHook/useMaster.js | 65 ++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/hooks/masterHook/useMaster.js b/src/hooks/masterHook/useMaster.js index 174c43cb..ee37cbda 100644 --- a/src/hooks/masterHook/useMaster.js +++ b/src/hooks/masterHook/useMaster.js @@ -157,4 +157,67 @@ export const useActivitiesMaster = () => }, [] ) return {categories,categoryLoading,categoryError} - } \ No newline at end of file +} + +export const useContactCategory = () => +{ + const [ contactCategory, setContactCategory ] = useState( [] ) + const [ loading, setLoading ] = useState( false ) + const [ Error, setError ] = useState() + + const fetchConatctCategory = async() => + { + const cache_Category = getCachedData( "Contact Category" ); + if ( !cache_Category ) + { + try + { + let resp = await MasterRespository.getContactCategory(); + setContactCategory( resp.data ); + cacheData("Contact Category",resp.data) + } catch ( error ) + { + setError(error) + } + } else + { + setContactCategory(cache_Category) + } + } + + useEffect( () => + { + fetchConatctCategory() + }, [] ) + return { contactCategory,loading,Error} +} +export const useContactTags = () => { + const [contactTags, setContactTags] = useState([]); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + + useEffect(() => { + const fetchContactTag = async () => { + const cache_Tags = getCachedData("Contact Tag"); + + if (!cache_Tags) { + setLoading(true); + try { + const resp = await MasterRespository.getContactTag(); + setContactTags(resp.data); + cacheData("Contact Tag", resp.data); + } catch (err) { + setError(err); + } finally { + setLoading(false); + } + } else { + setContactTags(cache_Tags); + } + }; + + fetchContactTag(); + }, []); + + return { contactTags, loading, error }; +}; \ No newline at end of file