mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
feat: add connect to bank dialog
This commit is contained in:
@@ -50,6 +50,7 @@ import InvoiceMailDialog from '@/containers/Sales/Invoices/InvoiceMailDialog/Inv
|
|||||||
import EstimateMailDialog from '@/containers/Sales/Estimates/EstimateMailDialog/EstimateMailDialog';
|
import EstimateMailDialog from '@/containers/Sales/Estimates/EstimateMailDialog/EstimateMailDialog';
|
||||||
import ReceiptMailDialog from '@/containers/Sales/Receipts/ReceiptMailDialog/ReceiptMailDialog';
|
import ReceiptMailDialog from '@/containers/Sales/Receipts/ReceiptMailDialog/ReceiptMailDialog';
|
||||||
import PaymentMailDialog from '@/containers/Sales/PaymentReceives/PaymentMailDialog/PaymentMailDialog';
|
import PaymentMailDialog from '@/containers/Sales/PaymentReceives/PaymentMailDialog/PaymentMailDialog';
|
||||||
|
import { ConnectBankDialog } from '@/containers/CashFlow/ConnectBankDialog';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dialogs container.
|
* Dialogs container.
|
||||||
@@ -146,6 +147,7 @@ export default function DialogsContainer() {
|
|||||||
<EstimateMailDialog dialogName={DialogsName.EstimateMail} />
|
<EstimateMailDialog dialogName={DialogsName.EstimateMail} />
|
||||||
<ReceiptMailDialog dialogName={DialogsName.ReceiptMail} />
|
<ReceiptMailDialog dialogName={DialogsName.ReceiptMail} />
|
||||||
<PaymentMailDialog dialogName={DialogsName.PaymentMail} />
|
<PaymentMailDialog dialogName={DialogsName.PaymentMail} />
|
||||||
|
<ConnectBankDialog dialogName={DialogsName.ConnectBankCreditCard} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,4 +53,5 @@ export enum DialogsName {
|
|||||||
EstimateMail = 'estimate-mail',
|
EstimateMail = 'estimate-mail',
|
||||||
ReceiptMail = 'receipt-mail',
|
ReceiptMail = 'receipt-mail',
|
||||||
PaymentMail = 'payment-mail',
|
PaymentMail = 'payment-mail',
|
||||||
|
ConnectBankCreditCard = 'connect-bank-credit-card'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// @ts-nocheck
|
||||||
|
import { usePlaidExchangeToken } from '@/hooks/query';
|
||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
usePlaidLink,
|
usePlaidLink,
|
||||||
@@ -30,6 +32,8 @@ export function LaunchLink(props: LaunchLinkProps) {
|
|||||||
// const { generateLinkToken, deleteLinkToken } = useLink();
|
// const { generateLinkToken, deleteLinkToken } = useLink();
|
||||||
// const { setError, resetError } = useErrors();
|
// const { setError, resetError } = useErrors();
|
||||||
|
|
||||||
|
const { mutateAsync: exchangeAccessToken } = usePlaidExchangeToken();
|
||||||
|
|
||||||
// define onSuccess, onExit and onEvent functions as configs for Plaid Link creation
|
// define onSuccess, onExit and onEvent functions as configs for Plaid Link creation
|
||||||
const onSuccess = async (
|
const onSuccess = async (
|
||||||
publicToken: string,
|
publicToken: string,
|
||||||
@@ -45,6 +49,12 @@ export function LaunchLink(props: LaunchLinkProps) {
|
|||||||
// regular link mode: exchange public token for access token
|
// regular link mode: exchange public token for access token
|
||||||
} else {
|
} else {
|
||||||
// call to Plaid api endpoint: /item/public_token/exchange in order to obtain access_token which is then stored with the created item
|
// call to Plaid api endpoint: /item/public_token/exchange in order to obtain access_token which is then stored with the created item
|
||||||
|
debugger;
|
||||||
|
|
||||||
|
await exchangeAccessToken({
|
||||||
|
public_token: publicToken,
|
||||||
|
institution_id: metadata.institution.institution_id,
|
||||||
|
});
|
||||||
// await exchangeToken(
|
// await exchangeToken(
|
||||||
// publicToken,
|
// publicToken,
|
||||||
// metadata.institution,
|
// metadata.institution,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React, { useState } from 'react';
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
NavbarGroup,
|
NavbarGroup,
|
||||||
@@ -14,10 +13,7 @@ import {
|
|||||||
Icon,
|
Icon,
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import {
|
import { useRefreshCashflowAccounts } from '@/hooks/query';
|
||||||
useGetPlaidLinkToken,
|
|
||||||
useRefreshCashflowAccounts,
|
|
||||||
} from '@/hooks/query';
|
|
||||||
import { CashflowAction, AbilitySubject } from '@/constants/abilityOption';
|
import { CashflowAction, AbilitySubject } from '@/constants/abilityOption';
|
||||||
|
|
||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
@@ -29,7 +25,6 @@ import { ACCOUNT_TYPE } from '@/constants';
|
|||||||
import { DialogsName } from '@/constants/dialogs';
|
import { DialogsName } from '@/constants/dialogs';
|
||||||
|
|
||||||
import { compose } from '@/utils';
|
import { compose } from '@/utils';
|
||||||
import { LaunchLink } from '@/containers/Banking/Plaid/PlaidLanchLink';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cash Flow accounts actions bar.
|
* Cash Flow accounts actions bar.
|
||||||
@@ -66,21 +61,13 @@ function CashFlowAccountsActionsBar({
|
|||||||
const checked = event.target.checked;
|
const checked = event.target.checked;
|
||||||
setCashflowAccountsTableState({ inactiveMode: checked });
|
setCashflowAccountsTableState({ inactiveMode: checked });
|
||||||
};
|
};
|
||||||
|
// Handle connect button click.
|
||||||
const { mutateAsync: getPlaidLinkToken } = useGetPlaidLinkToken();
|
|
||||||
const [linkToken, setLinkToken] = useState<string>('');
|
|
||||||
|
|
||||||
const handleConnectToBank = () => {
|
const handleConnectToBank = () => {
|
||||||
getPlaidLinkToken()
|
openDialog(DialogsName.ConnectBankCreditCard);
|
||||||
.then((res) => {
|
|
||||||
setLinkToken(res.data.link_token);
|
|
||||||
})
|
|
||||||
.catch(() => {});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardActionsBar>
|
<DashboardActionsBar>
|
||||||
<LaunchLink userId={3} token={linkToken} />
|
|
||||||
<NavbarGroup>
|
<NavbarGroup>
|
||||||
<Can I={CashflowAction.Create} a={AbilitySubject.Cashflow}>
|
<Can I={CashflowAction.Create} a={AbilitySubject.Cashflow}>
|
||||||
<Button
|
<Button
|
||||||
@@ -120,15 +107,15 @@ function CashFlowAccountsActionsBar({
|
|||||||
onChange={handleInactiveSwitchChange}
|
onChange={handleInactiveSwitchChange}
|
||||||
/>
|
/>
|
||||||
</Can>
|
</Can>
|
||||||
|
|
||||||
<Button
|
|
||||||
className={Classes.MINIMAL}
|
|
||||||
text={'Connect to Bank'}
|
|
||||||
onClick={handleConnectToBank}
|
|
||||||
/>
|
|
||||||
</NavbarGroup>
|
</NavbarGroup>
|
||||||
|
|
||||||
<NavbarGroup align={Alignment.RIGHT}>
|
<NavbarGroup align={Alignment.RIGHT}>
|
||||||
|
<Button
|
||||||
|
className={Classes.MINIMAL}
|
||||||
|
text={'Connect to Bank / Credit Card'}
|
||||||
|
onClick={handleConnectToBank}
|
||||||
|
/>
|
||||||
|
<NavbarDivider />
|
||||||
<Button
|
<Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
icon={<Icon icon="refresh-16" iconSize={14} />}
|
icon={<Icon icon="refresh-16" iconSize={14} />}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { CashFlowAccountsProvider } from './CashFlowAccountsProvider';
|
|||||||
|
|
||||||
import CashflowAccountsGrid from './CashflowAccountsGrid';
|
import CashflowAccountsGrid from './CashflowAccountsGrid';
|
||||||
import CashFlowAccountsActionsBar from './CashFlowAccountsActionsBar';
|
import CashFlowAccountsActionsBar from './CashFlowAccountsActionsBar';
|
||||||
|
import { CashflowAccountsPlaidLink } from './CashflowAccountsPlaidLink';
|
||||||
|
|
||||||
import withCashflowAccounts from '@/containers/CashFlow/AccountTransactions/withCashflowAccounts';
|
import withCashflowAccounts from '@/containers/CashFlow/AccountTransactions/withCashflowAccounts';
|
||||||
import withCashflowAccountsTableActions from '@/containers/CashFlow/AccountTransactions/withCashflowAccountsTableActions';
|
import withCashflowAccountsTableActions from '@/containers/CashFlow/AccountTransactions/withCashflowAccountsTableActions';
|
||||||
@@ -38,6 +39,8 @@ function CashFlowAccountsList({
|
|||||||
<DashboardPageContent>
|
<DashboardPageContent>
|
||||||
<CashflowAccountsGrid />
|
<CashflowAccountsGrid />
|
||||||
</DashboardPageContent>
|
</DashboardPageContent>
|
||||||
|
|
||||||
|
<CashflowAccountsPlaidLink />
|
||||||
</CashFlowAccountsProvider>
|
</CashFlowAccountsProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ function CashflowBankAccount({
|
|||||||
// #withAlertsDialog
|
// #withAlertsDialog
|
||||||
openAlert,
|
openAlert,
|
||||||
|
|
||||||
// #withDial
|
// #withDialog
|
||||||
openDialog,
|
openDialog,
|
||||||
|
|
||||||
// #withDrawerActions
|
// #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';
|
||||||
@@ -5,7 +5,7 @@ import useApiRequest from '../useRequest';
|
|||||||
/**
|
/**
|
||||||
* Retrieves the plaid link token.
|
* Retrieves the plaid link token.
|
||||||
*/
|
*/
|
||||||
export function useGetPlaidLinkToken(props) {
|
export function useGetPlaidLinkToken(props = {}) {
|
||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
@@ -15,3 +15,17 @@ export function useGetPlaidLinkToken(props) {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the plaid link token.
|
||||||
|
*/
|
||||||
|
export function usePlaidExchangeToken(props = {}) {
|
||||||
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
|
return useMutation(
|
||||||
|
(data) => apiRequest.post('banking/plaid/exchange-token', data, {}),
|
||||||
|
{
|
||||||
|
...props,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
20
packages/webapp/src/hooks/state/banking.ts
Normal file
20
packages/webapp/src/hooks/state/banking.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { getPlaidToken, setPlaidId } from '@/store/banking/banking.reducer';
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
|
|
||||||
|
export const useSetBankingPlaidToken = () => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
return useCallback(
|
||||||
|
(plaidId: string) => {
|
||||||
|
dispatch(setPlaidId(plaidId));
|
||||||
|
},
|
||||||
|
[dispatch],
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useGetBankingPlaidToken = () => {
|
||||||
|
const plaidToken = useSelector(getPlaidToken);
|
||||||
|
|
||||||
|
return plaidToken;
|
||||||
|
};
|
||||||
20
packages/webapp/src/store/banking/banking.reducer.ts
Normal file
20
packages/webapp/src/store/banking/banking.reducer.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { PayloadAction, createSlice } from '@reduxjs/toolkit';
|
||||||
|
|
||||||
|
interface StorePlaidState {
|
||||||
|
plaidToken: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PlaidSlice = createSlice({
|
||||||
|
name: 'plaid',
|
||||||
|
initialState: {
|
||||||
|
plaidToken: '',
|
||||||
|
} as StorePlaidState,
|
||||||
|
reducers: {
|
||||||
|
setPlaidId: (state: StorePlaidState, action: PayloadAction<string>) => {
|
||||||
|
state.plaidToken = action.payload;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const { setPlaidId } = PlaidSlice.actions;
|
||||||
|
export const getPlaidToken = (state: any) => state.plaid.plaidToken;
|
||||||
@@ -37,6 +37,7 @@ import creditNotes from './CreditNote/creditNote.reducer';
|
|||||||
import vendorCredit from './VendorCredit/VendorCredit.reducer';
|
import vendorCredit from './VendorCredit/VendorCredit.reducer';
|
||||||
import warehouseTransfers from './WarehouseTransfer/warehouseTransfer.reducer';
|
import warehouseTransfers from './WarehouseTransfer/warehouseTransfer.reducer';
|
||||||
import projects from './Project/projects.reducer';
|
import projects from './Project/projects.reducer';
|
||||||
|
import { PlaidSlice } from './banking/banking.reducer';
|
||||||
|
|
||||||
const appReducer = combineReducers({
|
const appReducer = combineReducers({
|
||||||
authentication,
|
authentication,
|
||||||
@@ -73,6 +74,7 @@ const appReducer = combineReducers({
|
|||||||
vendorCredit,
|
vendorCredit,
|
||||||
warehouseTransfers,
|
warehouseTransfers,
|
||||||
projects,
|
projects,
|
||||||
|
plaid: PlaidSlice.reducer,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reset the state of a redux store
|
// Reset the state of a redux store
|
||||||
|
|||||||
Reference in New Issue
Block a user