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