mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
feat: invlidate cashflow queries after mutate assocaited queries.
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
|||||||
DashboardRowsHeightButton,
|
DashboardRowsHeightButton,
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
} from 'components';
|
} from 'components';
|
||||||
|
import { useRefreshCashflowTransactionsInfinity } from 'hooks/query';
|
||||||
|
|
||||||
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||||
import { CashFlowMenuItems } from './utils';
|
import { CashFlowMenuItems } from './utils';
|
||||||
@@ -46,7 +47,6 @@ function AccountTransactionsActionsBar({
|
|||||||
account_id: accountId,
|
account_id: accountId,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle money out form
|
// Handle money out form
|
||||||
const handlMoneyOutFormTransaction = (account) => {
|
const handlMoneyOutFormTransaction = (account) => {
|
||||||
openDialog('money-out', {
|
openDialog('money-out', {
|
||||||
@@ -54,8 +54,13 @@ function AccountTransactionsActionsBar({
|
|||||||
account_id: accountId,
|
account_id: accountId,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
// Refresh cashflow infinity transactions hook.
|
||||||
|
const { refresh } = useRefreshCashflowTransactionsInfinity();
|
||||||
|
|
||||||
const handleRefreshBtnClick = () => {};
|
// Handle the refresh button click.
|
||||||
|
const handleRefreshBtnClick = () => {
|
||||||
|
refresh();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardActionsBar>
|
<DashboardActionsBar>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import styled from 'styled-components';
|
|||||||
|
|
||||||
import 'style/pages/CashFlow/AccountTransactions/List.scss';
|
import 'style/pages/CashFlow/AccountTransactions/List.scss';
|
||||||
|
|
||||||
import { DashboardPageContent, DashboardContentTable } from 'components';
|
import { DashboardPageContent } from 'components';
|
||||||
|
|
||||||
import { AccountTransactionsProvider } from './AccountTransactionsProvider';
|
import { AccountTransactionsProvider } from './AccountTransactionsProvider';
|
||||||
import AccountTransactionsActionsBar from './AccountTransactionsActionsBar';
|
import AccountTransactionsActionsBar from './AccountTransactionsActionsBar';
|
||||||
|
|||||||
@@ -30,10 +30,12 @@ function AccountTransactionsProvider({ query, ...props }) {
|
|||||||
isSuccess: isCashflowTransactionsSuccess,
|
isSuccess: isCashflowTransactionsSuccess,
|
||||||
fetchNextPage: fetchNextTransactionsPage,
|
fetchNextPage: fetchNextTransactionsPage,
|
||||||
isFetchingNextPage,
|
isFetchingNextPage,
|
||||||
|
hasNextPage
|
||||||
} = useAccountTransactionsInfinity(accountId, {
|
} = useAccountTransactionsInfinity(accountId, {
|
||||||
page_size: 50,
|
page_size: 50,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Memorized the cashflow account transactions.
|
||||||
const cashflowTransactions = React.useMemo(
|
const cashflowTransactions = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
isCashflowTransactionsSuccess
|
isCashflowTransactionsSuccess
|
||||||
@@ -56,11 +58,12 @@ function AccountTransactionsProvider({ query, ...props }) {
|
|||||||
isLoading: isCurrentAccountLoading,
|
isLoading: isCurrentAccountLoading,
|
||||||
} = useAccount(accountId, { keepPreviousData: true });
|
} = useAccount(accountId, { keepPreviousData: true });
|
||||||
|
|
||||||
|
// Handle the observer ineraction.
|
||||||
const handleObserverInteract = React.useCallback(() => {
|
const handleObserverInteract = React.useCallback(() => {
|
||||||
if (!isFetchingNextPage) {
|
if (!isFetchingNextPage && hasNextPage) {
|
||||||
fetchNextTransactionsPage();
|
fetchNextTransactionsPage();
|
||||||
}
|
}
|
||||||
}, [isFetchingNextPage, fetchNextTransactionsPage]);
|
}, [isFetchingNextPage, hasNextPage, fetchNextTransactionsPage]);
|
||||||
|
|
||||||
// Provider payload.
|
// Provider payload.
|
||||||
const provider = {
|
const provider = {
|
||||||
@@ -81,7 +84,7 @@ function AccountTransactionsProvider({ query, ...props }) {
|
|||||||
<AccountTransactionsContext.Provider value={provider} {...props} />
|
<AccountTransactionsContext.Provider value={provider} {...props} />
|
||||||
<IntersectionObserver
|
<IntersectionObserver
|
||||||
onIntersect={handleObserverInteract}
|
onIntersect={handleObserverInteract}
|
||||||
// enabled={!isFetchingNextPage}
|
enabled={!isFetchingNextPage}
|
||||||
/>
|
/>
|
||||||
</DashboardInsider>
|
</DashboardInsider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,15 +7,12 @@ import {
|
|||||||
Alignment,
|
Alignment,
|
||||||
Switch,
|
Switch,
|
||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import {
|
import { Icon, FormattedMessage as T } from 'components';
|
||||||
Icon,
|
import { useRefreshCashflowAccounts } from 'hooks/query';
|
||||||
FormattedMessage as T,
|
|
||||||
} from 'components';
|
|
||||||
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||||
|
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
import withSettings from '../../Settings/withSettings';
|
|
||||||
import withSettingsActions from '../../Settings/withSettingsActions';
|
|
||||||
import withCashflowAccountsTableActions from '../AccountTransactions/withCashflowAccountsTableActions';
|
import withCashflowAccountsTableActions from '../AccountTransactions/withCashflowAccountsTableActions';
|
||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
@@ -27,22 +24,15 @@ function CashFlowAccountsActionsBar({
|
|||||||
// #withDialogActions
|
// #withDialogActions
|
||||||
openDialog,
|
openDialog,
|
||||||
|
|
||||||
// #withSettings
|
// #withCashflowAccountsTableActions
|
||||||
cashflowTableSize,
|
setCashflowAccountsTableState,
|
||||||
|
|
||||||
// #withSettingsActions
|
|
||||||
addSetting,
|
|
||||||
|
|
||||||
// #
|
|
||||||
setCashflowAccountsTableState
|
|
||||||
}) {
|
}) {
|
||||||
// Handle table row size change.
|
const { refresh } = useRefreshCashflowAccounts();
|
||||||
const handleTableRowSizeChange = (size) => {
|
|
||||||
addSetting('cashflowAccounts', 'tableSize', size);
|
|
||||||
};
|
|
||||||
// Handle click a refresh
|
|
||||||
const handleRefreshBtnClick = () => {};
|
|
||||||
|
|
||||||
|
// Handle refresh button click.
|
||||||
|
const handleRefreshBtnClick = () => {
|
||||||
|
refresh();
|
||||||
|
};
|
||||||
// Handle add bank account.
|
// Handle add bank account.
|
||||||
const handleAddBankAccount = () => {
|
const handleAddBankAccount = () => {
|
||||||
openDialog('account-form', {});
|
openDialog('account-form', {});
|
||||||
@@ -89,7 +79,7 @@ function CashFlowAccountsActionsBar({
|
|||||||
text={<T id={'import'} />}
|
text={<T id={'import'} />}
|
||||||
/>
|
/>
|
||||||
<NavbarDivider />
|
<NavbarDivider />
|
||||||
|
|
||||||
<Switch
|
<Switch
|
||||||
labelElement={<T id={'inactive'} />}
|
labelElement={<T id={'inactive'} />}
|
||||||
defaultChecked={false}
|
defaultChecked={false}
|
||||||
@@ -108,9 +98,5 @@ function CashFlowAccountsActionsBar({
|
|||||||
}
|
}
|
||||||
export default compose(
|
export default compose(
|
||||||
withDialogActions,
|
withDialogActions,
|
||||||
withSettingsActions,
|
|
||||||
withSettings(({ cashflowSettings }) => ({
|
|
||||||
cashflowTableSize: cashflowSettings?.tableSize,
|
|
||||||
})),
|
|
||||||
withCashflowAccountsTableActions,
|
withCashflowAccountsTableActions,
|
||||||
)(CashFlowAccountsActionsBar);
|
)(CashFlowAccountsActionsBar);
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ const commonInvalidateQueries = (query) => {
|
|||||||
query.invalidateQueries(t.ACCOUNTS);
|
query.invalidateQueries(t.ACCOUNTS);
|
||||||
query.invalidateQueries(t.ACCOUNT);
|
query.invalidateQueries(t.ACCOUNT);
|
||||||
|
|
||||||
|
// Invalidate cashflow accounts.
|
||||||
|
query.invalidateQueries(t.CASH_FLOW_ACCOUNTS);
|
||||||
|
|
||||||
// Invalidate financial reports.
|
// Invalidate financial reports.
|
||||||
query.invalidateQueries(t.FINANCIAL_REPORT);
|
query.invalidateQueries(t.FINANCIAL_REPORT);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,19 @@ const commonInvalidateQueries = (queryClient) => {
|
|||||||
// Invalidate accounts.
|
// Invalidate accounts.
|
||||||
queryClient.invalidateQueries(t.ACCOUNTS);
|
queryClient.invalidateQueries(t.ACCOUNTS);
|
||||||
queryClient.invalidateQueries(t.ACCOUNT);
|
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.
|
* Retrieve account transactions list.
|
||||||
*/
|
*/
|
||||||
export function useCashflowTransactions(id, props) {
|
export function useCashflowTransactions(accountId, props) {
|
||||||
return useRequestQuery(
|
return useRequestQuery(
|
||||||
[t.CASH_FLOW_TRANSACTIONS, id],
|
[t.CASH_FLOW_TRANSACTIONS, accountId],
|
||||||
{ method: 'get', url: `cashflow/account/${id}/transactions` },
|
{ method: 'get', url: `cashflow/account/${accountId}/transactions` },
|
||||||
{
|
{
|
||||||
select: (res) => res.data.cashflow_transactions,
|
select: (res) => res.data.cashflow_transactions,
|
||||||
defaultData: [],
|
defaultData: [],
|
||||||
@@ -68,8 +80,6 @@ export function useDeleteCashflowTransaction(props) {
|
|||||||
|
|
||||||
return useMutation((id) => apiRequest.delete(`cashflow/transactions/${id}`), {
|
return useMutation((id) => apiRequest.delete(`cashflow/transactions/${id}`), {
|
||||||
onSuccess: (res, id) => {
|
onSuccess: (res, id) => {
|
||||||
queryClient.invalidateQueries([t.CASH_FLOW_TRANSACTION, id]);
|
|
||||||
|
|
||||||
// Invalidate queries.
|
// Invalidate queries.
|
||||||
commonInvalidateQueries(queryClient);
|
commonInvalidateQueries(queryClient);
|
||||||
},
|
},
|
||||||
@@ -92,7 +102,7 @@ export function useAccountTransactionsInfinity(
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useInfiniteQuery(
|
return useInfiniteQuery(
|
||||||
['CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY', accountId],
|
[t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY, accountId],
|
||||||
async ({ pageParam = 1 }) => {
|
async ({ pageParam = 1 }) => {
|
||||||
const response = await apiRequest.http({
|
const response = await apiRequest.http({
|
||||||
...axios,
|
...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.
|
// Invalidate financial reports.
|
||||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
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) => ({
|
const transformExpenses = (response) => ({
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ const commonInvalidateQueries = (client) => {
|
|||||||
|
|
||||||
// Invalidate financial reports.
|
// Invalidate financial reports.
|
||||||
client.invalidateQueries(t.FINANCIAL_REPORT);
|
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.
|
// Invalidate vendors.
|
||||||
client.invalidateQueries(t.VENDORS);
|
client.invalidateQueries(t.VENDORS);
|
||||||
client.invalidateQueries(t.VENDOR);
|
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.
|
// Invalidate customers.
|
||||||
client.invalidateQueries(t.CUSTOMERS);
|
client.invalidateQueries(t.CUSTOMERS);
|
||||||
client.invalidateQueries(t.CUSTOMER);
|
client.invalidateQueries(t.CUSTOMER);
|
||||||
|
|
||||||
|
// Invalidate the cashflow transactions.
|
||||||
|
client.invalidateQueries(t.CASH_FLOW_TRANSACTIONS);
|
||||||
|
client.invalidateQueries(t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Transform payment receives.
|
// Transform payment receives.
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ const CASH_FLOW_ACCOUNTS = {
|
|||||||
CASH_FLOW_ACCOUNTS: 'CASH_FLOW_ACCOUNTS',
|
CASH_FLOW_ACCOUNTS: 'CASH_FLOW_ACCOUNTS',
|
||||||
CASH_FLOW_TRANSACTIONS: 'CASH_FLOW_TRANSACTIONS',
|
CASH_FLOW_TRANSACTIONS: 'CASH_FLOW_TRANSACTIONS',
|
||||||
CASH_FLOW_TRANSACTION: 'CASH_FLOW_TRANSACTION',
|
CASH_FLOW_TRANSACTION: 'CASH_FLOW_TRANSACTION',
|
||||||
|
CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY: 'CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY'
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
Reference in New Issue
Block a user