Merge branch 'develop' into bulk-categorize-bank-transactions

This commit is contained in:
Ahmed Bouhuolia
2024-08-04 22:23:02 +02:00
committed by GitHub
29 changed files with 777 additions and 74 deletions

View File

@@ -41,13 +41,14 @@ import withSettingsActions from '@/containers/Settings/withSettingsActions';
import { compose } from '@/utils';
import {
useDisconnectBankAccount,
useUpdateBankAccount,
useExcludeUncategorizedTransactions,
useUnexcludeUncategorizedTransactions,
} from '@/hooks/query/bank-rules';
import { withBankingActions } from '../withBankingActions';
import { withBanking } from '../withBanking';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { DialogsName } from '@/constants/dialogs';
function AccountTransactionsActionsBar({
// #withDialogActions
@@ -66,6 +67,9 @@ function AccountTransactionsActionsBar({
// #withBankingActions
enableMultipleCategorization,
// #withAlerts
openAlert,
}) {
const history = useHistory();
const { accountId, currentAccount } = useAccountTransactionsContext();
@@ -73,7 +77,6 @@ function AccountTransactionsActionsBar({
// Refresh cashflow infinity transactions hook.
const { refresh } = useRefreshCashflowTransactionsInfinity();
const { mutateAsync: disconnectBankAccount } = useDisconnectBankAccount();
const { mutateAsync: updateBankAccount } = useUpdateBankAccount();
// Retrieves the money in/out buttons options.
@@ -81,6 +84,7 @@ function AccountTransactionsActionsBar({
const addMoneyOutOptions = useMemo(() => getAddMoneyOutOptions(), []);
const isFeedsActive = !!currentAccount.is_feeds_active;
const isFeedsPaused = currentAccount.is_feeds_paused;
const isSyncingOwner = currentAccount.is_syncing_owner;
// Handle table row size change.
@@ -114,19 +118,9 @@ function AccountTransactionsActionsBar({
// Handles the bank account disconnect click.
const handleDisconnectClick = () => {
disconnectBankAccount({ bankAccountId: accountId })
.then(() => {
AppToaster.show({
message: 'The bank account has been disconnected.',
intent: Intent.SUCCESS,
});
})
.catch((error) => {
AppToaster.show({
message: 'Something went wrong.',
intent: Intent.DANGER,
});
});
openDialog(DialogsName.DisconnectBankAccountConfirmation, {
bankAccountId: accountId,
});
};
// handles the bank update button click.
const handleBankUpdateClick = () => {
@@ -197,8 +191,21 @@ function AccountTransactionsActionsBar({
});
};
// Handle multi select transactions for categorization or matching.
const handleMultipleCategorizingSwitch = (event) => {
enableMultipleCategorization(event.currentTarget.checked);
}
// Handle resume bank feeds syncing.
const handleResumeFeedsSyncing = () => {
openAlert('resume-feeds-syncing-bank-accounnt', {
bankAccountId: accountId,
});
};
// Handles pause bank feeds syncing.
const handlePauseFeedsSyncing = () => {
openAlert('pause-feeds-syncing-bank-accounnt', {
bankAccountId: accountId,
});
};
return (
@@ -248,7 +255,9 @@ function AccountTransactionsActionsBar({
<Tooltip
content={
isFeedsActive
? 'The bank syncing is active'
? isFeedsPaused
? 'The bank syncing is paused'
: 'The bank syncing is active'
: 'The bank syncing is disconnected'
}
minimal={true}
@@ -257,7 +266,13 @@ function AccountTransactionsActionsBar({
<Button
className={Classes.MINIMAL}
icon={<Icon icon="feed" iconSize={16} />}
intent={isFeedsActive ? Intent.SUCCESS : Intent.DANGER}
intent={
isFeedsActive
? isFeedsPaused
? Intent.WARNING
: Intent.SUCCESS
: Intent.DANGER
}
/>
</Tooltip>
</If>
@@ -314,6 +329,23 @@ function AccountTransactionsActionsBar({
<MenuItem onClick={handleBankUpdateClick} text={'Update'} />
<MenuDivider />
</If>
<If condition={isSyncingOwner && isFeedsActive && !isFeedsPaused}>
<MenuItem
onClick={handlePauseFeedsSyncing}
text={'Pause bank feeds'}
/>
<MenuDivider />
</If>
<If condition={isSyncingOwner && isFeedsActive && isFeedsPaused}>
<MenuItem
onClick={handleResumeFeedsSyncing}
text={'Resume bank feeds'}
/>
<MenuDivider />
</If>
<MenuItem onClick={handleBankRulesClick} text={'Bank rules'} />
<If condition={isSyncingOwner && isFeedsActive}>
@@ -337,6 +369,7 @@ function AccountTransactionsActionsBar({
export default compose(
withDialogActions,
withAlertActions,
withSettingsActions,
withSettings(({ cashflowTransactionsSettings }) => ({
cashflowTansactionsTableSize: cashflowTransactionsSettings?.tableSize,

View File

@@ -0,0 +1,68 @@
// @ts-nocheck
import React from 'react';
import { Intent, Alert } from '@blueprintjs/core';
import { AppToaster, FormattedMessage as T } from '@/components';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { usePauseFeedsBankAccount } from '@/hooks/query/bank-accounts';
import { compose } from '@/utils';
/**
* Pause feeds of the bank account alert.
*/
function PauseFeedsBankAccountAlert({
name,
// #withAlertStoreConnect
isOpen,
payload: { bankAccountId },
// #withAlertActions
closeAlert,
}) {
const { mutateAsync: pauseBankAccountFeeds, isLoading } =
usePauseFeedsBankAccount();
// Handle activate item alert cancel.
const handleCancelActivateItem = () => {
closeAlert(name);
};
// Handle confirm item activated.
const handleConfirmItemActivate = () => {
pauseBankAccountFeeds({ bankAccountId })
.then(() => {
AppToaster.show({
message: 'The bank feeds of the bank account has been paused.',
intent: Intent.SUCCESS,
});
})
.catch((error) => {})
.finally(() => {
closeAlert(name);
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={'Pause bank feeds'}
intent={Intent.WARNING}
isOpen={isOpen}
onCancel={handleCancelActivateItem}
loading={isLoading}
onConfirm={handleConfirmItemActivate}
>
<p>
Are you sure want to pause bank feeds syncing of this bank account, you
can always resume it again?
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(PauseFeedsBankAccountAlert);

View File

@@ -0,0 +1,69 @@
// @ts-nocheck
import React from 'react';
import { Intent, Alert } from '@blueprintjs/core';
import { AppToaster, FormattedMessage as T } from '@/components';
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
import withAlertActions from '@/containers/Alert/withAlertActions';
import { useResumeFeedsBankAccount } from '@/hooks/query/bank-accounts';
import { compose } from '@/utils';
/**
* Resume bank account feeds alert.
*/
function ResumeFeedsBankAccountAlert({
name,
// #withAlertStoreConnect
isOpen,
payload: { bankAccountId },
// #withAlertActions
closeAlert,
}) {
const { mutateAsync: resumeFeedsBankAccount, isLoading } =
useResumeFeedsBankAccount();
// Handle activate item alert cancel.
const handleCancelActivateItem = () => {
closeAlert(name);
};
// Handle confirm item activated.
const handleConfirmItemActivate = () => {
resumeFeedsBankAccount({ bankAccountId })
.then(() => {
AppToaster.show({
message: 'The bank feeds of the bank account has been resumed.',
intent: Intent.SUCCESS,
});
})
.catch((error) => {})
.finally(() => {
closeAlert(name);
});
};
return (
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={'Resume bank feeds'}
intent={Intent.SUCCESS}
isOpen={isOpen}
onCancel={handleCancelActivateItem}
loading={isLoading}
onConfirm={handleConfirmItemActivate}
>
<p>
Are you sure want to resume bank feeds syncing of this bank account, you
can always pause it again?
</p>
</Alert>
);
}
export default compose(
withAlertStoreConnect(),
withAlertActions,
)(ResumeFeedsBankAccountAlert);

View File

@@ -0,0 +1,24 @@
// @ts-nocheck
import React from 'react';
const ResumeFeedsBankAccountAlert = React.lazy(
() => import('./ResumeFeedsBankAccount'),
);
const PauseFeedsBankAccountAlert = React.lazy(
() => import('./PauseFeedsBankAccount'),
);
/**
* Bank account alerts.
*/
export const BankAccountAlerts = [
{
name: 'resume-feeds-syncing-bank-accounnt',
component: ResumeFeedsBankAccountAlert,
},
{
name: 'pause-feeds-syncing-bank-accounnt',
component: PauseFeedsBankAccountAlert,
},
];

View File

@@ -0,0 +1,42 @@
// @ts-nocheck
import React from 'react';
import { Dialog, DialogSuspense } from '@/components';
import withDialogRedux from '@/components/DialogReduxConnect';
import { compose } from '@/utils';
const DisconnectBankAccountDialogContent = React.lazy(
() => import('./DisconnectBankAccountDialogContent'),
);
/**
* Disconnect bank account confirmation dialog.
*/
function DisconnectBankAccountDialogRoot({
dialogName,
payload: { bankAccountId },
isOpen,
}) {
return (
<Dialog
name={dialogName}
title={'Disconnect Bank Account'}
isOpen={isOpen}
canEscapeJeyClose={true}
autoFocus={true}
style={{ width: 400 }}
>
<DialogSuspense>
<DisconnectBankAccountDialogContent
dialogName={dialogName}
bankAccountId={bankAccountId}
/>
</DialogSuspense>
</Dialog>
);
}
export const DisconnectBankAccountDialog = compose(withDialogRedux())(
DisconnectBankAccountDialogRoot,
);
DisconnectBankAccountDialog.displayName = 'DisconnectBankAccountDialog';

View File

@@ -0,0 +1,104 @@
// @ts-nocheck
import * as Yup from 'yup';
import { Button, Intent, Classes } from '@blueprintjs/core';
import * as R from 'ramda';
import { Form, Formik, FormikHelpers } from 'formik';
import { AppToaster, FFormGroup, FInputGroup } from '@/components';
import { useDisconnectBankAccount } from '@/hooks/query/bank-rules';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import { DialogsName } from '@/constants/dialogs';
interface DisconnectFormValues {
label: string;
}
const initialValues = {
label: '',
};
const Schema = Yup.object().shape({
label: Yup.string().required().label('Confirmation'),
});
interface DisconnectBankAccountDialogContentProps {
bankAccountId: number;
}
function DisconnectBankAccountDialogContent({
bankAccountId,
// #withDialogActions
closeDialog,
}: DisconnectBankAccountDialogContentProps) {
const { mutateAsync: disconnectBankAccount } = useDisconnectBankAccount();
const handleSubmit = (
values: DisconnectFormValues,
{ setErrors, setSubmitting }: FormikHelpers<DisconnectFormValues>,
) => {
debugger;
setSubmitting(true);
if (values.label !== 'DISCONNECT ACCOUNT') {
setErrors({
label: 'The entered value is incorrect.',
});
setSubmitting(false);
return;
}
disconnectBankAccount({ bankAccountId })
.then(() => {
setSubmitting(false);
AppToaster.show({
message: 'The bank account has been disconnected.',
intent: Intent.SUCCESS,
});
closeDialog(DialogsName.DisconnectBankAccountConfirmation);
})
.catch((error) => {
setSubmitting(false);
AppToaster.show({
message: 'Something went wrong.',
intent: Intent.DANGER,
});
});
};
const handleCancelBtnClick = () => {
closeDialog(DialogsName.DisconnectBankAccountConfirmation);
};
return (
<Formik
onSubmit={handleSubmit}
validationSchema={Schema}
initialValues={initialValues}
>
<Form>
<div className={Classes.DIALOG_BODY}>
<FFormGroup
label={`Type "DISCONNECT ACCOUNT"`}
name={'label'}
fastField
>
<FInputGroup name={'label'} fastField />
</FFormGroup>
</div>
<div className={Classes.DIALOG_FOOTER}>
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
<Button type="submit" intent={Intent.DANGER}>
Disconnect Bank Account
</Button>
<Button intent={Intent.NONE} onClick={handleCancelBtnClick}>
Cancel
</Button>
</div>
</div>
</Form>
</Formik>
);
}
export default R.compose(withDialogActions)(DisconnectBankAccountDialogContent);