created new hook useOrganization

This commit is contained in:
Pramod Mahajan 2025-05-27 15:05:35 +05:30
parent 3f7456e5e7
commit eb0e424a18
2 changed files with 37 additions and 0 deletions

View File

@ -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 };
}

View File

@ -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 ),