feat: invlidate cashflow queries after mutate assocaited queries.

This commit is contained in:
a.bouhuolia
2021-10-25 13:09:28 +02:00
parent e94a386fe8
commit 3c49e8f57a
11 changed files with 101 additions and 38 deletions

View File

@@ -11,6 +11,7 @@ import {
DashboardRowsHeightButton,
FormattedMessage as T,
} from 'components';
import { useRefreshCashflowTransactionsInfinity } from 'hooks/query';
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
import { CashFlowMenuItems } from './utils';
@@ -46,7 +47,6 @@ function AccountTransactionsActionsBar({
account_id: accountId,
});
};
// Handle money out form
const handlMoneyOutFormTransaction = (account) => {
openDialog('money-out', {
@@ -54,8 +54,13 @@ function AccountTransactionsActionsBar({
account_id: accountId,
});
};
// Refresh cashflow infinity transactions hook.
const { refresh } = useRefreshCashflowTransactionsInfinity();
const handleRefreshBtnClick = () => {};
// Handle the refresh button click.
const handleRefreshBtnClick = () => {
refresh();
};
return (
<DashboardActionsBar>

View File

@@ -3,7 +3,7 @@ import styled from 'styled-components';
import 'style/pages/CashFlow/AccountTransactions/List.scss';
import { DashboardPageContent, DashboardContentTable } from 'components';
import { DashboardPageContent } from 'components';
import { AccountTransactionsProvider } from './AccountTransactionsProvider';
import AccountTransactionsActionsBar from './AccountTransactionsActionsBar';

View File

@@ -30,10 +30,12 @@ function AccountTransactionsProvider({ query, ...props }) {
isSuccess: isCashflowTransactionsSuccess,
fetchNextPage: fetchNextTransactionsPage,
isFetchingNextPage,
hasNextPage
} = useAccountTransactionsInfinity(accountId, {
page_size: 50,
});
// Memorized the cashflow account transactions.
const cashflowTransactions = React.useMemo(
() =>
isCashflowTransactionsSuccess
@@ -56,11 +58,12 @@ function AccountTransactionsProvider({ query, ...props }) {
isLoading: isCurrentAccountLoading,
} = useAccount(accountId, { keepPreviousData: true });
// Handle the observer ineraction.
const handleObserverInteract = React.useCallback(() => {
if (!isFetchingNextPage) {
if (!isFetchingNextPage && hasNextPage) {
fetchNextTransactionsPage();
}
}, [isFetchingNextPage, fetchNextTransactionsPage]);
}, [isFetchingNextPage, hasNextPage, fetchNextTransactionsPage]);
// Provider payload.
const provider = {
@@ -81,7 +84,7 @@ function AccountTransactionsProvider({ query, ...props }) {
<AccountTransactionsContext.Provider value={provider} {...props} />
<IntersectionObserver
onIntersect={handleObserverInteract}
// enabled={!isFetchingNextPage}
enabled={!isFetchingNextPage}
/>
</DashboardInsider>
);