created separate contactCategory and contactTag hook for managing contacts creation and edition
This commit is contained in:
parent
ada8856b3b
commit
42b769c1b5
@ -157,4 +157,67 @@ export const useActivitiesMaster = () =>
|
|||||||
}, [] )
|
}, [] )
|
||||||
|
|
||||||
return {categories,categoryLoading,categoryError}
|
return {categories,categoryLoading,categoryError}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 };
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user