mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat: wip multipe transactions categorization
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
// @ts-nocheck
|
||||
import { isEmpty } from 'lodash';
|
||||
import * as R from 'ramda';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useState, useMemo } from 'react';
|
||||
import { uniq } from 'lodash';
|
||||
import { AnchorButton, Button, Intent, Tag, Text } from '@blueprintjs/core';
|
||||
import { FastField, FastFieldProps, Formik, useFormikContext } from 'formik';
|
||||
import { AppToaster, Box, FormatNumber, Group, Stack } from '@/components';
|
||||
@@ -25,9 +26,9 @@ import {
|
||||
WithBankingActionsProps,
|
||||
withBankingActions,
|
||||
} from '../withBankingActions';
|
||||
import styles from './CategorizeTransactionAside.module.scss';
|
||||
import { MatchingReconcileTransactionForm } from './MatchingReconcileTransactionAside/MatchingReconcileTransactionForm';
|
||||
import { withBanking } from '../withBanking';
|
||||
import { MatchingReconcileTransactionForm } from './MatchingReconcileTransactionAside/MatchingReconcileTransactionForm';
|
||||
import styles from './CategorizeTransactionAside.module.scss';
|
||||
|
||||
const initialValues = {
|
||||
matched: {},
|
||||
@@ -40,10 +41,22 @@ const initialValues = {
|
||||
function MatchingBankTransactionRoot({
|
||||
// #withBankingActions
|
||||
closeMatchingTransactionAside,
|
||||
|
||||
// #withBanking
|
||||
transactionsToCategorizeIdsSelected,
|
||||
}) {
|
||||
const { uncategorizedTransactionId } = useCategorizeTransactionTabsBoot();
|
||||
const { mutateAsync: matchTransaction } = useMatchUncategorizedTransaction();
|
||||
|
||||
const selectedTransactionsIds = useMemo(
|
||||
() =>
|
||||
uniq([
|
||||
...transactionsToCategorizeIdsSelected,
|
||||
uncategorizedTransactionId,
|
||||
]),
|
||||
[uncategorizedTransactionId, transactionsToCategorizeIdsSelected],
|
||||
);
|
||||
|
||||
// Handles the form submitting.
|
||||
const handleSubmit = (
|
||||
values: MatchingTransactionFormValues,
|
||||
@@ -91,7 +104,7 @@ function MatchingBankTransactionRoot({
|
||||
|
||||
return (
|
||||
<MatchingTransactionBoot
|
||||
uncategorizedTransactionId={uncategorizedTransactionId}
|
||||
uncategorizedTransactionsIds={selectedTransactionsIds}
|
||||
>
|
||||
<Formik initialValues={initialValues} onSubmit={handleSubmit}>
|
||||
<MatchingBankTransactionFormContent />
|
||||
@@ -100,9 +113,12 @@ function MatchingBankTransactionRoot({
|
||||
);
|
||||
}
|
||||
|
||||
export const MatchingBankTransaction = R.compose(withBankingActions)(
|
||||
MatchingBankTransactionRoot,
|
||||
);
|
||||
export const MatchingBankTransaction = R.compose(
|
||||
withBankingActions,
|
||||
withBanking(({ transactionsToCategorizeIdsSelected }) => ({
|
||||
transactionsToCategorizeIdsSelected,
|
||||
})),
|
||||
)(MatchingBankTransactionRoot);
|
||||
|
||||
/**
|
||||
* Matching bank transaction form content.
|
||||
|
||||
@@ -18,12 +18,12 @@ const RuleFormBootContext = createContext<MatchingTransactionBootValues>(
|
||||
);
|
||||
|
||||
interface RuleFormBootProps {
|
||||
uncategorizedTransactionId: number;
|
||||
uncategorizedTransactionsIds: Array<number>;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
function MatchingTransactionBoot({
|
||||
uncategorizedTransactionId,
|
||||
uncategorizedTransactionsIds,
|
||||
...props
|
||||
}: RuleFormBootProps) {
|
||||
const {
|
||||
@@ -31,7 +31,7 @@ function MatchingTransactionBoot({
|
||||
isLoading: isMatchingTransactionsLoading,
|
||||
isFetching: isMatchingTransactionsFetching,
|
||||
isSuccess: isMatchingTransactionsSuccess,
|
||||
} = useGetBankTransactionsMatches(uncategorizedTransactionId);
|
||||
} = useGetBankTransactionsMatches(uncategorizedTransactionsIds);
|
||||
|
||||
const possibleMatches = defaultTo(matchingTransactions?.possibleMatches, []);
|
||||
const perfectMatchesCount = matchingTransactions?.perfectMatches?.length || 0;
|
||||
|
||||
@@ -19,6 +19,9 @@ export const withBanking = (mapState) => {
|
||||
|
||||
excludedTransactionsIdsSelected: state.plaid.excludedTransactionsSelected,
|
||||
isMultipleCategorization: state.plaid.isMultipleCategorization,
|
||||
|
||||
transactionsToCategorizeIdsSelected:
|
||||
state.plaid.transactionsToCategorizeSelected,
|
||||
};
|
||||
return mapState ? mapState(mapped, state, props) : mapped;
|
||||
};
|
||||
|
||||
@@ -168,7 +168,9 @@ export function useBankRule(
|
||||
);
|
||||
}
|
||||
|
||||
type GetBankTransactionsMatchesValue = number;
|
||||
interface GetBankTransactionsMatchesValue {
|
||||
uncategorizeTransactionsIds: Array<number>;
|
||||
}
|
||||
interface GetBankTransactionsMatchesResponse {
|
||||
perfectMatches: Array<any>;
|
||||
possibleMatches: Array<any>;
|
||||
@@ -180,16 +182,18 @@ interface GetBankTransactionsMatchesResponse {
|
||||
* @returns {UseQueryResult<GetBankTransactionsMatchesResponse, Error>}
|
||||
*/
|
||||
export function useGetBankTransactionsMatches(
|
||||
uncategorizedTransactionId: number,
|
||||
uncategorizeTransactionsIds: Array<number>,
|
||||
options?: UseQueryOptions<GetBankTransactionsMatchesResponse, Error>,
|
||||
): UseQueryResult<GetBankTransactionsMatchesResponse, Error> {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useQuery<GetBankTransactionsMatchesResponse, Error>(
|
||||
[QUERY_KEY.BANK_TRANSACTION_MATCHES, uncategorizedTransactionId],
|
||||
[QUERY_KEY.BANK_TRANSACTION_MATCHES, uncategorizeTransactionsIds],
|
||||
() =>
|
||||
apiRequest
|
||||
.get(`/cashflow/transactions/${uncategorizedTransactionId}/matches`)
|
||||
.get(`/cashflow/transactions/matches`, {
|
||||
params: { uncategorizeTransactionsIds },
|
||||
})
|
||||
.then((res) => transformToCamelCase(res.data)),
|
||||
options,
|
||||
);
|
||||
|
||||
@@ -195,3 +195,6 @@ export const getOpenMatchingTransactionAside = (state: any) =>
|
||||
|
||||
export const isMultipleCategorization = (state: any) =>
|
||||
state.plaid.enableMultipleCategorization;
|
||||
|
||||
export const getTransactionsToCategorizeIdsSelected = (state: any) =>
|
||||
state.plaid.transactionsToCategorizeSelected;
|
||||
|
||||
Reference in New Issue
Block a user