created new hook useOrganization
This commit is contained in:
parent
3f7456e5e7
commit
eb0e424a18
@ -146,3 +146,38 @@ const fetchContactNotes = async () => {
|
||||
|
||||
return { contactNotes, loading, Error };
|
||||
}
|
||||
|
||||
|
||||
export const useOrganization = () =>
|
||||
{
|
||||
const [organizationList, setOrganizationList] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [ error, setError ] = useState( "" );
|
||||
|
||||
|
||||
const fetchOrg = async() =>
|
||||
{
|
||||
const cacheOrg = getCachedData("organizations");
|
||||
if (cacheOrg?.length != 0) {
|
||||
setLoading( true );
|
||||
try {
|
||||
const resp = await DirectoryRepository.GetOrganizations()
|
||||
cacheData( "organizations", resp.data );
|
||||
setOrganizationList( resp.data );
|
||||
setLoading(false)
|
||||
} catch (error) {
|
||||
const msg =
|
||||
error?.response?.data?.message || error?.message || "Something went wrong";
|
||||
setError(msg);
|
||||
}
|
||||
} else {
|
||||
setOrganizationList(cacheOrg);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
fetchOrg();
|
||||
}, []);
|
||||
|
||||
return { organizationList, loading, error };
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
import {api} from "../utils/axiosClient";
|
||||
|
||||
export const DirectoryRepository = {
|
||||
GetOrganizations:()=>api.get('/api/directory/organization'),
|
||||
|
||||
GetContacts: (isActive) => api.get( `/api/directory?active=${isActive}` ),
|
||||
CreateContact: ( data ) => api.post( '/api/directory', data ),
|
||||
UpdateContact: ( id, data ) => api.put( `/api/directory/${ id }`, data ),
|
||||
|
Loading…
x
Reference in New Issue
Block a user