mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: confimation dialog on disconnecting bank account
This commit is contained in:
@@ -40,13 +40,13 @@ import withSettingsActions from '@/containers/Settings/withSettingsActions';
|
||||
|
||||
import { compose } from '@/utils';
|
||||
import {
|
||||
useDisconnectBankAccount,
|
||||
useUpdateBankAccount,
|
||||
useExcludeUncategorizedTransactions,
|
||||
useUnexcludeUncategorizedTransactions,
|
||||
} from '@/hooks/query/bank-rules';
|
||||
import { withBanking } from '../withBanking';
|
||||
import withAlertActions from '@/containers/Alert/withAlertActions';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
|
||||
function AccountTransactionsActionsBar({
|
||||
// #withDialogActions
|
||||
@@ -71,7 +71,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.
|
||||
@@ -112,19 +111,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 = () => {
|
||||
@@ -301,7 +290,7 @@ function AccountTransactionsActionsBar({
|
||||
}}
|
||||
content={
|
||||
<Menu>
|
||||
<If condition={isSyncingOwner}>
|
||||
<If condition={isSyncingOwner && isFeedsActive}>
|
||||
<MenuItem
|
||||
onClick={handlePauseFeedsSyncing}
|
||||
text={'Pause bank feeds'}
|
||||
@@ -309,7 +298,7 @@ function AccountTransactionsActionsBar({
|
||||
<MenuDivider />
|
||||
</If>
|
||||
|
||||
<If condition={isSyncingOwner}>
|
||||
<If condition={isSyncingOwner && isFeedsActive}>
|
||||
<MenuItem
|
||||
onClick={handleResumeFeedsSyncing}
|
||||
text={'Resume bank feeds'}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
|
||||
import { AppToaster, FormattedMessage as T } from '@/components';
|
||||
|
||||
@@ -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'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Payment mail dialog.X
|
||||
*/
|
||||
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';
|
||||
@@ -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);
|
||||
Reference in New Issue
Block a user