mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat(FinancialReports): add loading progress bar.
fix(preformance): Optimize preformance of virtualized list. fix(preformance): Optimize financial reports preformance.
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import t from 'store/types';
|
||||
import { useMutation } from 'react-query';
|
||||
import t from './types';
|
||||
import useApiRequest from '../useRequest';
|
||||
import { useQueryTenant } from '../useQueryTenant';
|
||||
import { useEffect } from 'react';
|
||||
import { useSetOrganizations, useSetSubscriptions } from '../state';
|
||||
import { omit } from 'lodash';
|
||||
|
||||
/**
|
||||
* Retrieve the contact duplicate.
|
||||
* Retrieve organizations of the authenticated user.
|
||||
*/
|
||||
export function useOrganizations(props) {
|
||||
const apiRequest = useApiRequest();
|
||||
@@ -23,3 +27,74 @@ export function useOrganizations(props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current organization metadata.
|
||||
*/
|
||||
export function useCurrentOrganization(props) {
|
||||
const apiRequest = useApiRequest();
|
||||
const setOrganizations = useSetOrganizations();
|
||||
const setSubscriptions = useSetSubscriptions();
|
||||
|
||||
const query = useQueryTenant(
|
||||
[t.ORGANIZATION_CURRENT],
|
||||
() => apiRequest.get(`organization/current`),
|
||||
{
|
||||
select: (res) => res.data.organization,
|
||||
initialDataUpdatedAt: 0,
|
||||
initialData: {
|
||||
data: {
|
||||
organization: {},
|
||||
},
|
||||
},
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (query.isSuccess) {
|
||||
const organization = omit(query.data, ['subscriptions']);
|
||||
|
||||
// Sets organizations.
|
||||
setOrganizations([organization]);
|
||||
|
||||
// Sets subscriptions.
|
||||
setSubscriptions(query.data.subscriptions);
|
||||
}
|
||||
}, [query.data, query.isSuccess, setOrganizations, setSubscriptions]);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the current tenant.
|
||||
*/
|
||||
export function useBuildTenant(props) {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(values) => apiRequest.post('organization/build'),
|
||||
{
|
||||
onSuccess: (res, values) => {
|
||||
|
||||
},
|
||||
...props,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Seeds the current tenant
|
||||
*/
|
||||
export function useSeedTenant() {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(values) => apiRequest.post('organization/seed'),
|
||||
{
|
||||
onSuccess: (res) => {
|
||||
|
||||
},
|
||||
}
|
||||
)
|
||||
};
|
||||
Reference in New Issue
Block a user