mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: add connect to bank dialog
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
// @ts-nocheck
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Button,
|
||||
NavbarGroup,
|
||||
@@ -14,10 +13,7 @@ import {
|
||||
Icon,
|
||||
FormattedMessage as T,
|
||||
} from '@/components';
|
||||
import {
|
||||
useGetPlaidLinkToken,
|
||||
useRefreshCashflowAccounts,
|
||||
} from '@/hooks/query';
|
||||
import { useRefreshCashflowAccounts } from '@/hooks/query';
|
||||
import { CashflowAction, AbilitySubject } from '@/constants/abilityOption';
|
||||
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
@@ -29,7 +25,6 @@ import { ACCOUNT_TYPE } from '@/constants';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
|
||||
import { compose } from '@/utils';
|
||||
import { LaunchLink } from '@/containers/Banking/Plaid/PlaidLanchLink';
|
||||
|
||||
/**
|
||||
* Cash Flow accounts actions bar.
|
||||
@@ -66,21 +61,13 @@ function CashFlowAccountsActionsBar({
|
||||
const checked = event.target.checked;
|
||||
setCashflowAccountsTableState({ inactiveMode: checked });
|
||||
};
|
||||
|
||||
const { mutateAsync: getPlaidLinkToken } = useGetPlaidLinkToken();
|
||||
const [linkToken, setLinkToken] = useState<string>('');
|
||||
|
||||
// Handle connect button click.
|
||||
const handleConnectToBank = () => {
|
||||
getPlaidLinkToken()
|
||||
.then((res) => {
|
||||
setLinkToken(res.data.link_token);
|
||||
})
|
||||
.catch(() => {});
|
||||
openDialog(DialogsName.ConnectBankCreditCard);
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<LaunchLink userId={3} token={linkToken} />
|
||||
<NavbarGroup>
|
||||
<Can I={CashflowAction.Create} a={AbilitySubject.Cashflow}>
|
||||
<Button
|
||||
@@ -120,15 +107,15 @@ function CashFlowAccountsActionsBar({
|
||||
onChange={handleInactiveSwitchChange}
|
||||
/>
|
||||
</Can>
|
||||
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
text={'Connect to Bank'}
|
||||
onClick={handleConnectToBank}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
|
||||
<NavbarGroup align={Alignment.RIGHT}>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
text={'Connect to Bank / Credit Card'}
|
||||
onClick={handleConnectToBank}
|
||||
/>
|
||||
<NavbarDivider />
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="refresh-16" iconSize={14} />}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { CashFlowAccountsProvider } from './CashFlowAccountsProvider';
|
||||
|
||||
import CashflowAccountsGrid from './CashflowAccountsGrid';
|
||||
import CashFlowAccountsActionsBar from './CashFlowAccountsActionsBar';
|
||||
import { CashflowAccountsPlaidLink } from './CashflowAccountsPlaidLink';
|
||||
|
||||
import withCashflowAccounts from '@/containers/CashFlow/AccountTransactions/withCashflowAccounts';
|
||||
import withCashflowAccountsTableActions from '@/containers/CashFlow/AccountTransactions/withCashflowAccountsTableActions';
|
||||
@@ -38,6 +39,8 @@ function CashFlowAccountsList({
|
||||
<DashboardPageContent>
|
||||
<CashflowAccountsGrid />
|
||||
</DashboardPageContent>
|
||||
|
||||
<CashflowAccountsPlaidLink />
|
||||
</CashFlowAccountsProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ function CashflowBankAccount({
|
||||
// #withAlertsDialog
|
||||
openAlert,
|
||||
|
||||
// #withDial
|
||||
// #withDialog
|
||||
openDialog,
|
||||
|
||||
// #withDrawerActions
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { LaunchLink } from '@/containers/Banking/Plaid/PlaidLanchLink';
|
||||
import { useGetBankingPlaidToken } from '@/hooks/state/banking';
|
||||
|
||||
export function CashflowAccountsPlaidLink() {
|
||||
const plaidToken = useGetBankingPlaidToken();
|
||||
|
||||
return <LaunchLink userId={3} token={plaidToken} />;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Dialog, DialogSuspense } from '@/components';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
const ConnectBankDialogBody = React.lazy(
|
||||
() => import('./ConnectBankDialogBody'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Connect bank dialog.
|
||||
*/
|
||||
function ConnectBankDialogRoot({ dialogName, payload = {}, isOpen }) {
|
||||
return (
|
||||
<Dialog
|
||||
name={dialogName}
|
||||
title={'Securly connect your bank or credit card.'}
|
||||
isOpen={isOpen}
|
||||
canEscapeJeyClose={true}
|
||||
autoFocus={true}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<ConnectBankDialogBody dialogName={dialogName} />
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export const ConnectBankDialog = compose(withDialogRedux())(
|
||||
ConnectBankDialogRoot,
|
||||
);
|
||||
@@ -0,0 +1,60 @@
|
||||
// @ts-nocheck
|
||||
import * as R from 'ramda';
|
||||
import { Form, Formik, FormikHelpers } from 'formik';
|
||||
import classNames from 'classnames';
|
||||
import { ConnectBankDialogContent } from './ConnectBankDialogContent';
|
||||
import { useGetPlaidLinkToken } from '@/hooks/query';
|
||||
import { useSetBankingPlaidToken } from '@/hooks/state/banking';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { CLASSES } from '@/constants';
|
||||
import { AppToaster } from '@/components';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
|
||||
const initialValues: ConnectBankDialogForm = {
|
||||
serviceProvider: 'plaid',
|
||||
};
|
||||
|
||||
interface ConnectBankDialogForm {
|
||||
serviceProvider: 'plaid';
|
||||
}
|
||||
|
||||
function ConnectBankDialogBodyRoot({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const { mutateAsync: getPlaidLinkToken } = useGetPlaidLinkToken();
|
||||
const setPlaidId = useSetBankingPlaidToken();
|
||||
|
||||
const handleSubmit = (
|
||||
values: ConnectBankDialogForm,
|
||||
{ setSubmitting }: FormikHelpers<ConnectBankDialogForm>,
|
||||
) => {
|
||||
setSubmitting(true);
|
||||
getPlaidLinkToken()
|
||||
.then((res) => {
|
||||
setSubmitting(false);
|
||||
closeDialog(DialogsName.ConnectBankCreditCard);
|
||||
setPlaidId(res.data.link_token);
|
||||
})
|
||||
.catch(() => {
|
||||
setSubmitting(false);
|
||||
AppToaster.show({
|
||||
message: 'Something went wrong.',
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={classNames(CLASSES.DIALOG_BODY)}>
|
||||
<Formik initialValues={initialValues} onSubmit={handleSubmit}>
|
||||
<Form>
|
||||
<ConnectBankDialogContent />
|
||||
</Form>
|
||||
</Formik>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default R.compose(withDialogActions)(ConnectBankDialogBodyRoot);
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Button } from '@blueprintjs/core';
|
||||
import { FFormGroup, FSelect } from '@/components';
|
||||
import { useFormikContext } from 'formik';
|
||||
|
||||
export function ConnectBankDialogContent() {
|
||||
const { isSubmitting } = useFormikContext();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<FFormGroup
|
||||
label={'Banking Syncing Service Provider'}
|
||||
name={'serviceProvider'}
|
||||
>
|
||||
<FSelect
|
||||
name={'serviceProvider'}
|
||||
valueAccessor={'key'}
|
||||
textAccessor={'label'}
|
||||
popoverProps={{ minimal: true }}
|
||||
items={BankFeedsServiceProviders}
|
||||
/>
|
||||
</FFormGroup>
|
||||
|
||||
<Button type={'submit'} loading={isSubmitting}>
|
||||
Connect
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const BankFeedsServiceProviders = [{ label: 'Plaid', key: 'plaid' }];
|
||||
@@ -0,0 +1 @@
|
||||
export * from './ConnectBankDialog';
|
||||
Reference in New Issue
Block a user