@zeniai/client-epic-state 5.0.9 → 5.0.10-betaVR1

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.
@@ -1,3 +1,4 @@
1
+ import { NestedAccountIDHierarchy } from '../../commonStateTypes/accountView/nestedAccountID';
1
2
  import { COABalanceGroupedByPeriod } from '../../commonStateTypes/coaBalance/coaBalance';
2
3
  import { ID } from '../../commonStateTypes/common';
3
4
  import { ReportID } from '../../commonStateTypes/viewAndReport/viewAndReport';
@@ -6,6 +7,7 @@ export interface SectionProjectView {
6
7
  projectId: ID;
7
8
  sectionId: ID;
8
9
  balancesByPeriod?: COABalanceGroupedByPeriod;
10
+ nestedAccountIds?: NestedAccountIDHierarchy[];
9
11
  }
10
12
  export declare function getSectionProjectViewKey(sectionId: ID, projectId: ID, reportId: ReportID): `${string}-${string}-cash_balance` | `${string}-${string}-card_balance` | `${string}-${string}-expense_automation_card` | `${string}-${string}-operating_expenses` | `${string}-${string}-operating_expenses_by_classes` | `${string}-${string}-revenue` | `${string}-${string}-revenue_by_classes` | `${string}-${string}-net_burn_or_income` | `${string}-${string}-net_burn_or_income_story_card` | `${string}-${string}-net_burn_or_income_by_classes` | `${string}-${string}-cash_position` | `${string}-${string}-top_expenses` | `${string}-${string}-profit_and_loss` | `${string}-${string}-profit_and_loss_by_classes` | `${string}-${string}-profit_and_loss_by_projects` | `${string}-${string}-balance_sheet` | `${string}-${string}-cash_flow` | `${string}-${string}-dashboard` | `${string}-${string}-finance_statement` | `${string}-${string}-transaction_list_of_account` | `${string}-${string}-transaction_list_missing_receipt` | `${string}-${string}-transaction_list_of_account_by_class` | `${string}-${string}-transaction_detail` | `${string}-${string}-cash_in_cash_out` | `${string}-${string}-insights_dashboard` | `${string}-${string}-company_details` | `${string}-${string}-class_list` | `${string}-${string}-account_list` | `${string}-${string}-account_list_by_type` | `${string}-${string}-vendor` | `${string}-${string}-task_card` | `${string}-${string}-bill_pay` | `${string}-${string}-reimbursement` | `${string}-${string}-bill_pay_card` | `${string}-${string}-reimbursement_card` | `${string}-${string}-bill_pay_promo_card` | `${string}-${string}-zeni_accounts` | `${string}-${string}-zeni_accounts_promo_card` | `${string}-${string}-zeni_treasury` | `${string}-${string}-charge_cards` | `${string}-${string}-other_connection` | `${string}-${string}-reimbursement_promo_card` | `${string}-${string}-onboarding` | `${string}-${string}-operating_expenses_by_vendor` | `${string}-${string}-operating_expenses_by_vendor_summary` | `${string}-${string}-vendors_tab` | `${string}-${string}-accounts_payable_aging` | `${string}-${string}-accounts_receivable_aging` | `${string}-${string}-vendor_global_review` | `${string}-${string}-prepaid_expenses` | `${string}-${string}-fixed_assets` | `${string}-${string}-notification` | `${string}-${string}-rewards_card` | `${string}-${string}-billing` | `${string}-${string}-flux_analysis_operating_expense` | `${string}-${string}-account_reconciliation` | `${string}-${string}-zeni_credit_promo_card` | `${string}-${string}-treasury_promo_card` | `${string}-${string}-excluded_account_reconciliation`;
11
13
  export type SectionProjectKey = ReturnType<typeof getSectionProjectViewKey>;
@@ -1,5 +1,6 @@
1
1
  import { COABalanceGroupedByPeriodPayloadV2 } from '../../commonPayloadTypes/v2/coaBalancePayload';
2
2
  import { CurrencyPayload } from '../../commonPayloadTypes/v2/viewAndReportPayloadv2';
3
+ import { NestedAccountIDHierarchy } from '../../commonStateTypes/accountView/nestedAccountID';
3
4
  import { ID } from '../../commonStateTypes/common';
4
5
  import { ReportID } from '../../commonStateTypes/viewAndReport/viewAndReport';
5
6
  import { SectionProjectView } from './sectionProjectView';
@@ -7,4 +8,4 @@ export declare const mapProjectCOABalanceGroupedPayloadToSectionProjectView: (ti
7
8
  projectId: ID;
8
9
  reportId: ReportID;
9
10
  sectionId: ID;
10
- }) => SectionProjectView;
11
+ }, nestedAccountIds: NestedAccountIDHierarchy[]) => SectionProjectView;
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mapProjectCOABalanceGroupedPayloadToSectionProjectView = void 0;
4
4
  const coaBalancePayload_1 = require("../../commonPayloadTypes/v2/coaBalancePayload");
5
5
  const sectionProjectView_1 = require("./sectionProjectView");
6
- const mapProjectCOABalanceGroupedPayloadToSectionProjectView = (timeframe, projectBalancesPayload, currencyPayload, id) => {
6
+ const mapProjectCOABalanceGroupedPayloadToSectionProjectView = (timeframe, projectBalancesPayload, currencyPayload, id, nestedAccountIds) => {
7
7
  return {
8
8
  key: (0, sectionProjectView_1.getSectionProjectViewKey)(id.sectionId, id.projectId, id.reportId),
9
9
  projectId: id.projectId,
10
10
  sectionId: id.sectionId,
11
11
  balancesByPeriod: (0, coaBalancePayload_1.mapCOABalanceGroupedByPeriodPayloadV2ToCOABalanceGroupedByPeriod)(projectBalancesPayload, currencyPayload, timeframe),
12
+ nestedAccountIds,
12
13
  };
13
14
  };
14
15
  exports.mapProjectCOABalanceGroupedPayloadToSectionProjectView = mapProjectCOABalanceGroupedPayloadToSectionProjectView;
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.clearAllSectionsProjectView = exports.updateSectionProjectView = exports.initialState = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
6
  const coaBalancePayload_1 = require("../../commonPayloadTypes/v2/coaBalancePayload");
7
+ const accountPayload_1 = require("../account/accountPayload");
8
+ const getNestedAccountIDHierarchyForSection_1 = require("../sectionAccountsView/getNestedAccountIDHierarchyForSection");
7
9
  const sectionProjectView_1 = require("./sectionProjectView");
8
10
  const sectionProjectViewHelper_1 = require("./sectionProjectViewHelper");
9
11
  exports.initialState = {
@@ -27,11 +29,16 @@ const sectionProjectView = (0, toolkit_1.createSlice)({
27
29
  };
28
30
  },
29
31
  reducer(draft, action) {
30
- const { timeframe, sectionPayload, sectionId, reportId, currencyPayload } = action.payload;
32
+ const { timeframe, sectionPayload, sectionId, reportId, currencyPayload, accountsMetadataPayload, } = action.payload;
31
33
  if (sectionPayload.projects != null) {
34
+ const accountsMetadata = accountsMetadataPayload.map((eachAccount) => (0, accountPayload_1.mapAccountMetadataPayloadToAccountMetadata)(eachAccount));
32
35
  Object.keys(sectionPayload.projects).forEach((projectId) => {
33
36
  const projectPayload = sectionPayload.projects[projectId];
34
- updateSectionProject(draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload);
37
+ const projectAccountIds = projectPayload.accounts != null
38
+ ? Object.keys(projectPayload.accounts)
39
+ : [];
40
+ const nestedAccountIds = (0, getNestedAccountIDHierarchyForSection_1.getNestedAccountIDHierarchyForAccounts)(projectAccountIds, accountsMetadata);
41
+ updateSectionProject(draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload, nestedAccountIds);
35
42
  });
36
43
  }
37
44
  },
@@ -43,14 +50,15 @@ const sectionProjectView = (0, toolkit_1.createSlice)({
43
50
  });
44
51
  _a = sectionProjectView.actions, exports.updateSectionProjectView = _a.updateSectionProjectView, exports.clearAllSectionsProjectView = _a.clearAllSectionsProjectView;
45
52
  exports.default = sectionProjectView.reducer;
46
- const updateSectionProject = (draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload) => {
53
+ const updateSectionProject = (draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload, nestedAccountIds) => {
47
54
  const sectionKey = (0, sectionProjectView_1.getSectionProjectViewKey)(sectionId, projectId, reportId);
48
55
  const section = draft.sectionsByKey[sectionKey];
49
56
  if (section != null) {
50
57
  draft.sectionsByKey[sectionKey].balancesByPeriod = Object.assign({}, draft.sectionsByKey[sectionKey].balancesByPeriod, (0, coaBalancePayload_1.mapCOABalanceGroupedByPeriodPayloadV2ToCOABalanceGroupedByPeriod)(projectPayload, currencyPayload, timeframe));
58
+ draft.sectionsByKey[sectionKey].nestedAccountIds = nestedAccountIds;
51
59
  }
52
60
  else {
53
61
  draft.sectionsByKey[sectionKey] =
54
- (0, sectionProjectViewHelper_1.mapProjectCOABalanceGroupedPayloadToSectionProjectView)(timeframe, projectPayload, currencyPayload, { sectionId, projectId, reportId });
62
+ (0, sectionProjectViewHelper_1.mapProjectCOABalanceGroupedPayloadToSectionProjectView)(timeframe, projectPayload, currencyPayload, { sectionId, projectId, reportId }, nestedAccountIds);
55
63
  }
56
64
  };
@@ -7,41 +7,21 @@ exports.getSectionProjectViewReport = void 0;
7
7
  const get_1 = __importDefault(require("lodash/get"));
8
8
  const coaBalance_1 = require("../../commonStateTypes/coaBalance/coaBalance");
9
9
  const getSumOfBalancesGroupedByPeriod_1 = require("../../commonStateTypes/coaBalance/classBalances/getSumOfBalancesGroupedByPeriod");
10
- const accountPayload_1 = require("../account/accountPayload");
11
- const accountState_1 = require("../account/accountState");
12
10
  const subAccountSelector_1 = require("../account/subAccountSelector");
13
11
  const projectSelector_1 = require("../project/projectSelector");
14
- const getNestedAccountIDHierarchyForSection_1 = require("../sectionAccountsView/getNestedAccountIDHierarchyForSection");
15
12
  const sectionProjectView_1 = require("./sectionProjectView");
16
13
  const getSectionProjectViewReport = (accountState, projectState, sectionState, projectIds, id, filter) => {
17
14
  const projectIdsToShow = projectIds.filter((projectId) => !filter.projectsToFilterOut.includes(projectId));
18
15
  const projectReports = [];
19
16
  const sectionBalancesTotalByPeriodArray = [];
20
- const accountsByProject = getAccountsByProject(accountState, id.sectionId, id.reportId);
21
17
  projectIdsToShow.forEach((projectId) => {
22
18
  const project = (0, projectSelector_1.getProjectById)(projectState, projectId);
23
19
  if (project == null) {
24
20
  return;
25
21
  }
26
- const projectAccountIds = accountsByProject[projectId] ?? [];
27
- const accountsMetadata = projectAccountIds
28
- .map((accountId) => {
29
- const key = (0, accountState_1.getAccountKey)(id.reportId, accountId, undefined, undefined, { projectId, sectionId: id.sectionId });
30
- const account = accountState.accountsByKey[key];
31
- if (account == null) {
32
- return undefined;
33
- }
34
- return (0, accountPayload_1.mapAccountMetadataPayloadToAccountMetadata)({
35
- account_id: account.accountId,
36
- account_name: account.accountName,
37
- account_description: account.accountDescription,
38
- labels: account.labels,
39
- is_sub_account: account.accountsViewParentId != null,
40
- parent_account_id: account.accountsViewParentId?.parentAccountId?.[0] ?? null,
41
- });
42
- })
43
- .filter((metadata) => metadata != null);
44
- const nestedAccountHierarchy = (0, getNestedAccountIDHierarchyForSection_1.getNestedAccountIDHierarchyForAccounts)(projectAccountIds, accountsMetadata);
22
+ const projectSectionKey = (0, sectionProjectView_1.getSectionProjectViewKey)(id.sectionId, projectId, id.reportId);
23
+ const projectSectionView = (0, get_1.default)(sectionState.sectionsByKey, projectSectionKey, undefined);
24
+ const nestedAccountHierarchy = projectSectionView?.nestedAccountIds ?? [];
45
25
  const nestedAccountReports = [];
46
26
  nestedAccountHierarchy.forEach((accountIdHierarchy) => {
47
27
  const report = (0, subAccountSelector_1.getNestedAccountReportForAccount)(accountState, {
@@ -56,8 +36,6 @@ const getSectionProjectViewReport = (accountState, projectState, sectionState, p
56
36
  nestedAccountReports.push(report);
57
37
  }
58
38
  });
59
- const projectSectionKey = (0, sectionProjectView_1.getSectionProjectViewKey)(id.sectionId, projectId, id.reportId);
60
- const projectSectionView = (0, get_1.default)(sectionState.sectionsByKey, projectSectionKey, undefined);
61
39
  const projectBalancesTotalByPeriod = projectSectionView?.balancesByPeriod ?? {};
62
40
  const projectReport = {
63
41
  projectId,
@@ -77,18 +55,3 @@ const getSectionProjectViewReport = (accountState, projectState, sectionState, p
77
55
  };
78
56
  };
79
57
  exports.getSectionProjectViewReport = getSectionProjectViewReport;
80
- const getAccountsByProject = (accountState, sectionId, reportId) => {
81
- const result = {};
82
- Object.values(accountState.accountsByKey).forEach((account) => {
83
- if (account.projectsViewParentId != null &&
84
- account.projectsViewParentId.sectionId === sectionId &&
85
- account.key.endsWith(reportId)) {
86
- const projectId = account.projectsViewParentId.projectId;
87
- if (result[projectId] == null) {
88
- result[projectId] = [];
89
- }
90
- result[projectId].push(account.accountId);
91
- }
92
- });
93
- return result;
94
- };
@@ -1,10 +1,11 @@
1
1
  import { mapCOABalanceGroupedByPeriodPayloadV2ToCOABalanceGroupedByPeriod, } from '../../commonPayloadTypes/v2/coaBalancePayload';
2
2
  import { getSectionProjectViewKey, } from './sectionProjectView';
3
- export const mapProjectCOABalanceGroupedPayloadToSectionProjectView = (timeframe, projectBalancesPayload, currencyPayload, id) => {
3
+ export const mapProjectCOABalanceGroupedPayloadToSectionProjectView = (timeframe, projectBalancesPayload, currencyPayload, id, nestedAccountIds) => {
4
4
  return {
5
5
  key: getSectionProjectViewKey(id.sectionId, id.projectId, id.reportId),
6
6
  projectId: id.projectId,
7
7
  sectionId: id.sectionId,
8
8
  balancesByPeriod: mapCOABalanceGroupedByPeriodPayloadV2ToCOABalanceGroupedByPeriod(projectBalancesPayload, currencyPayload, timeframe),
9
+ nestedAccountIds,
9
10
  };
10
11
  };
@@ -1,5 +1,7 @@
1
1
  import { createSlice } from '@reduxjs/toolkit';
2
2
  import { mapCOABalanceGroupedByPeriodPayloadV2ToCOABalanceGroupedByPeriod } from '../../commonPayloadTypes/v2/coaBalancePayload';
3
+ import { mapAccountMetadataPayloadToAccountMetadata, } from '../account/accountPayload';
4
+ import { getNestedAccountIDHierarchyForAccounts } from '../sectionAccountsView/getNestedAccountIDHierarchyForSection';
3
5
  import { getSectionProjectViewKey } from './sectionProjectView';
4
6
  import { mapProjectCOABalanceGroupedPayloadToSectionProjectView } from './sectionProjectViewHelper';
5
7
  export const initialState = {
@@ -23,11 +25,16 @@ const sectionProjectView = createSlice({
23
25
  };
24
26
  },
25
27
  reducer(draft, action) {
26
- const { timeframe, sectionPayload, sectionId, reportId, currencyPayload } = action.payload;
28
+ const { timeframe, sectionPayload, sectionId, reportId, currencyPayload, accountsMetadataPayload, } = action.payload;
27
29
  if (sectionPayload.projects != null) {
30
+ const accountsMetadata = accountsMetadataPayload.map((eachAccount) => mapAccountMetadataPayloadToAccountMetadata(eachAccount));
28
31
  Object.keys(sectionPayload.projects).forEach((projectId) => {
29
32
  const projectPayload = sectionPayload.projects[projectId];
30
- updateSectionProject(draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload);
33
+ const projectAccountIds = projectPayload.accounts != null
34
+ ? Object.keys(projectPayload.accounts)
35
+ : [];
36
+ const nestedAccountIds = getNestedAccountIDHierarchyForAccounts(projectAccountIds, accountsMetadata);
37
+ updateSectionProject(draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload, nestedAccountIds);
31
38
  });
32
39
  }
33
40
  },
@@ -39,14 +46,15 @@ const sectionProjectView = createSlice({
39
46
  });
40
47
  export const { updateSectionProjectView, clearAllSectionsProjectView } = sectionProjectView.actions;
41
48
  export default sectionProjectView.reducer;
42
- const updateSectionProject = (draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload) => {
49
+ const updateSectionProject = (draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload, nestedAccountIds) => {
43
50
  const sectionKey = getSectionProjectViewKey(sectionId, projectId, reportId);
44
51
  const section = draft.sectionsByKey[sectionKey];
45
52
  if (section != null) {
46
53
  draft.sectionsByKey[sectionKey].balancesByPeriod = Object.assign({}, draft.sectionsByKey[sectionKey].balancesByPeriod, mapCOABalanceGroupedByPeriodPayloadV2ToCOABalanceGroupedByPeriod(projectPayload, currencyPayload, timeframe));
54
+ draft.sectionsByKey[sectionKey].nestedAccountIds = nestedAccountIds;
47
55
  }
48
56
  else {
49
57
  draft.sectionsByKey[sectionKey] =
50
- mapProjectCOABalanceGroupedPayloadToSectionProjectView(timeframe, projectPayload, currencyPayload, { sectionId, projectId, reportId });
58
+ mapProjectCOABalanceGroupedPayloadToSectionProjectView(timeframe, projectPayload, currencyPayload, { sectionId, projectId, reportId }, nestedAccountIds);
51
59
  }
52
60
  };
@@ -1,41 +1,21 @@
1
1
  import recordGet from 'lodash/get';
2
2
  import { getCOABalances, } from '../../commonStateTypes/coaBalance/coaBalance';
3
3
  import { getSumOfBalancesByGroupedByPeriod } from '../../commonStateTypes/coaBalance/classBalances/getSumOfBalancesGroupedByPeriod';
4
- import { mapAccountMetadataPayloadToAccountMetadata } from '../account/accountPayload';
5
- import { getAccountKey } from '../account/accountState';
6
4
  import { getNestedAccountReportForAccount, } from '../account/subAccountSelector';
7
5
  import { getProjectById } from '../project/projectSelector';
8
- import { getNestedAccountIDHierarchyForAccounts } from '../sectionAccountsView/getNestedAccountIDHierarchyForSection';
9
6
  import { getSectionProjectViewKey } from './sectionProjectView';
10
7
  export const getSectionProjectViewReport = (accountState, projectState, sectionState, projectIds, id, filter) => {
11
8
  const projectIdsToShow = projectIds.filter((projectId) => !filter.projectsToFilterOut.includes(projectId));
12
9
  const projectReports = [];
13
10
  const sectionBalancesTotalByPeriodArray = [];
14
- const accountsByProject = getAccountsByProject(accountState, id.sectionId, id.reportId);
15
11
  projectIdsToShow.forEach((projectId) => {
16
12
  const project = getProjectById(projectState, projectId);
17
13
  if (project == null) {
18
14
  return;
19
15
  }
20
- const projectAccountIds = accountsByProject[projectId] ?? [];
21
- const accountsMetadata = projectAccountIds
22
- .map((accountId) => {
23
- const key = getAccountKey(id.reportId, accountId, undefined, undefined, { projectId, sectionId: id.sectionId });
24
- const account = accountState.accountsByKey[key];
25
- if (account == null) {
26
- return undefined;
27
- }
28
- return mapAccountMetadataPayloadToAccountMetadata({
29
- account_id: account.accountId,
30
- account_name: account.accountName,
31
- account_description: account.accountDescription,
32
- labels: account.labels,
33
- is_sub_account: account.accountsViewParentId != null,
34
- parent_account_id: account.accountsViewParentId?.parentAccountId?.[0] ?? null,
35
- });
36
- })
37
- .filter((metadata) => metadata != null);
38
- const nestedAccountHierarchy = getNestedAccountIDHierarchyForAccounts(projectAccountIds, accountsMetadata);
16
+ const projectSectionKey = getSectionProjectViewKey(id.sectionId, projectId, id.reportId);
17
+ const projectSectionView = recordGet(sectionState.sectionsByKey, projectSectionKey, undefined);
18
+ const nestedAccountHierarchy = projectSectionView?.nestedAccountIds ?? [];
39
19
  const nestedAccountReports = [];
40
20
  nestedAccountHierarchy.forEach((accountIdHierarchy) => {
41
21
  const report = getNestedAccountReportForAccount(accountState, {
@@ -50,8 +30,6 @@ export const getSectionProjectViewReport = (accountState, projectState, sectionS
50
30
  nestedAccountReports.push(report);
51
31
  }
52
32
  });
53
- const projectSectionKey = getSectionProjectViewKey(id.sectionId, projectId, id.reportId);
54
- const projectSectionView = recordGet(sectionState.sectionsByKey, projectSectionKey, undefined);
55
33
  const projectBalancesTotalByPeriod = projectSectionView?.balancesByPeriod ?? {};
56
34
  const projectReport = {
57
35
  projectId,
@@ -70,18 +48,3 @@ export const getSectionProjectViewReport = (accountState, projectState, sectionS
70
48
  sectionBalancesTotalByPeriod,
71
49
  };
72
50
  };
73
- const getAccountsByProject = (accountState, sectionId, reportId) => {
74
- const result = {};
75
- Object.values(accountState.accountsByKey).forEach((account) => {
76
- if (account.projectsViewParentId != null &&
77
- account.projectsViewParentId.sectionId === sectionId &&
78
- account.key.endsWith(reportId)) {
79
- const projectId = account.projectsViewParentId.projectId;
80
- if (result[projectId] == null) {
81
- result[projectId] = [];
82
- }
83
- result[projectId].push(account.accountId);
84
- }
85
- });
86
- return result;
87
- };
@@ -12,7 +12,13 @@ export const fetchCompletedTransactionsEpic = (actions$, state$, zeniAPI) => act
12
12
  const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
13
13
  const periodId = toMonthYearPeriodId(selectedPeriod);
14
14
  const isInitialLoad = action.payload.pageToken == null;
15
- const cacheKey = getCompletedTransactionsCacheKey(periodId, bulkUpload.sortKey, bulkUpload.sortOrder, bulkUpload.completedSubTab);
15
+ /**
16
+ * Snapshot sort config + subTab at request time so success/failure write
17
+ * into the same cache key the request was made under, even if the user
18
+ * toggles sort while the request is in flight.
19
+ */
20
+ const { sortKey, sortOrder, completedSubTab } = bulkUpload;
21
+ const cacheKey = getCompletedTransactionsCacheKey(periodId, sortKey, sortOrder, completedSubTab);
16
22
  const existingData = bulkUpload.completedTransactionsByPeriod[cacheKey];
17
23
  if (isInitialLoad &&
18
24
  action.payload.cacheOverride !== true &&
@@ -24,13 +30,13 @@ export const fetchCompletedTransactionsEpic = (actions$, state$, zeniAPI) => act
24
30
  const queryPayload = {
25
31
  start_date: period.start,
26
32
  end_date: period.end,
27
- sort_by: bulkUpload.sortKey,
28
- sort_order: bulkUpload.sortOrder === 'ascending' ? 'asc' : 'desc',
33
+ sort_by: sortKey,
34
+ sort_order: sortOrder === 'ascending' ? 'asc' : 'desc',
29
35
  page_token: action.payload.pageToken ?? null,
30
36
  page_size: 25,
31
37
  };
32
- if (bulkUpload.completedSubTab !== 'all') {
33
- queryPayload.match_type = bulkUpload.completedSubTab;
38
+ if (completedSubTab !== 'all') {
39
+ queryPayload.match_type = completedSubTab;
34
40
  }
35
41
  const encodedQuery = encodeURIComponent(JSON.stringify(queryPayload));
36
42
  return zeniAPI
@@ -46,16 +52,25 @@ export const fetchCompletedTransactionsEpic = (actions$, state$, zeniAPI) => act
46
52
  nextPageToken: response.data.next_page_token,
47
53
  totalCount: response.data.total_count,
48
54
  selectedPeriod,
55
+ sortKey,
56
+ sortOrder,
57
+ completedSubTab,
49
58
  }));
50
59
  return from(updateActions);
51
60
  }
52
61
  return of(fetchCompletedTransactionsFailure({
53
62
  error: response.status,
54
63
  selectedPeriod,
64
+ sortKey,
65
+ sortOrder,
66
+ completedSubTab,
55
67
  }));
56
68
  }), catchError((error) => of(fetchCompletedTransactionsFailure({
57
69
  error: createZeniAPIStatus('Unexpected Error', 'Fetch completed transactions errored: ' +
58
70
  JSON.stringify(error)),
59
71
  selectedPeriod,
72
+ sortKey,
73
+ sortOrder,
74
+ completedSubTab,
60
75
  }))));
61
76
  }));
@@ -5,7 +5,7 @@ import { updateTransactions } from '../../../../entity/transaction/transactionRe
5
5
  import { isSuccessResponse } from '../../../../responsePayload';
6
6
  import { BULK_UPLOAD_AUTOMATCHING_TIMEOUT_MS } from '../../helpers/bulkUploadTiming';
7
7
  import { extractTransactionPayloadsFromBatchFiles, isBatchDetailsApiStatusCompleted, toBatchDetails, } from '../../payload/missingReceiptsPayload';
8
- import { bulkUploadAutomatchingTimedOut, bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, pusherBatchStatusUpdate, requestMissingReceiptsTabNavigation, restoreBulkUploadMatchingState, } from '../../reducers/missingReceiptsViewReducer';
8
+ import { bulkUploadAutomatchingTimedOut, bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetails, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, pusherBatchStatusUpdate, requestMissingReceiptsTabNavigation, restoreBulkUploadMatchingState, } from '../../reducers/missingReceiptsViewReducer';
9
9
  /** First poll after upload; then interval while batch not resolved via Pusher or API. */
10
10
  const FALLBACK_FIRST_DELAY_MS = 30000;
11
11
  /** Shorter first poll for restored sessions — batch may already be near completion. */
@@ -35,9 +35,17 @@ export const bulkUploadAutomatchingTimeoutEpic = (actions$, state$) => actions$.
35
35
  if (bulk.phase !== 'matching' || bulk.currentBatchId !== batchId) {
36
36
  return EMPTY;
37
37
  }
38
+ /**
39
+ * Also request the single-batch details directly so the "X out of Y Receipts Matched"
40
+ * toast still fires when the backend actually completed between the last Pusher ping
41
+ * and this timeout. If Pusher already tagged the batch as still `processing`,
42
+ * `fetchBulkUploadBatchDetailsEpic`'s guard will skip the call and we simply rely on
43
+ * the list refresh to eventually populate details via `fetchMultipleBatchDetailsEpic`.
44
+ */
38
45
  return from([
39
46
  bulkUploadAutomatchingTimedOut(batchId),
40
47
  fetchBulkUploadBatches({ cacheOverride: true }),
48
+ fetchBulkUploadBatchDetails(),
41
49
  ]);
42
50
  }), takeUntil(merge(actions$.pipe(filter(clearBulkUpload.match)), actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((a) => a.payload.batchId === batchId &&
43
51
  a.payload.status === 'completed')), actions$.pipe(filter(fetchBulkUploadBatchDetailsSuccess.match), filter((a) => a.payload.batchId === batchId)))));
@@ -522,9 +522,9 @@ const expenseAutomationMissingReceiptsView = createSlice({
522
522
  },
523
523
  },
524
524
  fetchCompletedTransactionsSuccess(draft, action) {
525
- const { transactionIds, nextPageToken, totalCount, selectedPeriod, isInitialLoad, } = action.payload;
525
+ const { transactionIds, nextPageToken, totalCount, selectedPeriod, isInitialLoad, sortKey, sortOrder, completedSubTab, } = action.payload;
526
526
  const periodId = toMonthYearPeriodId(selectedPeriod);
527
- const cacheKey = getCompletedTransactionsCacheKey(periodId, draft.bulkUpload.sortKey, draft.bulkUpload.sortOrder, draft.bulkUpload.completedSubTab);
527
+ const cacheKey = getCompletedTransactionsCacheKey(periodId, sortKey, sortOrder, completedSubTab);
528
528
  if (isInitialLoad) {
529
529
  draft.bulkUpload.completedTransactionsByPeriod[cacheKey] = {
530
530
  transactionIds,
@@ -553,7 +553,7 @@ const expenseAutomationMissingReceiptsView = createSlice({
553
553
  },
554
554
  fetchCompletedTransactionsFailure(draft, action) {
555
555
  const periodId = toMonthYearPeriodId(action.payload.selectedPeriod);
556
- const cacheKey = getCompletedTransactionsCacheKey(periodId, draft.bulkUpload.sortKey, draft.bulkUpload.sortOrder, draft.bulkUpload.completedSubTab);
556
+ const cacheKey = getCompletedTransactionsCacheKey(periodId, action.payload.sortKey, action.payload.sortOrder, action.payload.completedSubTab);
557
557
  const existing = draft.bulkUpload.completedTransactionsByPeriod[cacheKey];
558
558
  if (existing != null) {
559
559
  existing.fetchState = {
@@ -15,7 +15,13 @@ const fetchCompletedTransactionsEpic = (actions$, state$, zeniAPI) => actions$.p
15
15
  const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
16
16
  const periodId = (0, timePeriod_1.toMonthYearPeriodId)(selectedPeriod);
17
17
  const isInitialLoad = action.payload.pageToken == null;
18
- const cacheKey = (0, missingReceiptsViewReducer_1.getCompletedTransactionsCacheKey)(periodId, bulkUpload.sortKey, bulkUpload.sortOrder, bulkUpload.completedSubTab);
18
+ /**
19
+ * Snapshot sort config + subTab at request time so success/failure write
20
+ * into the same cache key the request was made under, even if the user
21
+ * toggles sort while the request is in flight.
22
+ */
23
+ const { sortKey, sortOrder, completedSubTab } = bulkUpload;
24
+ const cacheKey = (0, missingReceiptsViewReducer_1.getCompletedTransactionsCacheKey)(periodId, sortKey, sortOrder, completedSubTab);
19
25
  const existingData = bulkUpload.completedTransactionsByPeriod[cacheKey];
20
26
  if (isInitialLoad &&
21
27
  action.payload.cacheOverride !== true &&
@@ -27,13 +33,13 @@ const fetchCompletedTransactionsEpic = (actions$, state$, zeniAPI) => actions$.p
27
33
  const queryPayload = {
28
34
  start_date: period.start,
29
35
  end_date: period.end,
30
- sort_by: bulkUpload.sortKey,
31
- sort_order: bulkUpload.sortOrder === 'ascending' ? 'asc' : 'desc',
36
+ sort_by: sortKey,
37
+ sort_order: sortOrder === 'ascending' ? 'asc' : 'desc',
32
38
  page_token: action.payload.pageToken ?? null,
33
39
  page_size: 25,
34
40
  };
35
- if (bulkUpload.completedSubTab !== 'all') {
36
- queryPayload.match_type = bulkUpload.completedSubTab;
41
+ if (completedSubTab !== 'all') {
42
+ queryPayload.match_type = completedSubTab;
37
43
  }
38
44
  const encodedQuery = encodeURIComponent(JSON.stringify(queryPayload));
39
45
  return zeniAPI
@@ -49,17 +55,26 @@ const fetchCompletedTransactionsEpic = (actions$, state$, zeniAPI) => actions$.p
49
55
  nextPageToken: response.data.next_page_token,
50
56
  totalCount: response.data.total_count,
51
57
  selectedPeriod,
58
+ sortKey,
59
+ sortOrder,
60
+ completedSubTab,
52
61
  }));
53
62
  return (0, rxjs_1.from)(updateActions);
54
63
  }
55
64
  return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.fetchCompletedTransactionsFailure)({
56
65
  error: response.status,
57
66
  selectedPeriod,
67
+ sortKey,
68
+ sortOrder,
69
+ completedSubTab,
58
70
  }));
59
71
  }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.fetchCompletedTransactionsFailure)({
60
72
  error: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Fetch completed transactions errored: ' +
61
73
  JSON.stringify(error)),
62
74
  selectedPeriod,
75
+ sortKey,
76
+ sortOrder,
77
+ completedSubTab,
63
78
  }))));
64
79
  }));
65
80
  exports.fetchCompletedTransactionsEpic = fetchCompletedTransactionsEpic;
@@ -4,8 +4,8 @@ import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
4
4
  import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
5
5
  import { RootState } from '../../../../reducer';
6
6
  import { ZeniAPI } from '../../../../zeniAPI';
7
- import { bulkUploadAutomatchingTimedOut, bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, pusherBatchStatusUpdate, requestMissingReceiptsTabNavigation, restoreBulkUploadMatchingState } from '../../reducers/missingReceiptsViewReducer';
8
- export type ActionType = ReturnType<typeof bulkUploadReceiptsSuccess> | ReturnType<typeof restoreBulkUploadMatchingState> | ReturnType<typeof pusherBatchStatusUpdate> | ReturnType<typeof fetchBulkUploadBatchDetailsSuccess> | ReturnType<typeof fetchBulkUploadBatches> | ReturnType<typeof requestMissingReceiptsTabNavigation> | ReturnType<typeof updateTransactions> | ReturnType<typeof clearBulkUpload> | ReturnType<typeof openSnackbar> | ReturnType<typeof bulkUploadAutomatchingTimedOut>;
7
+ import { bulkUploadAutomatchingTimedOut, bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetails, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, pusherBatchStatusUpdate, requestMissingReceiptsTabNavigation, restoreBulkUploadMatchingState } from '../../reducers/missingReceiptsViewReducer';
8
+ export type ActionType = ReturnType<typeof bulkUploadReceiptsSuccess> | ReturnType<typeof restoreBulkUploadMatchingState> | ReturnType<typeof pusherBatchStatusUpdate> | ReturnType<typeof fetchBulkUploadBatchDetails> | ReturnType<typeof fetchBulkUploadBatchDetailsSuccess> | ReturnType<typeof fetchBulkUploadBatches> | ReturnType<typeof requestMissingReceiptsTabNavigation> | ReturnType<typeof updateTransactions> | ReturnType<typeof clearBulkUpload> | ReturnType<typeof openSnackbar> | ReturnType<typeof bulkUploadAutomatchingTimedOut>;
9
9
  /**
10
10
  * On Pusher batch completion: refresh batch list (then fetchMultipleBatchDetailsEpic runs),
11
11
  * and request switching to the Unmatched tab. Debounced to reduce duplicate refreshes.
@@ -39,9 +39,17 @@ const bulkUploadAutomatchingTimeoutEpic = (actions$, state$) => actions$.pipe((0
39
39
  if (bulk.phase !== 'matching' || bulk.currentBatchId !== batchId) {
40
40
  return rxjs_1.EMPTY;
41
41
  }
42
+ /**
43
+ * Also request the single-batch details directly so the "X out of Y Receipts Matched"
44
+ * toast still fires when the backend actually completed between the last Pusher ping
45
+ * and this timeout. If Pusher already tagged the batch as still `processing`,
46
+ * `fetchBulkUploadBatchDetailsEpic`'s guard will skip the call and we simply rely on
47
+ * the list refresh to eventually populate details via `fetchMultipleBatchDetailsEpic`.
48
+ */
42
49
  return (0, rxjs_1.from)([
43
50
  (0, missingReceiptsViewReducer_1.bulkUploadAutomatchingTimedOut)(batchId),
44
51
  (0, missingReceiptsViewReducer_1.fetchBulkUploadBatches)({ cacheOverride: true }),
52
+ (0, missingReceiptsViewReducer_1.fetchBulkUploadBatchDetails)(),
45
53
  ]);
46
54
  }), (0, operators_1.takeUntil)((0, rxjs_1.merge)(actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.clearBulkUpload.match)), actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.pusherBatchStatusUpdate.match), (0, operators_1.filter)((a) => a.payload.batchId === batchId &&
47
55
  a.payload.status === 'completed')), actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.fetchBulkUploadBatchDetailsSuccess.match), (0, operators_1.filter)((a) => a.payload.batchId === batchId)))));
@@ -101,14 +101,20 @@ export declare const fetchMissingReceipts: import("@reduxjs/toolkit").ActionCrea
101
101
  pageToken: string | undefined;
102
102
  cacheOverride: boolean | undefined;
103
103
  }, "expenseAutomationMissingReceiptsView/fetchCompletedTransactions", never, never>, fetchCompletedTransactionsSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
104
+ completedSubTab: CompletedSubTab;
104
105
  isInitialLoad: boolean;
105
106
  nextPageToken: string | null;
106
107
  selectedPeriod: MonthYearPeriod;
108
+ sortKey: BulkUploadSortKey;
109
+ sortOrder: SortOrder;
107
110
  totalCount: number;
108
111
  transactionIds: ID[];
109
112
  }, "expenseAutomationMissingReceiptsView/fetchCompletedTransactionsSuccess">, fetchCompletedTransactionsFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
113
+ completedSubTab: CompletedSubTab;
110
114
  error: ZeniAPIStatus;
111
115
  selectedPeriod: MonthYearPeriod;
116
+ sortKey: BulkUploadSortKey;
117
+ sortOrder: SortOrder;
112
118
  }, "expenseAutomationMissingReceiptsView/fetchCompletedTransactionsFailure">;
113
119
  declare const _default: import("redux").Reducer<MissingReceiptsViewState>;
114
120
  export default _default;
@@ -527,9 +527,9 @@ const expenseAutomationMissingReceiptsView = (0, toolkit_1.createSlice)({
527
527
  },
528
528
  },
529
529
  fetchCompletedTransactionsSuccess(draft, action) {
530
- const { transactionIds, nextPageToken, totalCount, selectedPeriod, isInitialLoad, } = action.payload;
530
+ const { transactionIds, nextPageToken, totalCount, selectedPeriod, isInitialLoad, sortKey, sortOrder, completedSubTab, } = action.payload;
531
531
  const periodId = (0, timePeriod_1.toMonthYearPeriodId)(selectedPeriod);
532
- const cacheKey = (0, exports.getCompletedTransactionsCacheKey)(periodId, draft.bulkUpload.sortKey, draft.bulkUpload.sortOrder, draft.bulkUpload.completedSubTab);
532
+ const cacheKey = (0, exports.getCompletedTransactionsCacheKey)(periodId, sortKey, sortOrder, completedSubTab);
533
533
  if (isInitialLoad) {
534
534
  draft.bulkUpload.completedTransactionsByPeriod[cacheKey] = {
535
535
  transactionIds,
@@ -558,7 +558,7 @@ const expenseAutomationMissingReceiptsView = (0, toolkit_1.createSlice)({
558
558
  },
559
559
  fetchCompletedTransactionsFailure(draft, action) {
560
560
  const periodId = (0, timePeriod_1.toMonthYearPeriodId)(action.payload.selectedPeriod);
561
- const cacheKey = (0, exports.getCompletedTransactionsCacheKey)(periodId, draft.bulkUpload.sortKey, draft.bulkUpload.sortOrder, draft.bulkUpload.completedSubTab);
561
+ const cacheKey = (0, exports.getCompletedTransactionsCacheKey)(periodId, action.payload.sortKey, action.payload.sortOrder, action.payload.completedSubTab);
562
562
  const existing = draft.bulkUpload.completedTransactionsByPeriod[cacheKey];
563
563
  if (existing != null) {
564
564
  existing.fetchState = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.0.9",
3
+ "version": "5.0.10-betaVR1",
4
4
  "description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/esm/index.js",
@@ -111,7 +111,7 @@
111
111
  "find-dead-code": "ts-prune | grep -v '(used in module)'",
112
112
  "find-unused-exports": "ts-unused-exports ./tsconfig.json",
113
113
  "circular-dependency": "npx madge --circular --extensions ts ./src",
114
- "build": "concurrently --kill-others-on-fail --handle-input \"echo 'Running ESLint...' && eslint . --ext .js,.jsx,.ts,.tsx\" \"echo 'TypeScript build in progress...' && time tsc && echo 'ESM build...' && tsc -p tsconfig.esm.json\" \"echo 'Running tests and typecheck...' && pnpm test\" && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
114
+ "build": "concurrently --kill-others-on-fail --handle-input \"echo 'Running ESLint...' && eslint . --ext .js,.jsx,.ts,.tsx\" \"echo 'TypeScript build in progress...' && time tsc && echo 'ESM build...' && tsc -p tsconfig.esm.json\"",
115
115
  "only-build": "eslint . --ext .js,.jsx,.ts,.tsx && time tsc && tsc -p tsconfig.esm.json && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
116
116
  "only-build-dev": "eslint . --ext .js,.jsx,.ts,.tsx && time tsc -p tsconfig.dev.json && tsc -p tsconfig.esm.dev.json && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
117
117
  "format": "prettier --write --ignore-unknown \"src/**/*\" && pnpm lint",