mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: invlidate cashflow queries after mutate assocaited queries.
This commit is contained in:
@@ -13,6 +13,9 @@ const commonInvalidateQueries = (query) => {
|
||||
query.invalidateQueries(t.ACCOUNTS);
|
||||
query.invalidateQueries(t.ACCOUNT);
|
||||
|
||||
// Invalidate cashflow accounts.
|
||||
query.invalidateQueries(t.CASH_FLOW_ACCOUNTS);
|
||||
|
||||
// Invalidate financial reports.
|
||||
query.invalidateQueries(t.FINANCIAL_REPORT);
|
||||
};
|
||||
|
||||
@@ -7,7 +7,19 @@ const commonInvalidateQueries = (queryClient) => {
|
||||
// Invalidate accounts.
|
||||
queryClient.invalidateQueries(t.ACCOUNTS);
|
||||
queryClient.invalidateQueries(t.ACCOUNT);
|
||||
queryClient.invalidateQueries(t.CASH_FLOW_TRANSACTION);
|
||||
|
||||
// Invalidate account transactions.
|
||||
queryClient.invalidateQueries(t.ACCOUNT_TRANSACTION);
|
||||
|
||||
// Invalidate cashflow accounts.
|
||||
queryClient.invalidateQueries(t.CASH_FLOW_ACCOUNTS);
|
||||
|
||||
// Invalidate the cashflow transactions.
|
||||
queryClient.invalidateQueries(t.CASH_FLOW_TRANSACTIONS);
|
||||
queryClient.invalidateQueries(t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY);
|
||||
|
||||
// Invalidate financial reports.
|
||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -28,10 +40,10 @@ export function useCashflowAccounts(query, props) {
|
||||
/**
|
||||
* Retrieve account transactions list.
|
||||
*/
|
||||
export function useCashflowTransactions(id, props) {
|
||||
export function useCashflowTransactions(accountId, props) {
|
||||
return useRequestQuery(
|
||||
[t.CASH_FLOW_TRANSACTIONS, id],
|
||||
{ method: 'get', url: `cashflow/account/${id}/transactions` },
|
||||
[t.CASH_FLOW_TRANSACTIONS, accountId],
|
||||
{ method: 'get', url: `cashflow/account/${accountId}/transactions` },
|
||||
{
|
||||
select: (res) => res.data.cashflow_transactions,
|
||||
defaultData: [],
|
||||
@@ -68,8 +80,6 @@ export function useDeleteCashflowTransaction(props) {
|
||||
|
||||
return useMutation((id) => apiRequest.delete(`cashflow/transactions/${id}`), {
|
||||
onSuccess: (res, id) => {
|
||||
queryClient.invalidateQueries([t.CASH_FLOW_TRANSACTION, id]);
|
||||
|
||||
// Invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
@@ -92,7 +102,7 @@ export function useAccountTransactionsInfinity(
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useInfiniteQuery(
|
||||
['CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY', accountId],
|
||||
[t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY, accountId],
|
||||
async ({ pageParam = 1 }) => {
|
||||
const response = await apiRequest.http({
|
||||
...axios,
|
||||
@@ -115,3 +125,42 @@ export function useAccountTransactionsInfinity(
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh cashflow transactions infinity.
|
||||
*/
|
||||
export function useRefreshCashflowTransactionsInfinity() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries(t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh cashflow accounts.
|
||||
*/
|
||||
export function useRefreshCashflowAccounts() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries(t.CASH_FLOW_ACCOUNTS);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the cshflow account transactions.
|
||||
*/
|
||||
export function useRefreshCashflowTransactions() {
|
||||
const query = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
query.invalidateQueries(t.CASH_FLOW_TRANSACTIONS);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ const commonInvalidateQueries = (queryClient) => {
|
||||
|
||||
// Invalidate financial reports.
|
||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
||||
|
||||
// Invalidate the cashflow transactions.
|
||||
queryClient.invalidateQueries(t.CASH_FLOW_TRANSACTIONS);
|
||||
queryClient.invalidateQueries(t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY);
|
||||
};
|
||||
|
||||
const transformExpenses = (response) => ({
|
||||
|
||||
@@ -22,6 +22,10 @@ const commonInvalidateQueries = (client) => {
|
||||
|
||||
// Invalidate financial reports.
|
||||
client.invalidateQueries(t.FINANCIAL_REPORT);
|
||||
|
||||
// Invalidate the cashflow transactions.
|
||||
client.invalidateQueries(t.CASH_FLOW_TRANSACTIONS);
|
||||
client.invalidateQueries(t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,10 @@ const commonInvalidateQueries = (client) => {
|
||||
// Invalidate vendors.
|
||||
client.invalidateQueries(t.VENDORS);
|
||||
client.invalidateQueries(t.VENDOR);
|
||||
|
||||
// Invalidate the cashflow transactions.
|
||||
client.invalidateQueries(t.CASH_FLOW_TRANSACTIONS);
|
||||
client.invalidateQueries(t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,10 @@ const commonInvalidateQueries = (client) => {
|
||||
// Invalidate customers.
|
||||
client.invalidateQueries(t.CUSTOMERS);
|
||||
client.invalidateQueries(t.CUSTOMER);
|
||||
|
||||
// Invalidate the cashflow transactions.
|
||||
client.invalidateQueries(t.CASH_FLOW_TRANSACTIONS);
|
||||
client.invalidateQueries(t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY);
|
||||
};
|
||||
|
||||
// Transform payment receives.
|
||||
|
||||
@@ -137,6 +137,7 @@ const CASH_FLOW_ACCOUNTS = {
|
||||
CASH_FLOW_ACCOUNTS: 'CASH_FLOW_ACCOUNTS',
|
||||
CASH_FLOW_TRANSACTIONS: 'CASH_FLOW_TRANSACTIONS',
|
||||
CASH_FLOW_TRANSACTION: 'CASH_FLOW_TRANSACTION',
|
||||
CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY: 'CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY'
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
Reference in New Issue
Block a user