@zeniai/client-epic-state 4.11.58 → 4.11.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/lib/entity/cardPayment/cardPaymentPayload.d.ts +2 -2
  2. package/lib/entity/cardPayment/cardPaymentPayload.js +14 -11
  3. package/lib/entity/chargeCardTransaction/chargeCardTransaction.d.ts +1 -1
  4. package/lib/entity/company/companyPayload.d.ts +12 -0
  5. package/lib/entity/company/companyPayload.js +21 -0
  6. package/lib/entity/company/companyReducer.d.ts +7 -0
  7. package/lib/entity/company/companyReducer.js +22 -2
  8. package/lib/entity/company/companyStateTypes.d.ts +12 -0
  9. package/lib/entity/depositAccountTransaction/depositAccountTransaction.d.ts +1 -1
  10. package/lib/entity/paymentAccount/paymentAccountPayload.d.ts +2 -0
  11. package/lib/entity/paymentAccount/paymentAccountPayload.js +2 -0
  12. package/lib/entity/paymentAccount/paymentAccountState.d.ts +2 -0
  13. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  14. package/lib/entity/snackbar/snackbarTypes.js +1 -0
  15. package/lib/entity/tenant/epic/fetchAllTenantsEpic.d.ts +3 -3
  16. package/lib/entity/tenant/epic/fetchAllTenantsEpic.js +16 -3
  17. package/lib/entity/toastNotification/epic/pushToastNotificationEpic.d.ts +1 -1
  18. package/lib/index.d.ts +11 -11
  19. package/lib/index.js +22 -18
  20. package/lib/view/bankAccountView/epic/createBankAccountEpic.js +5 -3
  21. package/lib/view/cardPayment/epic/addCardPaymentSourceEpic.d.ts +1 -1
  22. package/lib/view/cardPayment/epic/confirmCardSetupIntentEpic.d.ts +1 -1
  23. package/lib/view/cardPayment/epic/createCardSetupIntentEpic.d.ts +1 -1
  24. package/lib/view/cardPayment/epic/fetchPaymentSourcesEpic.d.ts +1 -1
  25. package/lib/view/companyView/types/cockpitTypes.d.ts +2 -2
  26. package/lib/view/onboardingView/customerView/epic/plaidConnection/establishOnboardingPlaidConnectionEpic.js +2 -0
  27. package/lib/view/people/changeZeniPersonRolesEpic.d.ts +1 -1
  28. package/lib/view/people/deletePersonEpic.d.ts +1 -1
  29. package/lib/view/people/invitePeopleEpic.d.ts +1 -1
  30. package/lib/view/people/inviteZeniPeopleEpic.d.ts +1 -1
  31. package/lib/view/people/resendInviteEpic.d.ts +1 -1
  32. package/lib/view/referralView/referralState.d.ts +1 -1
  33. package/lib/view/reviewCompanyView/reviewCompanyViewSelector.js +45 -41
  34. package/lib/view/scheduleView/scheduleListView/scheduleListTypes.d.ts +1 -1
  35. package/lib/view/settingsView/epic/fetchBankConnectionsViewEpic.d.ts +6 -4
  36. package/lib/view/settingsView/epic/fetchBankConnectionsViewEpic.js +29 -6
  37. package/lib/view/settingsView/epic/saveNotificationSettingsEpic.d.ts +1 -1
  38. package/lib/view/settingsView/settingsViewReducer.d.ts +3 -1
  39. package/lib/view/settingsView/settingsViewReducer.js +11 -2
  40. package/lib/view/settingsView/settingsViewSelector.d.ts +1 -1
  41. package/lib/view/settingsView/settingsViewSelector.js +59 -7
  42. package/lib/view/settingsView/types/settingsViewSelectorTypes.d.ts +10 -2
  43. package/lib/view/spendManagement/billPay/billPayReview/billPayReviewSelector.js +2 -3
  44. package/lib/view/spendManagement/billPay/billPaySetupView/billPaySetupViewSelector.js +1 -1
  45. package/lib/view/spendManagement/billPay/billPaySetupView/epic/billPaySetup/fetchBillPaySetupViewEpic.d.ts +4 -1
  46. package/lib/view/spendManagement/billPay/billPaySetupView/epic/billPaySetup/fetchBillPaySetupViewEpic.js +16 -4
  47. package/lib/view/spendManagement/billPay/billsBulkActionView/billsBulkActionViewReducer.js +1 -1
  48. package/lib/view/spendManagement/billPay/billsBulkActionView/billsBulkActionViewSelector.d.ts +3 -1
  49. package/lib/view/spendManagement/billPay/billsBulkActionView/billsBulkActionViewSelector.js +20 -3
  50. package/lib/view/spendManagement/billPay/billsBulkActionView/billsBulkActionViewState.d.ts +4 -1
  51. package/lib/view/spendManagement/billPay/billsBulkActionView/billsBulkActionViewState.js +18 -1
  52. package/lib/view/spendManagement/billPay/billsBulkActionView/epics/submitDraftBillsBulkActionEpic.js +25 -6
  53. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +15 -12
  54. package/lib/view/spendManagement/billPay/editBillView/epics/fetchEditBillDetailPageEpic.d.ts +2 -2
  55. package/lib/view/spendManagement/billPay/editBillView/epics/fetchEditBillDetailPageEpic.js +6 -6
  56. package/lib/view/spendManagement/billPay/editBillView/epics/initializeBillToLocalStoreEpic.d.ts +1 -2
  57. package/lib/view/spendManagement/chargeCards/chargeCardSetUp/chargeCardSetUpViewSelector.js +1 -1
  58. package/lib/view/spendManagement/chargeCards/chargeCardSetUp/epic/fetchChargeCardSetupViewEpic.d.ts +4 -1
  59. package/lib/view/spendManagement/chargeCards/chargeCardSetUp/epic/fetchChargeCardSetupViewEpic.js +16 -4
  60. package/lib/view/spendManagement/commonSetup/setupViewSelector.d.ts +4 -0
  61. package/lib/view/spendManagement/commonSetup/setupViewSelector.js +47 -31
  62. package/lib/view/spendManagement/plaidAccount/epic/paymentAccounts/updateMappedCashAccountEpic.js +4 -5
  63. package/lib/view/spendManagement/plaidAccount/epic/paymentAccounts/updatePaymentAccountEpic.js +1 -2
  64. package/lib/view/spendManagement/plaidAccount/epic/paymentAccounts/updatePaymentAccountStatusEpic.js +1 -2
  65. package/lib/view/spendManagement/plaidAccount/epic/paymentAccounts/updatePrimaryFundingAccountEpic.d.ts +2 -1
  66. package/lib/view/spendManagement/plaidAccount/epic/paymentAccounts/updatePrimaryFundingAccountEpic.js +59 -12
  67. package/lib/view/spendManagement/plaidAccount/epic/plaidConnection/establishPlaidConnectionEpic.d.ts +2 -1
  68. package/lib/view/spendManagement/plaidAccount/epic/plaidConnection/establishPlaidConnectionEpic.js +52 -16
  69. package/lib/view/spendManagement/plaidAccount/epic/plaidConnection/getPlaidLinkTokenEpic.js +1 -1
  70. package/lib/view/spendManagement/plaidAccount/plaidAccountViewReducer.d.ts +21 -27
  71. package/lib/view/spendManagement/plaidAccount/plaidAccountViewReducer.js +47 -74
  72. package/lib/view/spendManagement/plaidAccount/plaidAccountViewState.d.ts +3 -8
  73. package/lib/view/spendManagement/plaidAccount/plaidAccountViewState.js +6 -3
  74. package/lib/view/spendManagement/reimbursement/remiSetupView/epic/remiSetup/fetchRemiSetupViewEpic.js +6 -19
  75. package/lib/view/spendManagement/zeniAccounts/zeniAccountList/zeniAccountListSelector.js +2 -2
  76. package/lib/view/spendManagement/zeniAccounts/zeniAccountSetUp/epic/fetchZeniAccountSetupViewEpic.d.ts +4 -1
  77. package/lib/view/spendManagement/zeniAccounts/zeniAccountSetUp/epic/fetchZeniAccountSetupViewEpic.js +20 -9
  78. package/lib/view/spendManagement/zeniAccounts/zeniAccountSetUp/zeniAccountSetupViewSelector.js +1 -1
  79. package/lib/view/tagView/epics/createTagEpic.d.ts +6 -6
  80. package/lib/view/tagView/epics/deleteTagEpic.d.ts +6 -6
  81. package/package.json +2 -2
@@ -7,13 +7,10 @@ const responsePayload_1 = require("../../../../../responsePayload");
7
7
  const billTransactionReducer_1 = require("../../../../../entity/billPay/billTransaction/billTransactionReducer");
8
8
  const snackbarReducer_1 = require("../../../../../entity/snackbar/snackbarReducer");
9
9
  const billsBulkActionViewReducer_1 = require("../billsBulkActionViewReducer");
10
+ const editBillViewSelector_1 = require("../../editBillView/editBillViewSelector");
10
11
  const submitDraftBillsBulkActionEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(billsBulkActionViewReducer_1.submitDraftBillsBulkAction.match), (0, operators_1.mergeMap)(() => {
11
- const { billsBulkActionViewState } = state$.value;
12
- const transactionIds = billsBulkActionViewState.billsSelectedForBulkAction;
13
- const payload = {
14
- operation_type: 'send_for_approval',
15
- operations: transactionIds.map((id) => ({ entity_id: id })),
16
- };
12
+ const { billsBulkActionViewState, billTransactionState } = state$.value;
13
+ const payload = prepareBulkSubmitPayload(billsBulkActionViewState, billTransactionState);
17
14
  const bulkApiUrl = `${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/bulk/bills/transactions`;
18
15
  return zeniAPI
19
16
  .putAndGetJSON(bulkApiUrl, payload)
@@ -67,3 +64,25 @@ const submitDraftBillsBulkActionEpic = (actions$, state$, zeniAPI) => actions$.p
67
64
  JSON.stringify(error))))));
68
65
  }));
69
66
  exports.submitDraftBillsBulkActionEpic = submitDraftBillsBulkActionEpic;
67
+ function prepareBulkSubmitPayload(bulkActionState, transactionsState) {
68
+ const bulkDraftSubmitItems = bulkActionState.billsSelectedForBulkAction.map((id) => {
69
+ var _a, _b;
70
+ let itemPayload = {
71
+ entity_id: id,
72
+ };
73
+ if (((_b = (_a = bulkActionState.bulkReviewStateById[id]) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.code) ===
74
+ 'ERR_INVOICE_DATE_OUTSIDE_ACCOUNTING_PERIOD') {
75
+ const billTransaction = transactionsState.transactionById[id];
76
+ if (billTransaction != null) {
77
+ itemPayload = Object.assign(Object.assign({}, itemPayload), { request_data: {
78
+ transaction_date: (0, editBillViewSelector_1.getInvoiceDate)('draft', billTransaction.date, billTransaction.bookCloseDate).format('YYYY-MM-DD'),
79
+ } });
80
+ }
81
+ }
82
+ return itemPayload;
83
+ });
84
+ return {
85
+ operation_type: 'send_for_approval',
86
+ operations: bulkDraftSubmitItems,
87
+ };
88
+ }
@@ -32,7 +32,7 @@ const depositAccountSelector_1 = require("../../../../entity/depositAccount/depo
32
32
  const setupViewSelector_1 = require("../../commonSetup/setupViewSelector");
33
33
  const getEditBillDetail = (state, isVendorRecommendationFeatureEnabled, isZeniAccountsEnabled, billId) => {
34
34
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
35
- const { accountListState, accountState, bankAccountState, billDetailViewState, plaidAccountViewState, billTransactionState, billPayConfigState, classListState, classState, editBillDetailViewState, paymentAccountState, vendorState, tenantState, companyState, userState, commonHistoryState, contactState, paymentInstrumentState, recurringBillState, depositAccountListState, depositAccountState, } = state;
35
+ const { accountListState, accountState, bankAccountState, billDetailViewState, paymentAccountListState, billTransactionState, billPayConfigState, classListState, classState, editBillDetailViewState, paymentAccountState, vendorState, tenantState, companyState, userState, commonHistoryState, contactState, paymentInstrumentState, recurringBillState, depositAccountListState, depositAccountState, } = state;
36
36
  const transaction = (0, get_1.default)(billTransactionState.transactionById, billId !== null && billId !== void 0 ? billId : '', undefined);
37
37
  let recommendations = {};
38
38
  if (billId != null) {
@@ -61,17 +61,20 @@ const getEditBillDetail = (state, isVendorRecommendationFeatureEnabled, isZeniAc
61
61
  ? (_f = (_e = tenantState.tenantsById) === null || _e === void 0 ? void 0 : _e[currentTenantId]) === null || _f === void 0 ? void 0 : _f.companyId
62
62
  : undefined;
63
63
  const currentCompany = (0, companySelector_1.getCompanyByCompanyId)(companyState, companyId !== null && companyId !== void 0 ? companyId : '');
64
- const primaryPaymentAccount = (0, paymentAccountSelector_1.getPaymentAccountsByPaymentAccountIds)(paymentAccountState, (transaction === null || transaction === void 0 ? void 0 : transaction.billPayInfo.fromAccount.billAccountType) ===
65
- 'paymentAccount' &&
66
- (transaction === null || transaction === void 0 ? void 0 : transaction.billPayInfo.fromAccount.billAccountId) != null &&
67
- (transaction === null || transaction === void 0 ? void 0 : transaction.billPayInfo.fromAccount.billAccountId.length) > 0
68
- ? /*
69
- for extsing transaction since we are not calling payment accounts
70
- we need to pick payment ids from billPayInfo object
71
- */
72
- [transaction.billPayInfo.fromAccount.billAccountId]
73
- : plaidAccountViewState['spend_management_setup'].accountDetails
74
- .paymentAccountIds);
64
+ const primaryPaymentAccount = (0, paymentAccountSelector_1.getPaymentAccountsByPaymentAccountIds)(paymentAccountState, paymentAccountListState.paymentAccountIds);
65
+ const fromPaymentAccount = (transaction === null || transaction === void 0 ? void 0 : transaction.billPayInfo.fromAccount.billAccountType) === 'paymentAccount' &&
66
+ (transaction === null || transaction === void 0 ? void 0 : transaction.billPayInfo.fromAccount.billAccountId) != null
67
+ ? (0, paymentAccountSelector_1.getPaymentAccountsByPaymentAccountIds)(paymentAccountState, [
68
+ transaction.billPayInfo.fromAccount.billAccountId,
69
+ ])
70
+ : undefined;
71
+ // add the account received in the transaction fromAccount
72
+ // if its not already present in the payment account list
73
+ if (fromPaymentAccount != null &&
74
+ fromPaymentAccount.length > 0 &&
75
+ primaryPaymentAccount.some((account) => account.paymentAccountId === fromPaymentAccount[0].paymentAccountId) === false) {
76
+ primaryPaymentAccount.push(fromPaymentAccount[0]);
77
+ }
75
78
  const fromDepositAccount = (transaction === null || transaction === void 0 ? void 0 : transaction.billPayInfo.fromAccount.billAccountType) === 'depositAccount' &&
76
79
  (transaction === null || transaction === void 0 ? void 0 : transaction.billPayInfo.fromAccount.billAccountId) != null
77
80
  ? (0, depositAccountSelector_1.getDepositAccountByDepositAccountId)(depositAccountState, transaction === null || transaction === void 0 ? void 0 : transaction.billPayInfo.fromAccount.billAccountId)
@@ -4,11 +4,11 @@ import { fetchEditBillDetailPage, updateShowAutofill } from '../editBillViewRedu
4
4
  import { RootState } from '../../../../../reducer';
5
5
  import { fetchClassList } from '../../../../classList/classListReducer';
6
6
  import { fetchAccountList } from '../../../../accountList/accountListReducer';
7
- import { getPaymentAccounts } from '../../../plaidAccount/plaidAccountViewReducer';
8
7
  import { fetchBillPaySetupApproverView } from '../../billPaySetupApproverView/billPaySetupApproverViewReducer';
9
8
  import { fetchOwnerList } from '../../../../ownerList/ownerListReducer';
10
9
  import { fetchVendorTypeList } from '../../../../vendorTypeList/vendorTypeListReducer';
11
10
  import { fetchBillPayConfig } from '../../billPayConfig/billPayConfigReducer';
12
11
  import { fetchDepositAccountList } from '../../../zeniAccounts/depositAccountList/depositAccountListReducer';
13
- export declare type ActionType = ReturnType<typeof fetchEditBillDetailPage> | ReturnType<typeof fetchClassList> | ReturnType<typeof fetchVendorTypeList> | ReturnType<typeof fetchAccountList> | ReturnType<typeof getPaymentAccounts> | ReturnType<typeof fetchDepositAccountList> | ReturnType<typeof fetchBillPayConfig> | ReturnType<typeof updateShowAutofill> | ReturnType<typeof fetchBillPaySetupApproverView> | ReturnType<typeof fetchOwnerList>;
12
+ import { fetchPaymentAccountList } from '../../../zeniAccounts/paymentAccountList/paymentAccountListReducer';
13
+ export declare type ActionType = ReturnType<typeof fetchEditBillDetailPage> | ReturnType<typeof fetchClassList> | ReturnType<typeof fetchVendorTypeList> | ReturnType<typeof fetchAccountList> | ReturnType<typeof fetchPaymentAccountList> | ReturnType<typeof fetchDepositAccountList> | ReturnType<typeof fetchBillPayConfig> | ReturnType<typeof updateShowAutofill> | ReturnType<typeof fetchBillPaySetupApproverView> | ReturnType<typeof fetchOwnerList>;
14
14
  export declare const fetchEditBillDetailPageEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>) => Observable<ActionType>;
@@ -6,13 +6,13 @@ const operators_1 = require("rxjs/operators");
6
6
  const editBillViewReducer_1 = require("../editBillViewReducer");
7
7
  const classListReducer_1 = require("../../../../classList/classListReducer");
8
8
  const accountListReducer_1 = require("../../../../accountList/accountListReducer");
9
- const plaidAccountViewReducer_1 = require("../../../plaidAccount/plaidAccountViewReducer");
10
9
  const billPaySetupApproverViewReducer_1 = require("../../billPaySetupApproverView/billPaySetupApproverViewReducer");
11
10
  const ownerListReducer_1 = require("../../../../ownerList/ownerListReducer");
12
11
  const vendorTypeListReducer_1 = require("../../../../vendorTypeList/vendorTypeListReducer");
13
12
  const billPayConfigReducer_1 = require("../../billPayConfig/billPayConfigReducer");
14
13
  const depositAccountListReducer_1 = require("../../../zeniAccounts/depositAccountList/depositAccountListReducer");
15
14
  const companySelector_1 = require("../../../../../entity/company/companySelector");
15
+ const paymentAccountListReducer_1 = require("../../../zeniAccounts/paymentAccountList/paymentAccountListReducer");
16
16
  const fetchEditBillDetailPageEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)(editBillViewReducer_1.fetchEditBillDetailPage.match), (0, operators_1.mergeMap)((action) => {
17
17
  var _a, _b, _c;
18
18
  const { cacheOverride, billId, isShowDeletedBillsEnabled } = action.payload;
@@ -34,7 +34,7 @@ const fetchEditBillDetailPageEpic = (actions$, state$) => actions$.pipe((0, oper
34
34
  if (isCompanyZeniAccountsSetUpDone) {
35
35
  billDetailActions.push((0, depositAccountListReducer_1.fetchDepositAccountList)());
36
36
  }
37
- billDetailActions.push((0, plaidAccountViewReducer_1.getPaymentAccounts)('bill_pay', 'spend_management_setup'));
37
+ billDetailActions.push((0, paymentAccountListReducer_1.fetchPaymentAccountList)());
38
38
  if (billId != null) {
39
39
  billDetailActions.push((0, editBillViewReducer_1.fetchBillAndInitializeLocalStore)(billId, true, isShowDeletedBillsEnabled));
40
40
  }
@@ -73,10 +73,10 @@ const fetchEditBillDetailPageEpic = (actions$, state$) => actions$.pipe((0, oper
73
73
  depositAccounts.fetchState !== 'Completed') {
74
74
  billDetailActions.push((0, depositAccountListReducer_1.fetchDepositAccountList)());
75
75
  }
76
- const paymentAccount = state.plaidAccountViewState['spend_management_setup'].accountDetails;
77
- if (paymentAccount.fetchStatus.fetchState !== 'In-Progress' &&
78
- paymentAccount.fetchStatus.fetchState !== 'Completed') {
79
- billDetailActions.push((0, plaidAccountViewReducer_1.getPaymentAccounts)('bill_pay', 'spend_management_setup'));
76
+ const paymentAccounts = state.paymentAccountListState;
77
+ if (paymentAccounts.fetchState !== 'In-Progress' &&
78
+ paymentAccounts.fetchState !== 'Completed') {
79
+ billDetailActions.push((0, paymentAccountListReducer_1.fetchPaymentAccountList)());
80
80
  }
81
81
  if (billId != null) {
82
82
  billDetailActions.push((0, editBillViewReducer_1.fetchBillAndInitializeLocalStore)(billId, false, isShowDeletedBillsEnabled));
@@ -3,13 +3,12 @@ import { Observable } from 'rxjs';
3
3
  import { convertAmountToHomeCurrency, initializeBillToLocalStore, saveBillUpdatesToLocalStore, updateEditBillFetchStateCompleted } from '../editBillViewReducer';
4
4
  import { RootState } from '../../../../../reducer';
5
5
  import { fetchClassList } from '../../../../classList/classListReducer';
6
- import { getPaymentAccounts } from '../../../plaidAccount/plaidAccountViewReducer';
7
6
  import { LineItemRecommendationsLocalData } from '../editBillViewSelector';
8
7
  import { RecommendationByLineId } from '../../../../../entity/transaction/stateTypes/transaction';
9
8
  import { Vendor } from '../../../../../entity/vendor/vendorState';
10
9
  import { AccountListSelectorView } from '../../../../accountList/accountListSelector';
11
10
  import { ClassListSelectorView } from '../../../../classList/classListSelector';
12
11
  import Line from '../../../../../entity/transaction/stateTypes/transactionLine';
13
- export declare type ActionType = ReturnType<typeof initializeBillToLocalStore> | ReturnType<typeof saveBillUpdatesToLocalStore> | ReturnType<typeof fetchClassList> | ReturnType<typeof updateEditBillFetchStateCompleted> | ReturnType<typeof getPaymentAccounts> | ReturnType<typeof convertAmountToHomeCurrency>;
12
+ export declare type ActionType = ReturnType<typeof initializeBillToLocalStore> | ReturnType<typeof saveBillUpdatesToLocalStore> | ReturnType<typeof fetchClassList> | ReturnType<typeof updateEditBillFetchStateCompleted> | ReturnType<typeof convertAmountToHomeCurrency>;
14
13
  export declare const getLineRecommendationsLocalData: (lineId: string, line: Line, recommendations: RecommendationByLineId | undefined, accountList: AccountListSelectorView, classList: ClassListSelectorView, vendorDetails?: Vendor | undefined) => LineItemRecommendationsLocalData;
15
14
  export declare const initializeBillToLocalStoreEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>) => Observable<ActionType>;
@@ -5,7 +5,7 @@ const getCompanyView_1 = require("../../../companyView/selectorHelpers/getCompan
5
5
  const setupViewSelector_1 = require("../../commonSetup/setupViewSelector");
6
6
  const helpers_1 = require("../../helpers");
7
7
  function getChargeCardSetupViewDetails(state, companyId) {
8
- const chargeCardSetupViewDetails = (0, setupViewSelector_1.getCommonSetupViewDetails)(state, companyId, 'charge_cards', 'spend_management_setup');
8
+ const chargeCardSetupViewDetails = (0, setupViewSelector_1.getCommonSetupViewDetails)(state, companyId, 'charge_cards', 'charge_card_setup');
9
9
  const companyView = (0, getCompanyView_1.getCompanyView)(state, companyId, []);
10
10
  const companyChargeCardInfo = companyView === null || companyView === void 0 ? void 0 : companyView.company.company.companyChargeCardInfo;
11
11
  const { chargeCardSetupViewState, setupViewState } = state;
@@ -13,5 +13,8 @@ import { ZeniAPI } from '../../../../../zeniAPI';
13
13
  import { updateSetupViewLocalStoreData } from '../../../commonSetup/setupViewReducer';
14
14
  import { fetchChargeCardSetupView, fetchChargeCardSetupViewFailure, fetchChargeCardSetupViewSuccess } from '../chargeCardSetUpViewReducer';
15
15
  import { updatePlaidAccountViewAccountDetails } from '../../../plaidAccount/plaidAccountViewReducer';
16
- export declare type ActionType = ReturnType<typeof fetchChargeCardSetupView> | ReturnType<typeof updateAllUsers> | ReturnType<typeof updateUserRoles> | ReturnType<typeof updateCompanies> | ReturnType<typeof updateFiles> | ReturnType<typeof updateAccounts> | ReturnType<typeof updateAddresses> | ReturnType<typeof updatePaymentAccounts> | ReturnType<typeof updatePlaidAccountViewAccountDetails> | ReturnType<typeof updateSetupViewLocalStoreData> | ReturnType<typeof openSnackbar> | ReturnType<typeof fetchChargeCardSetupViewSuccess> | ReturnType<typeof fetchChargeCardSetupViewFailure>;
16
+ import { updatePaymentAccountList } from '../../../zeniAccounts/paymentAccountList/paymentAccountListReducer';
17
+ import { updateDepositAccounts } from '../../../../../entity/depositAccount/depositAccountReducer';
18
+ import { updateDepositAccountList } from '../../../zeniAccounts/depositAccountList/depositAccountListReducer';
19
+ export declare type ActionType = ReturnType<typeof fetchChargeCardSetupView> | ReturnType<typeof updateAllUsers> | ReturnType<typeof updateUserRoles> | ReturnType<typeof updateCompanies> | ReturnType<typeof updateFiles> | ReturnType<typeof updateAccounts> | ReturnType<typeof updateAddresses> | ReturnType<typeof updatePaymentAccounts> | ReturnType<typeof updatePaymentAccountList> | ReturnType<typeof updateDepositAccounts> | ReturnType<typeof updateDepositAccountList> | ReturnType<typeof updatePlaidAccountViewAccountDetails> | ReturnType<typeof updateSetupViewLocalStoreData> | ReturnType<typeof openSnackbar> | ReturnType<typeof fetchChargeCardSetupViewSuccess> | ReturnType<typeof fetchChargeCardSetupViewFailure>;
17
20
  export declare const fetchChargeCardSetupViewEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -16,6 +16,9 @@ const responsePayload_1 = require("../../../../../responsePayload");
16
16
  const setupViewReducer_1 = require("../../../commonSetup/setupViewReducer");
17
17
  const chargeCardSetUpViewReducer_1 = require("../chargeCardSetUpViewReducer");
18
18
  const plaidAccountViewReducer_1 = require("../../../plaidAccount/plaidAccountViewReducer");
19
+ const paymentAccountListReducer_1 = require("../../../zeniAccounts/paymentAccountList/paymentAccountListReducer");
20
+ const depositAccountReducer_1 = require("../../../../../entity/depositAccount/depositAccountReducer");
21
+ const depositAccountListReducer_1 = require("../../../zeniAccounts/depositAccountList/depositAccountListReducer");
19
22
  const fetchChargeCardSetupViewEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(chargeCardSetUpViewReducer_1.fetchChargeCardSetupView.match), (0, operators_1.switchMap)((action) => {
20
23
  var _a;
21
24
  const { companyId, cacheOverride, refreshViewInBackground } = action.payload;
@@ -29,9 +32,9 @@ const fetchChargeCardSetupViewEpic = (actions$, state$, zeniAPI) => actions$.pip
29
32
  return zeniAPI
30
33
  .getJSON(`${zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/companies/${companyId}?query={"view":"charge_cards_setup"}`)
31
34
  .pipe((0, operators_1.mergeMap)((response) => {
35
+ var _a, _b, _c;
32
36
  if ((0, responsePayload_1.isSuccessStatus)(response) && response.data != null) {
33
37
  const allBankAccountIds = response.data.accounts.map((account) => account.account_id);
34
- const paymentAccountIds = response.data.payment_accounts.map((paymentAccount) => paymentAccount.payment_account_id);
35
38
  const actions = [
36
39
  (0, userReducer_1.updateAllUsers)({ users: response.data.users }),
37
40
  (0, userRoleReducer_1.updateUserRoles)(response.data.user_roles),
@@ -43,10 +46,19 @@ const fetchChargeCardSetupViewEpic = (actions$, state$, zeniAPI) => actions$.pip
43
46
  (0, fileReducer_1.updateFiles)({ files: response.data.files }),
44
47
  (0, accountReducer_1.updateAccounts)(response.data.accounts, 'charge_cards'),
45
48
  (0, paymentAccountReducer_1.updatePaymentAccounts)(response.data.payment_accounts),
49
+ (0, paymentAccountListReducer_1.updatePaymentAccountList)({
50
+ data: response.data.payment_accounts,
51
+ updateType: 'replace',
52
+ }),
53
+ (0, depositAccountReducer_1.updateDepositAccounts)((_a = response.data.deposit_accounts) !== null && _a !== void 0 ? _a : []),
54
+ (0, depositAccountListReducer_1.updateDepositAccountList)({
55
+ data: (_c = (_b = response.data) === null || _b === void 0 ? void 0 : _b.deposit_accounts) !== null && _c !== void 0 ? _c : [],
56
+ updateType: 'replace',
57
+ }),
46
58
  (0, setupViewReducer_1.updateSetupViewLocalStoreData)({
47
59
  companyId: response.data.companies[0].company_id,
48
60
  }),
49
- (0, plaidAccountViewReducer_1.updatePlaidAccountViewAccountDetails)(allBankAccountIds, paymentAccountIds, 'spend_management_setup'),
61
+ (0, plaidAccountViewReducer_1.updatePlaidAccountViewAccountDetails)(allBankAccountIds, 'charge_card_setup'),
50
62
  (0, chargeCardSetUpViewReducer_1.fetchChargeCardSetupViewSuccess)(),
51
63
  ];
52
64
  return (0, rxjs_1.from)(actions);
@@ -62,10 +74,10 @@ const fetchChargeCardSetupViewEpic = (actions$, state$, zeniAPI) => actions$.pip
62
74
  JSON.stringify(error))))));
63
75
  }
64
76
  else {
65
- const { allBankAccountIds, paymentAccountIds } = plaidAccountViewState['spend_management_setup'].accountDetails;
77
+ const { allBankAccountIds } = plaidAccountViewState['spend_management_setup'].accountDetails;
66
78
  return (0, rxjs_1.of)((0, setupViewReducer_1.updateSetupViewLocalStoreData)({
67
79
  companyId,
68
- }), (0, plaidAccountViewReducer_1.updatePlaidAccountViewAccountDetails)(allBankAccountIds, paymentAccountIds, 'spend_management_setup'), (0, chargeCardSetUpViewReducer_1.fetchChargeCardSetupViewSuccess)());
80
+ }), (0, plaidAccountViewReducer_1.updatePlaidAccountViewAccountDetails)(allBankAccountIds, 'charge_card_setup'), (0, chargeCardSetUpViewReducer_1.fetchChargeCardSetupViewSuccess)());
69
81
  }
70
82
  }));
71
83
  exports.fetchChargeCardSetupViewEpic = fetchChargeCardSetupViewEpic;
@@ -77,6 +77,10 @@ export interface BusinessVerificationDetails extends CompanyAndOfficerLocalData
77
77
  updateStatus: FetchStateAndError;
78
78
  }
79
79
  export declare function getCommonSetupViewDetails(state: RootState, companyId: ID, setupViewType: SetupViewType, plaidAccountKeyType: PlaidAccountKeyType): SetupView;
80
+ export declare function getPrimaryAccountForTheProduct(state: RootState, companyId: ID, setupViewType: SetupViewType): {
81
+ accountId: ID;
82
+ accountType: AccountTypeSubConfigCodeKeyType;
83
+ } | undefined;
80
84
  export declare function getBusinessVerificationDetails(state: RootState, companyId: ID): BusinessVerificationDetails;
81
85
  export declare const getCompanyAndIdentityDetails: (state: RootState, companyId: ID, companyAndIdentityDetails: CompanyAndIdentityDetails) => CompanyAndOfficerLocalData;
82
86
  export declare const getAllFundingAccounts: (depositAccounts: DepositAccount[], paymentAccounts: PaymentAccount[], includeOnlyVerifiedAccounts?: boolean) => FundingAccount[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapPaymentAccToFundingAccount = exports.mapDepositAccToFundingAccount = exports.getAllFundingAccounts = exports.getCompanyAndIdentityDetails = exports.getBusinessVerificationDetails = exports.getCommonSetupViewDetails = void 0;
3
+ exports.mapPaymentAccToFundingAccount = exports.mapDepositAccToFundingAccount = exports.getAllFundingAccounts = exports.getCompanyAndIdentityDetails = exports.getBusinessVerificationDetails = exports.getPrimaryAccountForTheProduct = exports.getCommonSetupViewDetails = void 0;
4
4
  const accountSelector_1 = require("../../../entity/account/accountSelector");
5
5
  const fileSelector_1 = require("../../../entity/file/fileSelector");
6
6
  const fileViewSelector_1 = require("../../fileView/fileViewSelector");
@@ -14,58 +14,74 @@ function getCommonSetupViewDetails(state, companyId, setupViewType, plaidAccount
14
14
  const { accountState, setupViewState, paymentAccountState, paymentAccountListState, depositAccountState, depositAccountListState, plaidAccountViewState, } = state;
15
15
  const { updateStatus } = setupViewState;
16
16
  const { accountDetails, plaidConnectionDetails } = (0, plaidAccountViewSelector_1.getPlaidAccountDetails)(plaidAccountViewState, plaidAccountKeyType);
17
- const { allBankAccountIds, primaryFundingAccount } = accountDetails;
17
+ const { allBankAccountIds } = accountDetails;
18
18
  const { paymentAccountIds } = paymentAccountListState;
19
19
  const { accountIds: depositAccountIds } = depositAccountListState;
20
20
  const allBankAccounts = (_a = allBankAccountIds === null || allBankAccountIds === void 0 ? void 0 : allBankAccountIds.map((accountId) => (0, accountSelector_1.getAccountBase)(accountState, accountId, setupViewType)).filter((account) => account != null)) !== null && _a !== void 0 ? _a : [];
21
21
  const paymentAccounts = (_b = (0, paymentAccountSelector_1.getPaymentAccountsByPaymentAccountIds)(paymentAccountState, paymentAccountIds).filter((account) => account != null)) !== null && _b !== void 0 ? _b : [];
22
22
  const depositAccounts = (_c = (0, depositAccountSelector_1.getDepositAccountsByDepositAccountIds)(depositAccountState, depositAccountIds).filter((account) => account != null)) !== null && _c !== void 0 ? _c : [];
23
- const allFundingAccounts = (0, exports.getAllFundingAccounts)(depositAccounts, paymentAccounts, false);
23
+ const allFundingAccounts = (0, exports.getAllFundingAccounts)(setupViewType === 'zeni_accounts' ? [] : depositAccounts, // only external acct can be made primary for accounts setup
24
+ paymentAccounts, false);
24
25
  const companyView = (0, getCompanyView_1.getCompanyView)(state, companyId, []);
25
26
  const companyBillPayInfo = companyView === null || companyView === void 0 ? void 0 : companyView.company.company.companyBillPayInfo;
26
- let paymentAccount;
27
- let primaryAccount = undefined;
28
- if (((_d = accountDetails.paymentAccountIds) === null || _d === void 0 ? void 0 : _d.length) > 0) {
29
- // paymentAccount is used for products other than reimbursement
30
- const paymentAccountId = accountDetails.paymentAccountIds[0];
31
- paymentAccount = (0, paymentAccountSelector_1.getPaymentAccountByPaymentAccountId)(paymentAccountState, paymentAccountId);
32
- }
33
- // For reimbursement setup, use primaryFundingAccount as the payment account.
34
- // For other setup pages, continue using first payment account
35
- if (plaidAccountKeyType === 'reimbursement_setup') {
36
- if ((primaryFundingAccount === null || primaryFundingAccount === void 0 ? void 0 : primaryFundingAccount.accountType) === 'depositAccount') {
37
- const depositAccount = (0, depositAccountSelector_1.getDepositAccountByDepositAccountId)(depositAccountState, primaryFundingAccount.accountId);
38
- if (depositAccount != null) {
39
- primaryAccount = (0, exports.mapDepositAccToFundingAccount)(depositAccount);
40
- }
41
- }
42
- else if ((primaryFundingAccount === null || primaryFundingAccount === void 0 ? void 0 : primaryFundingAccount.accountType) === 'paymentAccount') {
43
- const paymentAccount = (0, paymentAccountSelector_1.getPaymentAccountByPaymentAccountId)(paymentAccountState, primaryFundingAccount.accountId);
44
- if (paymentAccount != null) {
45
- primaryAccount = (0, exports.mapPaymentAccToFundingAccount)(paymentAccount);
46
- }
27
+ const primaryAccount = getPrimaryAccountForTheProduct(state, companyId, setupViewType);
28
+ let primaryFundingAccount;
29
+ if ((primaryAccount === null || primaryAccount === void 0 ? void 0 : primaryAccount.accountType) === 'depositAccount') {
30
+ const depositAccount = (0, depositAccountSelector_1.getDepositAccountByDepositAccountId)(depositAccountState, primaryAccount.accountId);
31
+ if (depositAccount != null) {
32
+ primaryFundingAccount = (0, exports.mapDepositAccToFundingAccount)(depositAccount);
47
33
  }
48
34
  }
49
- else if ((paymentAccountIds === null || paymentAccountIds === void 0 ? void 0 : paymentAccountIds.length) > 0) {
50
- const paymentAccountId = paymentAccountIds[0];
51
- const paymentAccount = (0, paymentAccountSelector_1.getPaymentAccountByPaymentAccountId)(paymentAccountState, paymentAccountId);
35
+ else if ((primaryAccount === null || primaryAccount === void 0 ? void 0 : primaryAccount.accountType) === 'paymentAccount') {
36
+ const paymentAccount = (0, paymentAccountSelector_1.getPaymentAccountByPaymentAccountId)(paymentAccountState, primaryAccount.accountId);
52
37
  if (paymentAccount != null) {
53
- primaryAccount = (0, exports.mapPaymentAccToFundingAccount)(paymentAccount);
38
+ primaryFundingAccount = (0, exports.mapPaymentAccToFundingAccount)(paymentAccount);
54
39
  }
55
40
  }
41
+ let paymentAccountForBilling;
42
+ if (((_d = accountDetails.paymentAccountIds) === null || _d === void 0 ? void 0 : _d.length) > 0) {
43
+ const paymentAccountId = accountDetails.paymentAccountIds[0];
44
+ paymentAccountForBilling = (0, paymentAccountSelector_1.getPaymentAccountByPaymentAccountId)(paymentAccountState, paymentAccountId);
45
+ }
56
46
  return {
57
47
  companyBillPayInfo,
58
- paymentAccount,
59
- primaryFundingAccount: primaryAccount,
48
+ primaryFundingAccount,
49
+ paymentAccount: paymentAccountForBilling,
60
50
  allFundingAccounts,
61
51
  allBankAccounts,
62
52
  plaidConnectionDetails,
63
- accountUpdateStatus: accountDetails.updateStatus,
53
+ accountUpdateStatus: accountDetails.cashAccountUpdateStatus,
64
54
  accountFetchStatus: accountDetails.fetchStatus,
65
55
  updateStatus,
66
56
  };
67
57
  }
68
58
  exports.getCommonSetupViewDetails = getCommonSetupViewDetails;
59
+ function getPrimaryAccountForTheProduct(state, companyId, setupViewType) {
60
+ const companyView = (0, getCompanyView_1.getCompanyView)(state, companyId, []);
61
+ if (companyView == null) {
62
+ return undefined;
63
+ }
64
+ let primaryFundingAccount;
65
+ if (setupViewType === 'bill_pay') {
66
+ primaryFundingAccount =
67
+ companyView.company.company.companyBillPayInfo.primaryFundingAccount;
68
+ }
69
+ else if (setupViewType === 'reimbursement') {
70
+ primaryFundingAccount =
71
+ companyView.company.company.companyReimbursementInfo
72
+ .primaryFundingAccount;
73
+ }
74
+ else if (setupViewType === 'charge_cards') {
75
+ primaryFundingAccount =
76
+ companyView.company.company.companyChargeCardInfo.primaryFundingAccount;
77
+ }
78
+ else if (setupViewType === 'zeni_accounts') {
79
+ primaryFundingAccount =
80
+ companyView.company.company.companyZeniAccountInfo.primaryFundingAccount;
81
+ }
82
+ return primaryFundingAccount;
83
+ }
84
+ exports.getPrimaryAccountForTheProduct = getPrimaryAccountForTheProduct;
69
85
  function getBusinessVerificationDetails(state, companyId) {
70
86
  const { setupViewState } = state;
71
87
  const { companyDetails, companyOfficerUpdateStatus, primaryContactDetails, updateStatus, } = setupViewState;
@@ -7,7 +7,7 @@ const responsePayload_1 = require("../../../../../responsePayload");
7
7
  const plaidAccountViewReducer_1 = require("../../plaidAccountViewReducer");
8
8
  const depositAccountReducer_1 = require("../../../../../entity/depositAccount/depositAccountReducer");
9
9
  const updateMappedCashAccountEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(plaidAccountViewReducer_1.updateMappedCashAccount.match), (0, operators_1.mergeMap)((action) => {
10
- const { accountId, depositAccountId } = action.payload;
10
+ const { plaidAccountKeyType, accountId, depositAccountId } = action.payload;
11
11
  return zeniAPI
12
12
  .putAndGetJSON(`${zeniAPI.apiEndPoints.payMicroServiceBaseUrl}/1.0/deposit-accounts/${depositAccountId}`, {
13
13
  zeni_mapped_account_id: accountId,
@@ -15,17 +15,16 @@ const updateMappedCashAccountEpic = (actions$, _state$, zeniAPI) => actions$.pip
15
15
  .pipe((0, operators_1.mergeMap)((response) => {
16
16
  var _a, _b;
17
17
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
18
- const depositAccountIds = response.data.deposit_accounts.map((depositAccount) => depositAccount.deposit_account_id);
19
18
  const actions = [
20
19
  (0, depositAccountReducer_1.updateDepositAccounts)((_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.deposit_accounts) !== null && _b !== void 0 ? _b : []),
21
- (0, plaidAccountViewReducer_1.updateMappedCashAccountSuccess)(depositAccountIds),
20
+ (0, plaidAccountViewReducer_1.updateMappedCashAccountSuccess)(plaidAccountKeyType),
22
21
  ];
23
22
  return (0, rxjs_1.from)(actions);
24
23
  }
25
24
  else {
26
- return (0, rxjs_1.of)((0, plaidAccountViewReducer_1.updateMappedCashAccountFailure)(response.status));
25
+ return (0, rxjs_1.of)((0, plaidAccountViewReducer_1.updateMappedCashAccountFailure)(plaidAccountKeyType, response.status));
27
26
  }
28
- }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, plaidAccountViewReducer_1.updateMappedCashAccountFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Update Mapped Cash Account errored out' +
27
+ }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, plaidAccountViewReducer_1.updateMappedCashAccountFailure)(plaidAccountKeyType, (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Update Mapped Cash Account errored out' +
29
28
  JSON.stringify(error))))));
30
29
  }));
31
30
  exports.updateMappedCashAccountEpic = updateMappedCashAccountEpic;
@@ -15,11 +15,10 @@ const updatePaymentAccountEpic = (actions$, _state$, zeniAPI) => actions$.pipe((
15
15
  })
16
16
  .pipe((0, operators_1.mergeMap)((response) => {
17
17
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
18
- const paymentAccountIds = response.data.payment_accounts.map((paymentAccount) => paymentAccount.payment_account_id);
19
18
  const actions = [
20
19
  (0, accountReducer_1.updateAccounts)(response.data.accounts, setupViewType),
21
20
  (0, paymentAccountReducer_1.updatePaymentAccounts)(response.data.payment_accounts),
22
- (0, plaidAccountViewReducer_1.updatePaymentAccountSuccess)(paymentAccountIds, plaidAccountKeyType),
21
+ (0, plaidAccountViewReducer_1.updatePaymentAccountSuccess)(plaidAccountKeyType),
23
22
  ];
24
23
  return (0, rxjs_1.from)(actions);
25
24
  }
@@ -16,11 +16,10 @@ const updatePaymentAccountStatusEpic = (actions$, _state$, zeniAPI) => actions$.
16
16
  })
17
17
  .pipe((0, operators_1.mergeMap)((response) => {
18
18
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
19
- const paymentAccountIds = response.data.payment_accounts.map((paymentAccount) => paymentAccount.payment_account_id);
20
19
  const actions = [
21
20
  (0, accountReducer_1.updateAccounts)(response.data.accounts, setupViewType),
22
21
  (0, paymentAccountReducer_1.updatePaymentAccounts)(response.data.payment_accounts),
23
- (0, plaidAccountViewReducer_1.updatePaymentAccountStatusSuccess)(paymentAccountIds, linkTokenType, plaidAccountKeyType),
22
+ (0, plaidAccountViewReducer_1.updatePaymentAccountStatusSuccess)(linkTokenType, plaidAccountKeyType),
24
23
  ];
25
24
  return (0, rxjs_1.from)(actions);
26
25
  }
@@ -4,5 +4,6 @@ import { RootState } from '../../../../../reducer';
4
4
  import { ZeniAPI } from '../../../../../zeniAPI';
5
5
  import { updatePrimaryFundingAccount, updatePrimaryFundingAccountSuccess, updatePrimaryFundingAccountFailure } from '../../plaidAccountViewReducer';
6
6
  import { updateCompanies } from '../../../../../entity/company/companyReducer';
7
- export declare type ActionType = ReturnType<typeof updatePrimaryFundingAccount> | ReturnType<typeof updatePrimaryFundingAccountSuccess> | ReturnType<typeof updatePrimaryFundingAccountFailure> | ReturnType<typeof updateCompanies>;
7
+ import { openSnackbar } from '../../../../../entity/snackbar/snackbarReducer';
8
+ export declare type ActionType = ReturnType<typeof updatePrimaryFundingAccount> | ReturnType<typeof updatePrimaryFundingAccountSuccess> | ReturnType<typeof updatePrimaryFundingAccountFailure> | ReturnType<typeof updateCompanies> | ReturnType<typeof openSnackbar>;
8
9
  export declare const updatePrimaryFundingAccountEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -8,32 +8,79 @@ const plaidAccountViewReducer_1 = require("../../plaidAccountViewReducer");
8
8
  const companyReducer_1 = require("../../../../../entity/company/companyReducer");
9
9
  const helpers_1 = require("../../../helpers");
10
10
  const billPayConfigState_1 = require("../../../billPay/billPayConfig/billPayConfigState");
11
- const billPayConfigPayload_1 = require("../../../billPay/billPayConfig/billPayConfigPayload");
11
+ const snackbarReducer_1 = require("../../../../../entity/snackbar/snackbarReducer");
12
12
  const updatePrimaryFundingAccountEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(plaidAccountViewReducer_1.updatePrimaryFundingAccount.match), (0, operators_1.mergeMap)((action) => {
13
- const { companyId, accountId, accountType } = action.payload;
13
+ const { companyId, plaidAccountKeyType, accountId, accountType } = action.payload;
14
14
  return zeniAPI
15
- .putAndGetJSON(`${zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/companies/${companyId}`, {
16
- reimbursement_primary_funding_account_id: accountId,
17
- reimbursement_primary_funding_account_type: (0, helpers_1.accountTypeSubConfigCodeToAccType)(accountType),
18
- })
15
+ .putAndGetJSON(`${zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/companies/${companyId}`, toPayload(plaidAccountKeyType, accountId, accountType))
19
16
  .pipe((0, operators_1.mergeMap)((response) => {
20
- var _a, _b, _c;
17
+ var _a;
21
18
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
22
19
  const actions = [
23
20
  (0, companyReducer_1.updateCompanies)({
24
21
  payload: (_a = response.data.companies) !== null && _a !== void 0 ? _a : [],
25
22
  schema: {},
26
23
  }),
27
- (0, plaidAccountViewReducer_1.updatePrimaryFundingAccountSuccess)((_b = response.data.companies[0].reimbursement_info
28
- .primary_funding_account.account_id) !== null && _b !== void 0 ? _b : '', (0, billPayConfigPayload_1.getAccountTypeSubConfigCodeKey)((0, billPayConfigState_1.toAccType)((_c = response.data.companies[0].reimbursement_info
29
- .primary_funding_account.account_type) !== null && _c !== void 0 ? _c : ''))),
24
+ (0, plaidAccountViewReducer_1.updatePrimaryFundingAccountSuccess)(plaidAccountKeyType),
25
+ (0, snackbarReducer_1.openSnackbar)({
26
+ messageSection: 'primary_funding_account_updated',
27
+ messageText: 'success',
28
+ type: 'success',
29
+ variables: [
30
+ {
31
+ variableName: '_productType_',
32
+ variableValue: toProductTypeFromPlaidAccountKeyType(plaidAccountKeyType),
33
+ },
34
+ ],
35
+ }),
30
36
  ];
31
37
  return (0, rxjs_1.from)(actions);
32
38
  }
33
39
  else {
34
- return (0, rxjs_1.of)((0, plaidAccountViewReducer_1.updatePrimaryFundingAccountFailure)(response.status));
40
+ return (0, rxjs_1.of)((0, plaidAccountViewReducer_1.updatePrimaryFundingAccountFailure)(plaidAccountKeyType, response.status));
35
41
  }
36
- }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, plaidAccountViewReducer_1.updatePrimaryFundingAccountFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Update Primary Funding Account errored out' +
42
+ }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, plaidAccountViewReducer_1.updatePrimaryFundingAccountFailure)(plaidAccountKeyType, (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Update Primary Funding Account errored out' +
37
43
  JSON.stringify(error))))));
38
44
  }));
39
45
  exports.updatePrimaryFundingAccountEpic = updatePrimaryFundingAccountEpic;
46
+ function toPayload(plaidAccountKeyType, accountId, accountType) {
47
+ switch (plaidAccountKeyType) {
48
+ case 'bill_pay_setup': {
49
+ return {
50
+ bill_pay_primary_funding_account_id: accountId,
51
+ bill_pay_primary_funding_account_type: (0, helpers_1.accountTypeSubConfigCodeToAccType)((0, billPayConfigState_1.toAccountTypeSubConfigCodeKeyType)(accountType)),
52
+ };
53
+ }
54
+ case 'reimbursement_setup': {
55
+ return {
56
+ reimbursement_primary_funding_account_id: accountId,
57
+ reimbursement_primary_funding_account_type: (0, helpers_1.accountTypeSubConfigCodeToAccType)((0, billPayConfigState_1.toAccountTypeSubConfigCodeKeyType)(accountType)),
58
+ };
59
+ }
60
+ case 'charge_card_setup': {
61
+ return {
62
+ charge_cards_primary_funding_account_id: accountId,
63
+ charge_cards_primary_funding_account_type: (0, helpers_1.accountTypeSubConfigCodeToAccType)((0, billPayConfigState_1.toAccountTypeSubConfigCodeKeyType)(accountType)),
64
+ };
65
+ }
66
+ default: {
67
+ return {
68
+ deposit_accounts_primary_funding_account_id: accountId,
69
+ deposit_accounts_primary_funding_account_type: (0, helpers_1.accountTypeSubConfigCodeToAccType)((0, billPayConfigState_1.toAccountTypeSubConfigCodeKeyType)(accountType)),
70
+ };
71
+ }
72
+ }
73
+ }
74
+ function toProductTypeFromPlaidAccountKeyType(plaidAccountKeyType) {
75
+ switch (plaidAccountKeyType) {
76
+ case 'bill_pay_setup':
77
+ return 'Bill Pay';
78
+ case 'reimbursement_setup':
79
+ return 'Reimbursements';
80
+ case 'charge_card_setup':
81
+ return 'Cards';
82
+ case 'account_setup':
83
+ default:
84
+ return 'Checking';
85
+ }
86
+ }
@@ -9,5 +9,6 @@ import { establishPlaidConnection, establishPlaidConnectionSuccess, establishPla
9
9
  import { updateBankAccounts } from '../../../../../entity/bankAccount/bankAccountReducer';
10
10
  import { updateUserBankAccount } from '../../../../userFinancialAccount/userFinancialAccountReducer';
11
11
  import { updatePaymentAccountList } from '../../../zeniAccounts/paymentAccountList/paymentAccountListReducer';
12
- export declare type ActionType = ReturnType<typeof establishPlaidConnection> | ReturnType<typeof updateAccounts> | ReturnType<typeof updateBankAccounts> | ReturnType<typeof updateUserBankAccount> | ReturnType<typeof updatePaymentAccounts> | ReturnType<typeof openSnackbar> | ReturnType<typeof updatePaymentAccountList> | ReturnType<typeof establishPlaidConnectionSuccess> | ReturnType<typeof establishPlaidConnectionFailure>;
12
+ import { updateCompanyPrimaryAccount } from '../../../../../entity/company/companyReducer';
13
+ export declare type ActionType = ReturnType<typeof establishPlaidConnection> | ReturnType<typeof updateAccounts> | ReturnType<typeof updateBankAccounts> | ReturnType<typeof updateUserBankAccount> | ReturnType<typeof updatePaymentAccounts> | ReturnType<typeof openSnackbar> | ReturnType<typeof updatePaymentAccountList> | ReturnType<typeof establishPlaidConnectionSuccess> | ReturnType<typeof establishPlaidConnectionFailure> | ReturnType<typeof updateCompanyPrimaryAccount>;
13
14
  export declare const establishPlaidConnectionEpic: (actions$: ActionsObservable<ActionType>, state: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;