@zeniai/client-epic-state 5.0.65-betaRR6 → 5.0.65

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 (106) hide show
  1. package/lib/common/aiCfo/aiCfoSuggestedQuestionsPageContext.d.ts +1 -1
  2. package/lib/entity/aiCfo/aiCfoPayload.d.ts +1 -168
  3. package/lib/entity/aiCfo/aiCfoReducer.js +2 -186
  4. package/lib/entity/aiCfo/aiCfoState.d.ts +4 -164
  5. package/lib/entity/aiCfo/aiCfoState.js +1 -10
  6. package/lib/entity/jeSchedules/jeSchedulesTypes.d.ts +1 -1
  7. package/lib/entity/monthEndCloseChecks/monthEndCloseChecksState.d.ts +1 -1
  8. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  9. package/lib/entity/snackbar/snackbarTypes.js +0 -2
  10. package/lib/entity/tenant/clearAllEpic.d.ts +2 -6
  11. package/lib/entity/tenant/clearAllEpic.js +0 -8
  12. package/lib/epic.d.ts +1 -9
  13. package/lib/epic.js +1 -9
  14. package/lib/esm/entity/aiCfo/aiCfoReducer.js +3 -187
  15. package/lib/esm/entity/aiCfo/aiCfoState.js +0 -7
  16. package/lib/esm/entity/snackbar/snackbarTypes.js +0 -2
  17. package/lib/esm/entity/tenant/clearAllEpic.js +0 -8
  18. package/lib/esm/epic.js +1 -9
  19. package/lib/esm/index.js +3 -17
  20. package/lib/esm/reducer.js +0 -12
  21. package/lib/esm/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +2 -12
  22. package/lib/esm/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +0 -25
  23. package/lib/index.d.ts +3 -16
  24. package/lib/index.js +11 -99
  25. package/lib/reducer.d.ts +0 -12
  26. package/lib/reducer.js +0 -12
  27. package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
  28. package/lib/view/aiCfoView/aiCfoViewReducer.d.ts +0 -7
  29. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.d.ts +1 -8
  30. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +2 -12
  31. package/lib/view/companyHealthMetricView/companyHealthMetricViewSelector.d.ts +1 -1
  32. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  33. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +1 -1
  34. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +2 -2
  35. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +1 -1
  36. package/lib/view/onboardingView/cockpitView/types/onboardingCockpitViewTypes.d.ts +1 -1
  37. package/lib/view/people/peopleTypes.d.ts +1 -1
  38. package/lib/view/scheduleView/scheduleListView/scheduleListTypes.d.ts +1 -1
  39. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.d.ts +1 -1
  40. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.d.ts +0 -14
  41. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +1 -27
  42. package/lib/view/taskManager/taskListView/taskListReducer.d.ts +1 -1
  43. package/package.json +1 -1
  44. package/lib/entity/cardPolicy/cardPolicyPayload.d.ts +0 -176
  45. package/lib/entity/cardPolicy/cardPolicyPayload.js +0 -112
  46. package/lib/entity/cardPolicy/cardPolicyReducer.d.ts +0 -13
  47. package/lib/entity/cardPolicy/cardPolicyReducer.js +0 -203
  48. package/lib/entity/cardPolicy/cardPolicySelector.d.ts +0 -28
  49. package/lib/entity/cardPolicy/cardPolicySelector.js +0 -86
  50. package/lib/entity/cardPolicy/cardPolicyState.d.ts +0 -172
  51. package/lib/entity/cardPolicy/cardPolicyState.js +0 -14
  52. package/lib/entity/cardPolicy/extractPolicyDocumentEpic.d.ts +0 -18
  53. package/lib/entity/cardPolicy/extractPolicyDocumentEpic.js +0 -54
  54. package/lib/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.d.ts +0 -26
  55. package/lib/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.js +0 -47
  56. package/lib/esm/entity/cardPolicy/cardPolicyPayload.js +0 -101
  57. package/lib/esm/entity/cardPolicy/cardPolicyReducer.js +0 -199
  58. package/lib/esm/entity/cardPolicy/cardPolicySelector.js +0 -66
  59. package/lib/esm/entity/cardPolicy/cardPolicyState.js +0 -9
  60. package/lib/esm/entity/cardPolicy/extractPolicyDocumentEpic.js +0 -50
  61. package/lib/esm/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.js +0 -43
  62. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.js +0 -70
  63. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.js +0 -22
  64. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.js +0 -1
  65. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.js +0 -56
  66. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.js +0 -49
  67. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.js +0 -42
  68. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.js +0 -72
  69. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.js +0 -21
  70. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.js +0 -1
  71. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.js +0 -56
  72. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +0 -50
  73. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +0 -6
  74. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.js +0 -1
  75. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.js +0 -34
  76. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.js +0 -25
  77. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.d.ts +0 -14
  78. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.js +0 -74
  79. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.d.ts +0 -21
  80. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.js +0 -28
  81. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.d.ts +0 -25
  82. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.js +0 -2
  83. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.d.ts +0 -19
  84. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.js +0 -60
  85. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.d.ts +0 -18
  86. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.js +0 -53
  87. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.d.ts +0 -16
  88. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.js +0 -46
  89. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.d.ts +0 -15
  90. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.js +0 -76
  91. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.d.ts +0 -21
  92. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.js +0 -27
  93. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.d.ts +0 -19
  94. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.js +0 -2
  95. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.d.ts +0 -19
  96. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.js +0 -60
  97. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.d.ts +0 -12
  98. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +0 -54
  99. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.d.ts +0 -4
  100. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +0 -10
  101. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.d.ts +0 -15
  102. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.js +0 -2
  103. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.d.ts +0 -8
  104. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.js +0 -38
  105. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.d.ts +0 -15
  106. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.js +0 -29
@@ -1,49 +0,0 @@
1
- import { from, of } from 'rxjs';
2
- import { catchError, filter, mergeMap } from 'rxjs/operators';
3
- import { toUpdateCardPolicyTemplateRequestBody, } from '../../../../../entity/cardPolicy/cardPolicyPayload';
4
- import { updateCreatedCardPolicyTemplate } from '../../../../../entity/cardPolicy/cardPolicyReducer';
5
- import { createZeniAPIStatus, isSuccessStatus } from '../../../../../responsePayload';
6
- import { updateCardPolicy, updateCardPolicyFetchStatus, } from './cardPolicyDetailReducer';
7
- /**
8
- * `PUT /cards/1.0/policy-templates/{id}`. Reads the current `formDraft`
9
- * off the `cardPolicyDetail` slice, converts it to the snake_case wire
10
- * body (same shape as create), and submits. On success the entity
11
- * slice picks up the refreshed template and the view lifecycle flips
12
- * to `Completed`.
13
- *
14
- * If the action fires before a draft is seeded (e.g. user clicks save
15
- * before the detail fetch lands), we short-circuit with an Error.
16
- */
17
- export const updateCardPolicyEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(updateCardPolicy.match), mergeMap((action) => {
18
- const templateId = action.payload;
19
- const formDraft = state$.value.cardPolicyDetailState.formDraft;
20
- if (formDraft == null) {
21
- return of(updateCardPolicyFetchStatus({
22
- fetchState: 'Error',
23
- error: createZeniAPIStatus('Missing form draft', `Cannot update card-policy ${templateId} — no formDraft is loaded.`),
24
- }));
25
- }
26
- const body = toUpdateCardPolicyTemplateRequestBody(formDraft);
27
- return zeniAPI
28
- .putAndGetJSON(`${zeniAPI.apiEndPoints.cardMicroServiceBaseUrl}/1.0/policy-templates/${templateId}`, body)
29
- .pipe(mergeMap((response) => {
30
- if (isSuccessStatus(response) && response.data != null) {
31
- const { template } = response.data;
32
- const actions = [
33
- updateCreatedCardPolicyTemplate(template),
34
- updateCardPolicyFetchStatus({ fetchState: 'Completed' }),
35
- ];
36
- return from(actions);
37
- }
38
- else {
39
- return of(updateCardPolicyFetchStatus({
40
- fetchState: 'Error',
41
- error: response.status,
42
- }));
43
- }
44
- }), catchError((error) => of(updateCardPolicyFetchStatus({
45
- fetchState: 'Error',
46
- error: createZeniAPIStatus('Unexpected Error', 'Update card-policy REST API call errored out' +
47
- JSON.stringify(error)),
48
- }))));
49
- }));
@@ -1,42 +0,0 @@
1
- import { from, of } from 'rxjs';
2
- import { catchError, filter, mergeMap } from 'rxjs/operators';
3
- import { removeCardPolicyTemplate } from '../../../../../entity/cardPolicy/cardPolicyReducer';
4
- import { createZeniAPIStatus, isSuccessStatus, } from '../../../../../responsePayload';
5
- import { archiveCardPolicy, updateArchiveCardPolicyFetchStatus, } from './cardPolicyListReducer';
6
- /**
7
- * `DELETE /cards/1.0/policy-templates/{id}`. Modeled like
8
- * `deleteBillEpic`: typed as bare `ZeniAPIResponse` (no `data` body
9
- * expected) with `isSuccessStatus` driving the success branch. On
10
- * success the entity slice drops the template via
11
- * `removeCardPolicyTemplate(templateId)` and the view slice records
12
- * `Completed` (also pruning the ID from `templateIds`).
13
- */
14
- export const archiveCardPolicyEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(archiveCardPolicy.match), mergeMap((action) => {
15
- const templateId = action.payload;
16
- return zeniAPI
17
- .deleteAndGetJSON(`${zeniAPI.apiEndPoints.cardMicroServiceBaseUrl}/1.0/policy-templates/${templateId}`)
18
- .pipe(mergeMap((response) => {
19
- if (isSuccessStatus(response)) {
20
- const actions = [
21
- removeCardPolicyTemplate(templateId),
22
- updateArchiveCardPolicyFetchStatus({
23
- fetchState: 'Completed',
24
- templateId,
25
- }),
26
- ];
27
- return from(actions);
28
- }
29
- else {
30
- return of(updateArchiveCardPolicyFetchStatus({
31
- fetchState: 'Error',
32
- error: response.status,
33
- templateId,
34
- }));
35
- }
36
- }), catchError((error) => of(updateArchiveCardPolicyFetchStatus({
37
- fetchState: 'Error',
38
- error: createZeniAPIStatus('Unexpected Error', 'Archive card-policy REST API call errored out' +
39
- JSON.stringify(error)),
40
- templateId,
41
- }))));
42
- }));
@@ -1,72 +0,0 @@
1
- import { createSlice } from '@reduxjs/toolkit';
2
- export const initialState = {
3
- templateIds: [],
4
- fetchState: {
5
- fetchState: 'Not-Started',
6
- error: undefined,
7
- },
8
- archiveFetchState: {
9
- fetchState: 'Not-Started',
10
- error: undefined,
11
- },
12
- archiveTargetTemplateId: undefined,
13
- };
14
- const cardPolicyList = createSlice({
15
- name: 'cardPolicyList',
16
- initialState,
17
- reducers: {
18
- /**
19
- * Kick off the `GET /cards/1.0/policy-templates` request. The
20
- * accompanying epic dispatches `updateCardPolicyTemplates(templates)`
21
- * + `updateCardPolicyStats(stats)` on the entity slice and
22
- * `updateCardPolicyListFetchStatus` here (also supplying the ordered
23
- * `templateIds` on success).
24
- */
25
- fetchCardPolicyList(draft) {
26
- draft.fetchState.fetchState = 'In-Progress';
27
- draft.fetchState.error = undefined;
28
- },
29
- updateCardPolicyListFetchStatus(draft, action) {
30
- draft.fetchState.fetchState = action.payload.fetchState;
31
- draft.fetchState.error = action.payload.error;
32
- if (action.payload.templateIds != null) {
33
- draft.templateIds = action.payload.templateIds;
34
- }
35
- },
36
- /**
37
- * Kick off the `DELETE /cards/1.0/policy-templates/{id}` request.
38
- * The accompanying epic dispatches `removeCardPolicyTemplate(id)` on
39
- * the entity slice on success + `updateArchiveCardPolicyFetchStatus`
40
- * here. The view layer also drops the ID from `templateIds` so the
41
- * list stays in sync without re-fetching.
42
- */
43
- archiveCardPolicy: {
44
- reducer(draft, action) {
45
- draft.archiveFetchState.fetchState = 'In-Progress';
46
- draft.archiveFetchState.error = undefined;
47
- draft.archiveTargetTemplateId = action.payload;
48
- },
49
- prepare(templateId) {
50
- return { payload: templateId };
51
- },
52
- },
53
- updateArchiveCardPolicyFetchStatus(draft, action) {
54
- draft.archiveFetchState.fetchState = action.payload.fetchState;
55
- draft.archiveFetchState.error = action.payload.error;
56
- if (action.payload.fetchState === 'Completed') {
57
- if (action.payload.templateId != null) {
58
- draft.templateIds = draft.templateIds.filter((id) => id !== action.payload.templateId);
59
- }
60
- draft.archiveTargetTemplateId = undefined;
61
- }
62
- else if (action.payload.fetchState === 'Error') {
63
- draft.archiveTargetTemplateId = undefined;
64
- }
65
- },
66
- clearCardPolicyList(draft) {
67
- Object.assign(draft, initialState);
68
- },
69
- },
70
- });
71
- export const { fetchCardPolicyList, updateCardPolicyListFetchStatus, archiveCardPolicy, updateArchiveCardPolicyFetchStatus, clearCardPolicyList, } = cardPolicyList.actions;
72
- export default cardPolicyList.reducer;
@@ -1,21 +0,0 @@
1
- import { getCardPolicyStats, getCardPolicyTemplatesByIds, } from '../../../../../entity/cardPolicy/cardPolicySelector';
2
- export function getCardPolicyListView(state) {
3
- const { cardPolicyListState, cardPolicyState } = state;
4
- return {
5
- templates: getCardPolicyTemplatesByIds(cardPolicyState, cardPolicyListState.templateIds),
6
- templateIds: cardPolicyListState.templateIds,
7
- fetchState: cardPolicyListState.fetchState,
8
- archiveFetchState: cardPolicyListState.archiveFetchState,
9
- archiveTargetTemplateId: cardPolicyListState.archiveTargetTemplateId,
10
- stats: getCardPolicyStats(cardPolicyState),
11
- };
12
- }
13
- export function getCardPolicyListFetchState(state) {
14
- return state.cardPolicyListState.fetchState;
15
- }
16
- export function getArchiveCardPolicyFetchState(state) {
17
- return state.cardPolicyListState.archiveFetchState;
18
- }
19
- export function getCardPolicyTemplateIds(state) {
20
- return state.cardPolicyListState.templateIds;
21
- }
@@ -1,56 +0,0 @@
1
- import { from, of } from 'rxjs';
2
- import { catchError, exhaustMap, filter, mergeMap } from 'rxjs/operators';
3
- import { toCardPolicyStats, toCardPolicyTemplateList, } from '../../../../../entity/cardPolicy/cardPolicyPayload';
4
- import { updateCardPolicyStats, updateCardPolicyTemplates, } from '../../../../../entity/cardPolicy/cardPolicyReducer';
5
- import { createZeniAPIStatus, isSuccessStatus, } from '../../../../../responsePayload';
6
- import { fetchCardPolicyList, updateCardPolicyListFetchStatus, } from './cardPolicyListReducer';
7
- /**
8
- * `GET /cards/1.0/policy-templates`. On success the response carries
9
- * both the tenant-wide `stats` block and a `templates[]` array whose
10
- * rows are wrapped in `{data: {cards_applied, template}}` (the same
11
- * envelope the create endpoint returns). We split the result into
12
- * three actions:
13
- *
14
- * 1. `updateCardPolicyTemplates` — full replace of the entity map.
15
- * 2. `updateCardPolicyStats` — entity-level cached stats.
16
- * 3. `updateCardPolicyListFetchStatus` — view lifecycle + ordered IDs.
17
- */
18
- export const fetchCardPolicyListEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchCardPolicyList.match),
19
- // `exhaustMap` (rather than `mergeMap`) so a duplicate
20
- // `fetchCardPolicyList` dispatched while the previous one is still
21
- // in flight is dropped instead of producing a second HTTP request.
22
- // This guards against React 18 StrictMode, which mount-cleanup-
23
- // remounts the screen's mount effect with a stale closure of
24
- // `listFetchState`, causing the same effect to dispatch this
25
- // action twice synchronously. Retry-after-error still works
26
- // because the previous inner observable has completed by the time
27
- // the user retries.
28
- exhaustMap(() => {
29
- return zeniAPI
30
- .getJSON(`${zeniAPI.apiEndPoints.cardMicroServiceBaseUrl}/1.0/policy-templates`)
31
- .pipe(mergeMap((response) => {
32
- if (isSuccessStatus(response) && response.data != null) {
33
- const templates = toCardPolicyTemplateList(response.data);
34
- const stats = toCardPolicyStats(response.data.stats);
35
- const actions = [
36
- updateCardPolicyTemplates(templates),
37
- updateCardPolicyStats(stats),
38
- updateCardPolicyListFetchStatus({
39
- fetchState: 'Completed',
40
- templateIds: templates.map((t) => t.templateId),
41
- }),
42
- ];
43
- return from(actions);
44
- }
45
- else {
46
- return of(updateCardPolicyListFetchStatus({
47
- fetchState: 'Error',
48
- error: response.status,
49
- }));
50
- }
51
- }), catchError((error) => of(updateCardPolicyListFetchStatus({
52
- fetchState: 'Error',
53
- error: createZeniAPIStatus('Unexpected Error', 'Fetch card-policy list REST API call errored out' +
54
- JSON.stringify(error)),
55
- }))));
56
- }));
@@ -1,50 +0,0 @@
1
- import { createSlice } from '@reduxjs/toolkit';
2
- export const initialState = {
3
- createCardPolicyTemplateRequestState: {
4
- fetchState: 'Not-Started',
5
- error: undefined,
6
- },
7
- lastCreatedCardPolicyTemplateId: undefined,
8
- };
9
- const createCardPolicy = createSlice({
10
- name: 'createCardPolicy',
11
- initialState,
12
- reducers: {
13
- /**
14
- * Kick off the `POST /cards/1.0/policy-templates` request. Setting
15
- * the request state to `In-Progress` synchronously here matches how
16
- * every other "create" slice in this repo wires its kickoff
17
- * (see `issueChargeCards`, `fetchChargeCardConfig`, etc.).
18
- *
19
- * The accompanying epic listens for this action, performs the POST,
20
- * dispatches `updateCreatedCardPolicyTemplate` on the entity slice,
21
- * and dispatches `updateCreateCardPolicyTemplateRequestState` here to
22
- * flip the lifecycle to `Completed` or `Error`.
23
- */
24
- createCardPolicyTemplate: {
25
- reducer(draft,
26
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
- _action) {
28
- draft.createCardPolicyTemplateRequestState.fetchState = 'In-Progress';
29
- draft.createCardPolicyTemplateRequestState.error = undefined;
30
- draft.lastCreatedCardPolicyTemplateId = undefined;
31
- },
32
- prepare(request) {
33
- return { payload: request };
34
- },
35
- },
36
- updateCreateCardPolicyTemplateRequestState(draft, action) {
37
- draft.createCardPolicyTemplateRequestState.fetchState =
38
- action.payload.fetchState;
39
- draft.createCardPolicyTemplateRequestState.error = action.payload.error;
40
- if (action.payload.templateId != null) {
41
- draft.lastCreatedCardPolicyTemplateId = action.payload.templateId;
42
- }
43
- },
44
- clearCreateCardPolicy(draft) {
45
- Object.assign(draft, initialState);
46
- },
47
- },
48
- });
49
- export const { createCardPolicyTemplate, updateCreateCardPolicyTemplateRequestState, clearCreateCardPolicy, } = createCardPolicy.actions;
50
- export default createCardPolicy.reducer;
@@ -1,6 +0,0 @@
1
- export function getCreateCardPolicyTemplateRequestState(state) {
2
- return state.createCardPolicyTemplateRequestState;
3
- }
4
- export function getLastCreatedCardPolicyTemplateId(state) {
5
- return state.lastCreatedCardPolicyTemplateId;
6
- }
@@ -1,34 +0,0 @@
1
- import { from, of } from 'rxjs';
2
- import { catchError, filter, mergeMap } from 'rxjs/operators';
3
- import { updateCreatedCardPolicyTemplate } from '../../../../../entity/cardPolicy/cardPolicyReducer';
4
- import { toCreateCardPolicyTemplateRequestBody, } from '../../../../../entity/cardPolicy/cardPolicyPayload';
5
- import { createZeniAPIStatus, isSuccessStatus } from '../../../../../responsePayload';
6
- import { createCardPolicyTemplate, updateCreateCardPolicyTemplateRequestState, } from './createCardPolicyReducer';
7
- export const createCardPolicyTemplateEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(createCardPolicyTemplate.match), mergeMap((action) => {
8
- const body = toCreateCardPolicyTemplateRequestBody(action.payload);
9
- return zeniAPI
10
- .postAndGetJSON(`${zeniAPI.apiEndPoints.cardMicroServiceBaseUrl}/1.0/policy-templates`, body)
11
- .pipe(mergeMap((response) => {
12
- if (isSuccessStatus(response) && response.data != null) {
13
- const { template } = response.data;
14
- const actions = [
15
- updateCreatedCardPolicyTemplate(template),
16
- updateCreateCardPolicyTemplateRequestState({
17
- fetchState: 'Completed',
18
- templateId: template.template_id,
19
- }),
20
- ];
21
- return from(actions);
22
- }
23
- else {
24
- return of(updateCreateCardPolicyTemplateRequestState({
25
- fetchState: 'Error',
26
- error: response.status,
27
- }));
28
- }
29
- }), catchError((error) => of(updateCreateCardPolicyTemplateRequestState({
30
- fetchState: 'Error',
31
- error: createZeniAPIStatus('Unexpected Error', 'Create card-policy template REST API call errored out' +
32
- JSON.stringify(error)),
33
- }))));
34
- }));
@@ -1,25 +0,0 @@
1
- import { from, of } from 'rxjs';
2
- import { catchError, exhaustMap, filter, mergeMap } from 'rxjs/operators';
3
- import { fetchCardPolicyMccCategories, updateCardPolicyMccCategories, updateCardPolicyMccCategoriesFailure, } from '../../../../../entity/cardPolicy/cardPolicyReducer';
4
- import { createZeniAPIStatus, isSuccessStatus, } from '../../../../../responsePayload';
5
- export const fetchCardPolicyMccCategoriesEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchCardPolicyMccCategories.match),
6
- // `exhaustMap` (rather than `mergeMap`) so a duplicate
7
- // `fetchCardPolicyMccCategories` dispatched while the previous one
8
- // is still in flight is dropped instead of producing a second HTTP
9
- // request. Both the Create and Edit policy screens dispatch this
10
- // on mount, and React 18 StrictMode invokes their mount effect
11
- // twice with a stale `mccCategoriesFetchState` closure — without
12
- // `exhaustMap` that yields two `/cards/mcc-codes` calls.
13
- exhaustMap(() => {
14
- return zeniAPI
15
- .getJSON(`${zeniAPI.apiEndPoints.cardMicroServiceBaseUrl}/1.0/cards/mcc-codes`)
16
- .pipe(mergeMap((response) => {
17
- if (isSuccessStatus(response) && response.data != null) {
18
- return from([updateCardPolicyMccCategories(response.data)]);
19
- }
20
- else {
21
- return of(updateCardPolicyMccCategoriesFailure(response.status));
22
- }
23
- }), catchError((error) => of(updateCardPolicyMccCategoriesFailure(createZeniAPIStatus('Unexpected Error', 'Fetch card policy MCC categories REST API call errored out' +
24
- JSON.stringify(error))))));
25
- }));
@@ -1,14 +0,0 @@
1
- import { FetchState } from '../../../../../commonStateTypes/common';
2
- import { CreateCardPolicyTemplateRequest } from '../../../../../entity/cardPolicy/cardPolicyPayload';
3
- import { ZeniAPIStatus } from '../../../../../responsePayload';
4
- import { CardPolicyDetailState } from './cardPolicyDetailState';
5
- export declare const initialState: CardPolicyDetailState;
6
- export declare const fetchCardPolicyDetail: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[templateId: string], string, "cardPolicyDetail/fetchCardPolicyDetail", never, never>, updateCardPolicyDetailFetchStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
7
- fetchState: FetchState;
8
- error?: ZeniAPIStatus;
9
- }, "cardPolicyDetail/updateCardPolicyDetailFetchStatus">, updateCardPolicyFormDraft: import("@reduxjs/toolkit").ActionCreatorWithPayload<CreateCardPolicyTemplateRequest, "cardPolicyDetail/updateCardPolicyFormDraft">, updateCardPolicy: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[templateId: string], string, "cardPolicyDetail/updateCardPolicy", never, never>, updateCardPolicyFetchStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
10
- fetchState: FetchState;
11
- error?: ZeniAPIStatus;
12
- }, "cardPolicyDetail/updateCardPolicyFetchStatus">, clearCardPolicyDetail: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"cardPolicyDetail/clearCardPolicyDetail">;
13
- declare const _default: import("redux").Reducer<CardPolicyDetailState>;
14
- export default _default;
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.clearCardPolicyDetail = exports.updateCardPolicyFetchStatus = exports.updateCardPolicy = exports.updateCardPolicyFormDraft = exports.updateCardPolicyDetailFetchStatus = exports.fetchCardPolicyDetail = exports.initialState = void 0;
5
- const toolkit_1 = require("@reduxjs/toolkit");
6
- exports.initialState = {
7
- detailTemplateId: undefined,
8
- detailFetchState: { fetchState: 'Not-Started', error: undefined },
9
- updateFetchState: { fetchState: 'Not-Started', error: undefined },
10
- formDraft: undefined,
11
- };
12
- const cardPolicyDetail = (0, toolkit_1.createSlice)({
13
- name: 'cardPolicyDetail',
14
- initialState: exports.initialState,
15
- reducers: {
16
- /**
17
- * Kick off the `GET /cards/1.0/policy-templates/{id}` request. The
18
- * accompanying epic dispatches `updateCreatedCardPolicyTemplate` on
19
- * the entity slice + `updateCardPolicyFormDraft` (seeded from the
20
- * template) + `updateCardPolicyDetailFetchStatus` here.
21
- */
22
- fetchCardPolicyDetail: {
23
- reducer(draft, action) {
24
- draft.detailTemplateId = action.payload;
25
- draft.detailFetchState.fetchState = 'In-Progress';
26
- draft.detailFetchState.error = undefined;
27
- // Reset the draft so a stale form from a previous template
28
- // doesn't leak into the new edit session.
29
- draft.formDraft = undefined;
30
- },
31
- prepare(templateId) {
32
- return { payload: templateId };
33
- },
34
- },
35
- updateCardPolicyDetailFetchStatus(draft, action) {
36
- draft.detailFetchState.fetchState = action.payload.fetchState;
37
- draft.detailFetchState.error = action.payload.error;
38
- },
39
- /**
40
- * Replace (or seed) the local edit-form draft. Dispatched by the
41
- * detail-fetch epic with the camelCased values pulled from the
42
- * fetched template, and by the edit page itself as the user types.
43
- */
44
- updateCardPolicyFormDraft(draft, action) {
45
- draft.formDraft = action.payload;
46
- },
47
- /**
48
- * Kick off the `PUT /cards/1.0/policy-templates/{id}` save. The
49
- * epic reads the current `formDraft` from state, posts the wire
50
- * body, then dispatches `updateCreatedCardPolicyTemplate` (entity)
51
- * + `updateCardPolicyFetchStatus({fetchState: 'Completed'})` here.
52
- */
53
- updateCardPolicy: {
54
- reducer(draft,
55
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
56
- _action) {
57
- draft.updateFetchState.fetchState = 'In-Progress';
58
- draft.updateFetchState.error = undefined;
59
- },
60
- prepare(templateId) {
61
- return { payload: templateId };
62
- },
63
- },
64
- updateCardPolicyFetchStatus(draft, action) {
65
- draft.updateFetchState.fetchState = action.payload.fetchState;
66
- draft.updateFetchState.error = action.payload.error;
67
- },
68
- clearCardPolicyDetail(draft) {
69
- Object.assign(draft, exports.initialState);
70
- },
71
- },
72
- });
73
- _a = cardPolicyDetail.actions, exports.fetchCardPolicyDetail = _a.fetchCardPolicyDetail, exports.updateCardPolicyDetailFetchStatus = _a.updateCardPolicyDetailFetchStatus, exports.updateCardPolicyFormDraft = _a.updateCardPolicyFormDraft, exports.updateCardPolicy = _a.updateCardPolicy, exports.updateCardPolicyFetchStatus = _a.updateCardPolicyFetchStatus, exports.clearCardPolicyDetail = _a.clearCardPolicyDetail;
74
- exports.default = cardPolicyDetail.reducer;
@@ -1,21 +0,0 @@
1
- import { FetchStateAndError, ID } from '../../../../../commonStateTypes/common';
2
- import { CreateCardPolicyTemplateRequest } from '../../../../../entity/cardPolicy/cardPolicyPayload';
3
- import { CardPolicyTemplate } from '../../../../../entity/cardPolicy/cardPolicyState';
4
- import { RootState } from '../../../../../reducer';
5
- /**
6
- * Composite view returned by `getCardPolicyDetailView` — the only
7
- * public shape the Card Policy edit page should consume. Mirrors how
8
- * `chargeCardDetailSelector` joins the view-side lifecycle slots with
9
- * the entity-store template.
10
- */
11
- export interface CardPolicyDetailSelectorView {
12
- detailFetchState: FetchStateAndError;
13
- updateFetchState: FetchStateAndError;
14
- formDraft?: CreateCardPolicyTemplateRequest;
15
- template?: CardPolicyTemplate;
16
- templateId?: ID;
17
- }
18
- export declare function getCardPolicyDetailView(state: RootState): CardPolicyDetailSelectorView;
19
- export declare function getCardPolicyFormDraft(state: RootState): CreateCardPolicyTemplateRequest | undefined;
20
- export declare function getCardPolicyDetailFetchState(state: RootState): FetchStateAndError;
21
- export declare function getUpdateCardPolicyFetchState(state: RootState): FetchStateAndError;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCardPolicyDetailView = getCardPolicyDetailView;
4
- exports.getCardPolicyFormDraft = getCardPolicyFormDraft;
5
- exports.getCardPolicyDetailFetchState = getCardPolicyDetailFetchState;
6
- exports.getUpdateCardPolicyFetchState = getUpdateCardPolicyFetchState;
7
- const cardPolicySelector_1 = require("../../../../../entity/cardPolicy/cardPolicySelector");
8
- function getCardPolicyDetailView(state) {
9
- const { cardPolicyDetailState, cardPolicyState } = state;
10
- return {
11
- templateId: cardPolicyDetailState.detailTemplateId,
12
- template: cardPolicyDetailState.detailTemplateId != null
13
- ? (0, cardPolicySelector_1.getCardPolicyTemplateById)(cardPolicyState, cardPolicyDetailState.detailTemplateId)
14
- : undefined,
15
- formDraft: cardPolicyDetailState.formDraft,
16
- detailFetchState: cardPolicyDetailState.detailFetchState,
17
- updateFetchState: cardPolicyDetailState.updateFetchState,
18
- };
19
- }
20
- function getCardPolicyFormDraft(state) {
21
- return state.cardPolicyDetailState.formDraft;
22
- }
23
- function getCardPolicyDetailFetchState(state) {
24
- return state.cardPolicyDetailState.detailFetchState;
25
- }
26
- function getUpdateCardPolicyFetchState(state) {
27
- return state.cardPolicyDetailState.updateFetchState;
28
- }
@@ -1,25 +0,0 @@
1
- import { FetchStateAndError, ID } from '../../../../../commonStateTypes/common';
2
- import { CreateCardPolicyTemplateRequest } from '../../../../../entity/cardPolicy/cardPolicyPayload';
3
- /**
4
- * View-side state for the Card Policy edit page.
5
- *
6
- * Mirrors `issueChargeCard` (a single page that owns a local form
7
- * draft + commits on save). There is no separate read-only "detail"
8
- * surface today — the same page loads the existing template and offers
9
- * inline edits. The saved template itself lives on the entity slice;
10
- * the page joins via `getCardPolicyDetailView`.
11
- */
12
- export interface CardPolicyDetailState {
13
- /** Lifecycle for the initial `GET /policy-templates/{id}` request. */
14
- detailFetchState: FetchStateAndError;
15
- /** Lifecycle for the `PUT /policy-templates/{id}` save. */
16
- updateFetchState: FetchStateAndError;
17
- /** Template currently being edited; cleared when the page unmounts. */
18
- detailTemplateId?: ID;
19
- /**
20
- * Local form draft seeded from the entity template on fetch success
21
- * and mutated as the user edits. `undefined` until the detail fetch
22
- * lands so the page can render a skeleton until then.
23
- */
24
- formDraft?: CreateCardPolicyTemplateRequest;
25
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,19 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { Observable } from 'rxjs';
3
- import { updateCreatedCardPolicyTemplate } from '../../../../../entity/cardPolicy/cardPolicyReducer';
4
- import { RootState } from '../../../../../reducer';
5
- import { ZeniAPI } from '../../../../../zeniAPI';
6
- import { fetchCardPolicyDetail, updateCardPolicyDetailFetchStatus, updateCardPolicyFormDraft } from './cardPolicyDetailReducer';
7
- export type ActionType = ReturnType<typeof fetchCardPolicyDetail> | ReturnType<typeof updateCreatedCardPolicyTemplate> | ReturnType<typeof updateCardPolicyFormDraft> | ReturnType<typeof updateCardPolicyDetailFetchStatus>;
8
- /**
9
- * `GET /cards/1.0/policy-templates/{id}`. Response is the same
10
- * `{cards_applied, template}` envelope the create endpoint returns.
11
- * We:
12
- *
13
- * 1. Cache the template on the entity slice (so the list page picks
14
- * up any drift from the server).
15
- * 2. Seed the local edit-form draft from the camelCased template so
16
- * the page can render with the existing values pre-populated.
17
- * 3. Flip the view lifecycle to `Completed` / `Error`.
18
- */
19
- export declare const fetchCardPolicyDetailEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchCardPolicyDetailEpic = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- const cardPolicyPayload_1 = require("../../../../../entity/cardPolicy/cardPolicyPayload");
7
- const cardPolicyReducer_1 = require("../../../../../entity/cardPolicy/cardPolicyReducer");
8
- const responsePayload_1 = require("../../../../../responsePayload");
9
- const cardPolicyDetailReducer_1 = require("./cardPolicyDetailReducer");
10
- /**
11
- * `GET /cards/1.0/policy-templates/{id}`. Response is the same
12
- * `{cards_applied, template}` envelope the create endpoint returns.
13
- * We:
14
- *
15
- * 1. Cache the template on the entity slice (so the list page picks
16
- * up any drift from the server).
17
- * 2. Seed the local edit-form draft from the camelCased template so
18
- * the page can render with the existing values pre-populated.
19
- * 3. Flip the view lifecycle to `Completed` / `Error`.
20
- */
21
- const fetchCardPolicyDetailEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(cardPolicyDetailReducer_1.fetchCardPolicyDetail.match),
22
- // `exhaustMap` (rather than `mergeMap`) so a duplicate
23
- // `fetchCardPolicyDetail` dispatched while the previous one is
24
- // still in flight is dropped instead of producing a second HTTP
25
- // request. The edit screen dispatches this on mount, and React 18
26
- // StrictMode invokes its mount effect twice with a stale
27
- // `detailFetchState` closure — without `exhaustMap` that yields
28
- // two `/policy-templates/{id}` calls. (The screen also dedupes
29
- // list→edit navigations via the entity-cached template, so the
30
- // detail GET is only emitted on direct landings — there's no
31
- // realistic cross-templateId scenario that needs cancel-and-retry
32
- // semantics here.)
33
- (0, operators_1.exhaustMap)((action) => {
34
- const templateId = action.payload;
35
- return zeniAPI
36
- .getJSON(`${zeniAPI.apiEndPoints.cardMicroServiceBaseUrl}/1.0/policy-templates/${templateId}`)
37
- .pipe((0, operators_1.mergeMap)((response) => {
38
- if ((0, responsePayload_1.isSuccessStatus)(response) && response.data != null) {
39
- const { template } = response.data;
40
- const formDraft = (0, cardPolicyPayload_1.toCardPolicyEditFormDraft)((0, cardPolicyPayload_1.toCardPolicyTemplate)(template));
41
- const actions = [
42
- (0, cardPolicyReducer_1.updateCreatedCardPolicyTemplate)(template),
43
- (0, cardPolicyDetailReducer_1.updateCardPolicyFormDraft)(formDraft),
44
- (0, cardPolicyDetailReducer_1.updateCardPolicyDetailFetchStatus)({ fetchState: 'Completed' }),
45
- ];
46
- return (0, rxjs_1.from)(actions);
47
- }
48
- else {
49
- return (0, rxjs_1.of)((0, cardPolicyDetailReducer_1.updateCardPolicyDetailFetchStatus)({
50
- fetchState: 'Error',
51
- error: response.status,
52
- }));
53
- }
54
- }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, cardPolicyDetailReducer_1.updateCardPolicyDetailFetchStatus)({
55
- fetchState: 'Error',
56
- error: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Fetch card-policy detail REST API call errored out' +
57
- JSON.stringify(error)),
58
- }))));
59
- }));
60
- exports.fetchCardPolicyDetailEpic = fetchCardPolicyDetailEpic;
@@ -1,18 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { Observable } from 'rxjs';
3
- import { updateCreatedCardPolicyTemplate } from '../../../../../entity/cardPolicy/cardPolicyReducer';
4
- import { RootState } from '../../../../../reducer';
5
- import { ZeniAPI } from '../../../../../zeniAPI';
6
- import { updateCardPolicy, updateCardPolicyFetchStatus } from './cardPolicyDetailReducer';
7
- export type ActionType = ReturnType<typeof updateCardPolicy> | ReturnType<typeof updateCreatedCardPolicyTemplate> | ReturnType<typeof updateCardPolicyFetchStatus>;
8
- /**
9
- * `PUT /cards/1.0/policy-templates/{id}`. Reads the current `formDraft`
10
- * off the `cardPolicyDetail` slice, converts it to the snake_case wire
11
- * body (same shape as create), and submits. On success the entity
12
- * slice picks up the refreshed template and the view lifecycle flips
13
- * to `Completed`.
14
- *
15
- * If the action fires before a draft is seeded (e.g. user clicks save
16
- * before the detail fetch lands), we short-circuit with an Error.
17
- */
18
- export declare const updateCardPolicyEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;