feat: Uncategorize bank transactions in bulk

This commit is contained in:
Ahmed Bouhuolia
2024-08-11 13:02:38 +02:00
parent be8352654e
commit 35a061d188
5 changed files with 77 additions and 2 deletions

View File

@@ -64,6 +64,7 @@ function AccountTransactionsActionsBar({
uncategorizedTransationsIdsSelected, uncategorizedTransationsIdsSelected,
excludedTransactionsIdsSelected, excludedTransactionsIdsSelected,
openMatchingTransactionAside, openMatchingTransactionAside,
categorizedTransactionsSelected,
// #withBankingActions // #withBankingActions
enableMultipleCategorization, enableMultipleCategorization,
@@ -194,7 +195,7 @@ function AccountTransactionsActionsBar({
// Handle multi select transactions for categorization or matching. // Handle multi select transactions for categorization or matching.
const handleMultipleCategorizingSwitch = (event) => { const handleMultipleCategorizingSwitch = (event) => {
enableMultipleCategorization(event.currentTarget.checked); enableMultipleCategorization(event.currentTarget.checked);
} };
// Handle resume bank feeds syncing. // Handle resume bank feeds syncing.
const handleResumeFeedsSyncing = () => { const handleResumeFeedsSyncing = () => {
openAlert('resume-feeds-syncing-bank-accounnt', { openAlert('resume-feeds-syncing-bank-accounnt', {
@@ -208,6 +209,9 @@ function AccountTransactionsActionsBar({
}); });
}; };
// Handles uncategorize the categorized transactions in bulk.
const handleUncategorizeCategorizedBulkBtnClick = () => {};
return ( return (
<DashboardActionsBar> <DashboardActionsBar>
<NavbarGroup> <NavbarGroup>
@@ -297,6 +301,14 @@ function AccountTransactionsActionsBar({
disabled={isUnexcludingLoading} disabled={isUnexcludingLoading}
/> />
)} )}
{!isEmpty(categorizedTransactionsSelected) && (
<Button
text={'Uncategorize'}
onClick={handleUncategorizeCategorizedBulkBtnClick}
intent={Intent.DANGER}
minimal
/>
)}
</NavbarGroup> </NavbarGroup>
<NavbarGroup align={Alignment.RIGHT}> <NavbarGroup align={Alignment.RIGHT}>
@@ -379,10 +391,12 @@ export default compose(
uncategorizedTransationsIdsSelected, uncategorizedTransationsIdsSelected,
excludedTransactionsIdsSelected, excludedTransactionsIdsSelected,
openMatchingTransactionAside, openMatchingTransactionAside,
categorizedTransactionsSelected,
}) => ({ }) => ({
uncategorizedTransationsIdsSelected, uncategorizedTransationsIdsSelected,
excludedTransactionsIdsSelected, excludedTransactionsIdsSelected,
openMatchingTransactionAside, openMatchingTransactionAside,
categorizedTransactionsSelected,
}), }),
), ),
withBankingActions, withBankingActions,

View File

@@ -22,10 +22,11 @@ import { useMemorizedColumnsWidths } from '@/hooks';
import { useAccountTransactionsColumns, ActionsMenu } from './components'; import { useAccountTransactionsColumns, ActionsMenu } from './components';
import { useAccountTransactionsAllContext } from './AccountTransactionsAllBoot'; import { useAccountTransactionsAllContext } from './AccountTransactionsAllBoot';
import { useUnmatchMatchedUncategorizedTransaction } from '@/hooks/query/bank-rules'; import { useUnmatchMatchedUncategorizedTransaction } from '@/hooks/query/bank-rules';
import { useUncategorizeTransaction } from '@/hooks/query';
import { handleCashFlowTransactionType } from './utils'; import { handleCashFlowTransactionType } from './utils';
import { compose } from '@/utils'; import { compose } from '@/utils';
import { useUncategorizeTransaction } from '@/hooks/query'; import { withBankingActions } from '../withBankingActions';
/** /**
* Account transactions data table. * Account transactions data table.
@@ -39,6 +40,9 @@ function AccountTransactionsDataTable({
// #withDrawerActions // #withDrawerActions
openDrawer, openDrawer,
// #withBankingActions
setCategorizedTransactionsSelected,
}) { }) {
// Retrieve table columns. // Retrieve table columns.
const columns = useAccountTransactionsColumns(); const columns = useAccountTransactionsColumns();
@@ -97,6 +101,14 @@ function AccountTransactionsDataTable({
}); });
}; };
// Handle selected rows change.
const handleSelectedRowsChange = (selected) => {
const selectedIds = selected?.map(
(row) => row.original.uncategorized_transaction_id,
);
setCategorizedTransactionsSelected(selectedIds);
};
return ( return (
<CashflowTransactionsTable <CashflowTransactionsTable
noInitialFetch={true} noInitialFetch={true}
@@ -119,6 +131,8 @@ function AccountTransactionsDataTable({
vListOverscanRowCount={0} vListOverscanRowCount={0}
initialColumnsWidths={initialColumnsWidths} initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing} onColumnResizing={handleColumnResizing}
selectionColumn={true}
onSelectedRowsChange={handleSelectedRowsChange}
noResults={<T id={'cash_flow.account_transactions.no_results'} />} noResults={<T id={'cash_flow.account_transactions.no_results'} />}
className="table-constrant" className="table-constrant"
payload={{ payload={{
@@ -136,6 +150,7 @@ export default compose(
})), })),
withAlertsActions, withAlertsActions,
withDrawerActions, withDrawerActions,
withBankingActions,
)(AccountTransactionsDataTable); )(AccountTransactionsDataTable);
const DashboardConstrantTable = styled(DataTable)` const DashboardConstrantTable = styled(DataTable)`

View File

@@ -22,6 +22,9 @@ export const withBanking = (mapState) => {
transactionsToCategorizeIdsSelected: transactionsToCategorizeIdsSelected:
state.plaid.transactionsToCategorizeSelected, state.plaid.transactionsToCategorizeSelected,
categorizedTransactionsSelected:
state.plaid.categorizedTransactionsSelected,
}; };
return mapState ? mapState(mapped, state, props) : mapped; return mapState ? mapState(mapped, state, props) : mapped;
}; };

View File

@@ -13,6 +13,8 @@ import {
enableMultipleCategorization, enableMultipleCategorization,
addTransactionsToCategorizeSelected, addTransactionsToCategorizeSelected,
removeTransactionsToCategorizeSelected, removeTransactionsToCategorizeSelected,
setCategorizedTransactionsSelected,
resetCategorizedTransactionsSelected,
} from '@/store/banking/banking.reducer'; } from '@/store/banking/banking.reducer';
export interface WithBankingActionsProps { export interface WithBankingActionsProps {
@@ -35,6 +37,9 @@ export interface WithBankingActionsProps {
resetTransactionsToCategorizeSelected: () => void; resetTransactionsToCategorizeSelected: () => void;
enableMultipleCategorization: (enable: boolean) => void; enableMultipleCategorization: (enable: boolean) => void;
setCategorizedTransactionsSelected: (ids: Array<string | number>) => void;
resetCategorizedTransactionsSelected: () => void;
} }
const mapDipatchToProps = (dispatch: any): WithBankingActionsProps => ({ const mapDipatchToProps = (dispatch: any): WithBankingActionsProps => ({
@@ -120,6 +125,19 @@ const mapDipatchToProps = (dispatch: any): WithBankingActionsProps => ({
*/ */
enableMultipleCategorization: (enable: boolean) => enableMultipleCategorization: (enable: boolean) =>
dispatch(enableMultipleCategorization({ enable })), dispatch(enableMultipleCategorization({ enable })),
/**
* Sets the selected ids of the categorized transactions.
* @param {Array<string | number>} ids
*/
setCategorizedTransactionsSelected: (ids: Array<string | number>) =>
dispatch(setCategorizedTransactionsSelected({ ids })),
/**
* Resets the selected categorized transcations.
*/
resetCategorizedTransactionsSelected: () =>
dispatch(resetCategorizedTransactionsSelected()),
}); });
export const withBankingActions = connect< export const withBankingActions = connect<

View File

@@ -12,6 +12,8 @@ interface StorePlaidState {
transactionsToCategorizeSelected: Array<number | string>; transactionsToCategorizeSelected: Array<number | string>;
enableMultipleCategorization: boolean; enableMultipleCategorization: boolean;
categorizedTransactionsSelected: Array<number | string>;
} }
export const PlaidSlice = createSlice({ export const PlaidSlice = createSlice({
@@ -28,6 +30,7 @@ export const PlaidSlice = createSlice({
excludedTransactionsSelected: [], excludedTransactionsSelected: [],
transactionsToCategorizeSelected: [], transactionsToCategorizeSelected: [],
enableMultipleCategorization: false, enableMultipleCategorization: false,
categorizedTransactionsSelected: [],
} as StorePlaidState, } as StorePlaidState,
reducers: { reducers: {
setPlaidId: (state: StorePlaidState, action: PayloadAction<string>) => { setPlaidId: (state: StorePlaidState, action: PayloadAction<string>) => {
@@ -176,6 +179,26 @@ export const PlaidSlice = createSlice({
) => { ) => {
state.enableMultipleCategorization = action.payload.enable; state.enableMultipleCategorization = action.payload.enable;
}, },
/**
* Sets the selected ids of the categorized transactions.
* @param {StorePlaidState}
* @param {PayloadAction<{ ids: Array<string | number> }>}
*/
setCategorizedTransactionsSelected: (
state: StorePlaidState,
action: PayloadAction<{ ids: Array<string | number> }>,
) => {
state.categorizedTransactionsSelected = action.payload.ids;
},
/**
* Resets the selected categorized transcations.
* @param {StorePlaidState}
*/
resetCategorizedTransactionsSelected: (state: StorePlaidState) => {
state.categorizedTransactionsSelected = [];
},
}, },
}); });
@@ -195,6 +218,8 @@ export const {
removeTransactionsToCategorizeSelected, removeTransactionsToCategorizeSelected,
resetTransactionsToCategorizeSelected, resetTransactionsToCategorizeSelected,
enableMultipleCategorization, enableMultipleCategorization,
setCategorizedTransactionsSelected,
resetCategorizedTransactionsSelected,
} = PlaidSlice.actions; } = PlaidSlice.actions;
export const getPlaidToken = (state: any) => state.plaid.plaidToken; export const getPlaidToken = (state: any) => state.plaid.plaidToken;