feat: alert messages of pause.resume bank feeds

This commit is contained in:
Ahmed Bouhuolia
2024-08-04 16:05:35 +02:00
parent 208800b411
commit b84675325f
6 changed files with 62 additions and 24 deletions

View File

@@ -2,6 +2,8 @@ import { Inject, Service } from 'typedi';
import { Knex } from 'knex'; import { Knex } from 'knex';
import HasTenancyService from '@/services/Tenancy/TenancyService'; import HasTenancyService from '@/services/Tenancy/TenancyService';
import UnitOfWork from '@/services/UnitOfWork'; import UnitOfWork from '@/services/UnitOfWork';
import { ServiceError } from '@/exceptions';
import { ERRORS } from './types';
@Service() @Service()
export class PauseBankAccountFeeds { export class PauseBankAccountFeeds {
@@ -22,10 +24,19 @@ export class PauseBankAccountFeeds {
const oldAccount = await Account.query() const oldAccount = await Account.query()
.findById(bankAccountId) .findById(bankAccountId)
.withGraphFetched('plaidItem'); .withGraphFetched('plaidItem')
.throwIfNotFound();
// Can't continue if the bank account is not connected.
if (!oldAccount.plaidItem) {
throw new ServiceError(ERRORS.BANK_ACCOUNT_NOT_CONNECTED);
}
// Cannot continue if the bank account feeds is already paused.
if (oldAccount.plaidItem.isPaused) {
throw new ServiceError(ERRORS.BANK_ACCOUNT_FEEDS_ALREADY_PAUSED);
}
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => { return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
await PlaidItem.query().findById(oldAccount.plaidItem.id).patch({ await PlaidItem.query(trx).findById(oldAccount.plaidItem.id).patch({
pausedAt: null, pausedAt: null,
}); });
}); });

View File

@@ -1,6 +1,9 @@
import { Inject, Service } from 'typedi';
import { Knex } from 'knex';
import HasTenancyService from '@/services/Tenancy/TenancyService'; import HasTenancyService from '@/services/Tenancy/TenancyService';
import UnitOfWork from '@/services/UnitOfWork'; import UnitOfWork from '@/services/UnitOfWork';
import { Inject, Service } from 'typedi'; import { ServiceError } from '@/exceptions';
import { ERRORS } from './types';
@Service() @Service()
export class ResumeBankAccountFeeds { export class ResumeBankAccountFeeds {
@@ -23,8 +26,16 @@ export class ResumeBankAccountFeeds {
.findById(bankAccountId) .findById(bankAccountId)
.withGraphFetched('plaidItem'); .withGraphFetched('plaidItem');
// Can't continue if the bank account is not connected.
if (!oldAccount.plaidItem) {
throw new ServiceError(ERRORS.BANK_ACCOUNT_NOT_CONNECTED);
}
// Cannot continue if the bank account feeds is already paused.
if (!oldAccount.plaidItem.isPaused) {
throw new ServiceError(ERRORS.BANK_ACCOUNT_FEEDS_ALREADY_RESUMED);
}
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => { return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
await PlaidItem.query().findById(oldAccount.plaidItem.id).patch({ await PlaidItem.query(trx).findById(oldAccount.plaidItem.id).patch({
pausedAt: new Date(), pausedAt: new Date(),
}); });
}); });

View File

@@ -14,4 +14,6 @@ export interface IBankAccountDisconnectedEventPayload {
export const ERRORS = { export const ERRORS = {
BANK_ACCOUNT_NOT_CONNECTED: 'BANK_ACCOUNT_NOT_CONNECTED', BANK_ACCOUNT_NOT_CONNECTED: 'BANK_ACCOUNT_NOT_CONNECTED',
BANK_ACCOUNT_FEEDS_ALREADY_PAUSED: 'BANK_ACCOUNT_FEEDS_ALREADY_PAUSED',
BANK_ACCOUNT_FEEDS_ALREADY_RESUMED: 'BANK_ACCOUNT_FEEDS_ALREADY_RESUMED',
}; };

View File

@@ -197,12 +197,15 @@ function AccountTransactionsActionsBar({
// Handle resume bank feeds syncing. // Handle resume bank feeds syncing.
const handleResumeFeedsSyncing = () => { const handleResumeFeedsSyncing = () => {
openAlert('resume-feeds-syncing-bank-accounnt'); openAlert('resume-feeds-syncing-bank-accounnt', {
bankAccountId: accountId,
});
}; };
// Handles pause bank feeds syncing. // Handles pause bank feeds syncing.
const handlePauseFeedsSyncing = () => { const handlePauseFeedsSyncing = () => {
openAlert('pause-feeds-syncing-bank-accounnt'); openAlert('pause-feeds-syncing-bank-accounnt', {
bankAccountId: accountId,
});
}; };
return ( return (
@@ -298,14 +301,21 @@ function AccountTransactionsActionsBar({
}} }}
content={ content={
<Menu> <Menu>
<MenuItem <If condition={isSyncingOwner}>
onClick={handlePauseFeedsSyncing} <MenuItem
text={'Pause bankfeeds syncing'} onClick={handlePauseFeedsSyncing}
/> text={'Pause bank feeds'}
<MenuItem />
onClick={handleResumeFeedsSyncing} <MenuDivider />
text={'Resume bankfeeds syncing'} </If>
/>
<If condition={isSyncingOwner}>
<MenuItem
onClick={handleResumeFeedsSyncing}
text={'Resume bank feeds'}
/>
<MenuDivider />
</If>
<If condition={isSyncingOwner && isFeedsActive}> <If condition={isSyncingOwner && isFeedsActive}>
<MenuItem onClick={handleBankUpdateClick} text={'Update'} /> <MenuItem onClick={handleBankUpdateClick} text={'Update'} />

View File

@@ -1,6 +1,5 @@
// @ts-nocheck // @ts-nocheck
import React from 'react'; import React from 'react';
import intl from 'react-intl-universal';
import { Intent, Alert } from '@blueprintjs/core'; import { Intent, Alert } from '@blueprintjs/core';
import { AppToaster, FormattedMessage as T } from '@/components'; import { AppToaster, FormattedMessage as T } from '@/components';
@@ -30,10 +29,9 @@ function PauseFeedsBankAccountAlert({
const handleCancelActivateItem = () => { const handleCancelActivateItem = () => {
closeAlert(name); closeAlert(name);
}; };
// Handle confirm item activated. // Handle confirm item activated.
const handleConfirmItemActivate = () => { const handleConfirmItemActivate = () => {
pauseBankAccountFeeds(bankAccountId) pauseBankAccountFeeds({ bankAccountId })
.then(() => { .then(() => {
AppToaster.show({ AppToaster.show({
message: 'The bank feeds of the bank account has been paused.', message: 'The bank feeds of the bank account has been paused.',
@@ -49,14 +47,17 @@ function PauseFeedsBankAccountAlert({
return ( return (
<Alert <Alert
cancelButtonText={<T id={'cancel'} />} cancelButtonText={<T id={'cancel'} />}
confirmButtonText={<T id={'activate'} />} confirmButtonText={'Pause bank feeds'}
intent={Intent.WARNING} intent={Intent.WARNING}
isOpen={isOpen} isOpen={isOpen}
onCancel={handleCancelActivateItem} onCancel={handleCancelActivateItem}
loading={isLoading} loading={isLoading}
onConfirm={handleConfirmItemActivate} onConfirm={handleConfirmItemActivate}
> >
<p>Are you sure.</p> <p>
Are you sure want to pause bank feeds syncing of this bank account, you
can always resume it again?
</p>
</Alert> </Alert>
); );
} }

View File

@@ -33,7 +33,7 @@ function ResumeFeedsBankAccountAlert({
// Handle confirm item activated. // Handle confirm item activated.
const handleConfirmItemActivate = () => { const handleConfirmItemActivate = () => {
resumeFeedsBankAccount(bankAccountId) resumeFeedsBankAccount({ bankAccountId })
.then(() => { .then(() => {
AppToaster.show({ AppToaster.show({
message: 'The bank feeds of the bank account has been resumed.', message: 'The bank feeds of the bank account has been resumed.',
@@ -49,14 +49,17 @@ function ResumeFeedsBankAccountAlert({
return ( return (
<Alert <Alert
cancelButtonText={<T id={'cancel'} />} cancelButtonText={<T id={'cancel'} />}
confirmButtonText={<T id={'activate'} />} confirmButtonText={'Resume bank feeds'}
intent={Intent.WARNING} intent={Intent.SUCCESS}
isOpen={isOpen} isOpen={isOpen}
onCancel={handleCancelActivateItem} onCancel={handleCancelActivateItem}
loading={isLoading} loading={isLoading}
onConfirm={handleConfirmItemActivate} onConfirm={handleConfirmItemActivate}
> >
<p>Are you sure.</p> <p>
Are you sure want to resume bank feeds syncing of this bank account, you
can always pause it again?
</p>
</Alert> </Alert>
); );
} }