@zeniai/client-epic-state 5.0.82 → 5.0.83-betaRR1

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 (142) hide show
  1. package/lib/common/aiCfo/aiCfoSuggestedQuestionsPageContext.d.ts +1 -1
  2. package/lib/entity/aiCfo/aiCfoPayload.d.ts +140 -1
  3. package/lib/entity/aiCfo/aiCfoReducer.d.ts +23 -2
  4. package/lib/entity/aiCfo/aiCfoReducer.js +328 -5
  5. package/lib/entity/aiCfo/aiCfoSelector.d.ts +13 -1
  6. package/lib/entity/aiCfo/aiCfoSelector.js +28 -1
  7. package/lib/entity/aiCfo/aiCfoState.d.ts +225 -4
  8. package/lib/entity/aiCfo/aiCfoState.js +30 -1
  9. package/lib/entity/cardPolicy/cardPolicyPayload.d.ts +277 -0
  10. package/lib/entity/cardPolicy/cardPolicyPayload.js +143 -0
  11. package/lib/entity/cardPolicy/cardPolicyReducer.d.ts +19 -0
  12. package/lib/entity/cardPolicy/cardPolicyReducer.js +175 -0
  13. package/lib/entity/cardPolicy/cardPolicySelector.d.ts +32 -0
  14. package/lib/entity/cardPolicy/cardPolicySelector.js +99 -0
  15. package/lib/entity/cardPolicy/cardPolicyState.d.ts +205 -0
  16. package/lib/entity/cardPolicy/cardPolicyState.js +14 -0
  17. package/lib/entity/cardPolicy/extractPolicyDocumentEpic.d.ts +18 -0
  18. package/lib/entity/cardPolicy/extractPolicyDocumentEpic.js +68 -0
  19. package/lib/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.d.ts +26 -0
  20. package/lib/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.js +47 -0
  21. package/lib/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.d.ts +25 -0
  22. package/lib/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.js +39 -0
  23. package/lib/entity/cardPolicy/policyRecommendationFromUploadEpic.d.ts +23 -0
  24. package/lib/entity/cardPolicy/policyRecommendationFromUploadEpic.js +104 -0
  25. package/lib/entity/jeSchedules/jeSchedulesTypes.d.ts +1 -1
  26. package/lib/entity/monthEndCloseChecks/monthEndCloseChecksState.d.ts +1 -1
  27. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  28. package/lib/entity/snackbar/snackbarTypes.js +3 -0
  29. package/lib/entity/tenant/clearAllEpic.d.ts +6 -2
  30. package/lib/entity/tenant/clearAllEpic.js +8 -0
  31. package/lib/epic.d.ts +11 -1
  32. package/lib/epic.js +11 -1
  33. package/lib/esm/entity/aiCfo/aiCfoReducer.js +328 -5
  34. package/lib/esm/entity/aiCfo/aiCfoSelector.js +26 -1
  35. package/lib/esm/entity/aiCfo/aiCfoState.js +27 -0
  36. package/lib/esm/entity/cardPolicy/cardPolicyPayload.js +130 -0
  37. package/lib/esm/entity/cardPolicy/cardPolicyReducer.js +171 -0
  38. package/lib/esm/entity/cardPolicy/cardPolicySelector.js +75 -0
  39. package/lib/esm/entity/cardPolicy/cardPolicyState.js +9 -0
  40. package/lib/esm/entity/cardPolicy/extractPolicyDocumentEpic.js +64 -0
  41. package/lib/esm/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.js +43 -0
  42. package/lib/esm/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.js +35 -0
  43. package/lib/esm/entity/cardPolicy/policyRecommendationFromUploadEpic.js +100 -0
  44. package/lib/esm/entity/snackbar/snackbarTypes.js +3 -0
  45. package/lib/esm/entity/tenant/clearAllEpic.js +8 -0
  46. package/lib/esm/epic.js +11 -1
  47. package/lib/esm/index.js +27 -8
  48. package/lib/esm/reducer.js +12 -0
  49. package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +6 -3
  50. package/lib/esm/view/aiCfoView/epics/createSessionAndSubmitEpic.js +5 -2
  51. package/lib/esm/view/aiCfoView/epics/createSessionEpic.js +2 -1
  52. package/lib/esm/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +12 -2
  53. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.js +70 -0
  54. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.js +22 -0
  55. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.js +1 -0
  56. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.js +56 -0
  57. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.js +49 -0
  58. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.js +42 -0
  59. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.js +72 -0
  60. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.js +21 -0
  61. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.js +1 -0
  62. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.js +56 -0
  63. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +45 -0
  64. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +39 -0
  65. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.js +1 -0
  66. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.js +53 -0
  67. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.js +25 -0
  68. package/lib/esm/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +25 -0
  69. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/aiCardCreationFormDraftTypes.js +1 -0
  70. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/applyAiCardCreationFormDraftUpdate.js +20 -0
  71. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/buildAiCardCreationFormDraftSeed.js +62 -0
  72. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/deriveAiCardRowsFromTeams.js +47 -0
  73. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardEpic.js +2 -2
  74. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.js +48 -4
  75. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.js +61 -0
  76. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/toIssueChargeCardLocalDataFromDraft.js +69 -0
  77. package/lib/index.d.ts +26 -8
  78. package/lib/index.js +141 -13
  79. package/lib/reducer.d.ts +12 -0
  80. package/lib/reducer.js +12 -0
  81. package/lib/view/aiCfoView/aiCfoViewReducer.d.ts +11 -2
  82. package/lib/view/aiCfoView/aiCfoViewReducer.js +6 -3
  83. package/lib/view/aiCfoView/epics/createSessionAndSubmitEpic.js +5 -2
  84. package/lib/view/aiCfoView/epics/createSessionEpic.js +2 -1
  85. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.d.ts +8 -1
  86. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +12 -2
  87. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  88. package/lib/view/expenseAutomationView/types/reconciliationViewState.d.ts +1 -1
  89. package/lib/view/people/peopleTypes.d.ts +1 -1
  90. package/lib/view/scheduleView/scheduleListView/scheduleListTypes.d.ts +1 -1
  91. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.d.ts +14 -0
  92. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.js +74 -0
  93. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.d.ts +21 -0
  94. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.js +28 -0
  95. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.d.ts +25 -0
  96. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.js +2 -0
  97. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.d.ts +19 -0
  98. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.js +60 -0
  99. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.d.ts +18 -0
  100. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.js +53 -0
  101. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.d.ts +16 -0
  102. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.js +46 -0
  103. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.d.ts +15 -0
  104. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.js +76 -0
  105. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.d.ts +21 -0
  106. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.js +27 -0
  107. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.d.ts +19 -0
  108. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.js +2 -0
  109. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.d.ts +19 -0
  110. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.js +60 -0
  111. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.d.ts +13 -0
  112. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +49 -0
  113. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.d.ts +32 -0
  114. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +46 -0
  115. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.d.ts +45 -0
  116. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.js +2 -0
  117. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.d.ts +25 -0
  118. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.js +57 -0
  119. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.d.ts +15 -0
  120. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.js +29 -0
  121. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.d.ts +1 -1
  122. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.d.ts +14 -0
  123. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +27 -1
  124. package/lib/view/spendManagement/chargeCards/issueChargeCard/aiCardCreationFormDraftTypes.d.ts +79 -0
  125. package/lib/view/spendManagement/chargeCards/issueChargeCard/aiCardCreationFormDraftTypes.js +2 -0
  126. package/lib/view/spendManagement/chargeCards/issueChargeCard/applyAiCardCreationFormDraftUpdate.d.ts +6 -0
  127. package/lib/view/spendManagement/chargeCards/issueChargeCard/applyAiCardCreationFormDraftUpdate.js +24 -0
  128. package/lib/view/spendManagement/chargeCards/issueChargeCard/buildAiCardCreationFormDraftSeed.d.ts +25 -0
  129. package/lib/view/spendManagement/chargeCards/issueChargeCard/buildAiCardCreationFormDraftSeed.js +66 -0
  130. package/lib/view/spendManagement/chargeCards/issueChargeCard/deriveAiCardRowsFromTeams.d.ts +26 -0
  131. package/lib/view/spendManagement/chargeCards/issueChargeCard/deriveAiCardRowsFromTeams.js +51 -0
  132. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardEpic.d.ts +2 -2
  133. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardEpic.js +1 -1
  134. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.d.ts +12 -2
  135. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.js +49 -5
  136. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.d.ts +42 -0
  137. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.js +68 -1
  138. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardState.d.ts +18 -0
  139. package/lib/view/spendManagement/chargeCards/issueChargeCard/toIssueChargeCardLocalDataFromDraft.d.ts +11 -0
  140. package/lib/view/spendManagement/chargeCards/issueChargeCard/toIssueChargeCardLocalDataFromDraft.js +73 -0
  141. package/lib/view/taskManager/taskListView/taskListReducer.d.ts +1 -1
  142. package/package.json +1 -1
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { AiCardCreationFormDraftSeedContext, CardsFormDraft } from './aiCardCreationFormDraftTypes';
2
+ export interface ApplyAiCardCreationFormDraftUpdateArgs {
3
+ context: AiCardCreationFormDraftSeedContext | undefined;
4
+ next: CardsFormDraft;
5
+ }
6
+ export declare const applyAiCardCreationFormDraftUpdate: ({ next, context, }: ApplyAiCardCreationFormDraftUpdateArgs) => CardsFormDraft;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyAiCardCreationFormDraftUpdate = void 0;
4
+ const deriveAiCardRowsFromTeams_1 = require("./deriveAiCardRowsFromTeams");
5
+ // Single source of truth for "what the next form draft should look like
6
+ // after a watchHandler flush". `create` mode + missing context keep the
7
+ // payload as-is; `review` mode re-derives step-2 cardRows from the latest
8
+ // teamRows, preserving in-place edits via prevCardRows.
9
+ const applyAiCardCreationFormDraftUpdate = ({ next, context, }) => {
10
+ if (context == null || context.mode === 'create') {
11
+ return next;
12
+ }
13
+ return {
14
+ teamRows: next.teamRows,
15
+ cardRows: (0, deriveAiCardRowsFromTeams_1.deriveAiCardRowsFromTeams)({
16
+ teamRows: next.teamRows,
17
+ prevCardRows: next.cardRows,
18
+ allUsers: context.allUsers,
19
+ defaultCardOptionId: context.defaultCardOptionId,
20
+ suggestedOwnerUserIdByTeamId: context.suggestedOwnerUserIdByTeamId,
21
+ }),
22
+ };
23
+ };
24
+ exports.applyAiCardCreationFormDraftUpdate = applyAiCardCreationFormDraftUpdate;
@@ -0,0 +1,25 @@
1
+ import { CardsCreationInitialData } from '../../../../entity/aiCfo/aiCfoState';
2
+ import { User } from '../../../../entity/user/userState';
3
+ import { AiCardCreationFormDraftSeedContext, CardsFormDraft } from './aiCardCreationFormDraftTypes';
4
+ export interface BuildAiCardCreationFormDraftSeedArgs {
5
+ allUsers: User[];
6
+ initialData: CardsCreationInitialData;
7
+ }
8
+ export interface BuildAiCardCreationFormDraftSeedResult {
9
+ context: AiCardCreationFormDraftSeedContext;
10
+ draft: CardsFormDraft;
11
+ }
12
+ /**
13
+ * Build the initial `CardsFormDraft` + companion seed context for a
14
+ * fresh AI card-creation session. Used by the `seedAiCardCreationFormDraft`
15
+ * reducer.
16
+ *
17
+ * Branches on `initialData.mode`:
18
+ * - `review`: step-1 team rows start fully checked. Step-2 `cardRows`
19
+ * is left empty — `deriveAiCardRowsFromTeams` materializes it on
20
+ * subsequent `updateAiCardCreationFormDraft` dispatches.
21
+ * - `create`: no step-1 list — seed `cardRows` directly from the AI's
22
+ * suggested cards (resolving owners via `allUsers`) and leave
23
+ * `teamRows` empty.
24
+ */
25
+ export declare const buildAiCardCreationFormDraftSeed: ({ initialData, allUsers, }: BuildAiCardCreationFormDraftSeedArgs) => BuildAiCardCreationFormDraftSeedResult;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildAiCardCreationFormDraftSeed = void 0;
4
+ /**
5
+ * Build the initial `CardsFormDraft` + companion seed context for a
6
+ * fresh AI card-creation session. Used by the `seedAiCardCreationFormDraft`
7
+ * reducer.
8
+ *
9
+ * Branches on `initialData.mode`:
10
+ * - `review`: step-1 team rows start fully checked. Step-2 `cardRows`
11
+ * is left empty — `deriveAiCardRowsFromTeams` materializes it on
12
+ * subsequent `updateAiCardCreationFormDraft` dispatches.
13
+ * - `create`: no step-1 list — seed `cardRows` directly from the AI's
14
+ * suggested cards (resolving owners via `allUsers`) and leave
15
+ * `teamRows` empty.
16
+ */
17
+ const buildAiCardCreationFormDraftSeed = ({ initialData, allUsers, }) => {
18
+ const context = {
19
+ allUsers,
20
+ defaultCardOptionId: initialData.cardOptions[0]?.id,
21
+ mode: initialData.mode,
22
+ suggestedOwnerUserIdByTeamId: initialData.suggestedOwnerUserIdByTeamId,
23
+ };
24
+ if (initialData.mode === 'create') {
25
+ return {
26
+ context,
27
+ draft: {
28
+ teamRows: [],
29
+ cardRows: initialData.cardRows.map((seed) => buildCardRowFromSeed(seed, allUsers)),
30
+ },
31
+ };
32
+ }
33
+ const teamRows = initialData.teamRows.map((row) => ({
34
+ cardKind: row.cardKind,
35
+ id: row.id,
36
+ isChecked: true,
37
+ label: row.label,
38
+ value: row.avgMonthlySpend,
39
+ rightLabel: row.recommendedLimit,
40
+ rightSubLabel: row.recommendedLimitCadence,
41
+ }));
42
+ return {
43
+ context,
44
+ draft: {
45
+ teamRows,
46
+ cardRows: [],
47
+ },
48
+ };
49
+ };
50
+ exports.buildAiCardCreationFormDraftSeed = buildAiCardCreationFormDraftSeed;
51
+ const buildCardRowFromSeed = (seed, allUsers) => {
52
+ const selectedUser = seed.suggestedOwnerUserId != null
53
+ ? allUsers.find((user) => user.userId === seed.suggestedOwnerUserId)
54
+ : undefined;
55
+ return {
56
+ cardKind: seed.cardKind,
57
+ id: seed.id,
58
+ label: seed.label,
59
+ cardOptionId: seed.cardOptionId,
60
+ owner: {
61
+ allUsers,
62
+ selectedUser,
63
+ },
64
+ recommendedLimit: seed.recommendedLimit,
65
+ };
66
+ };
@@ -0,0 +1,26 @@
1
+ import { User } from '../../../../entity/user/userState';
2
+ import { CardsCardRow, CardsTeamRow } from './aiCardCreationFormDraftTypes';
3
+ export interface DeriveAiCardRowsFromTeamsArgs {
4
+ allUsers: User[];
5
+ /** First card option id; used as the per-row default when nothing else applies. */
6
+ defaultCardOptionId: string | undefined;
7
+ /** Map of teamId -> suggested owner userId surfaced by the AI. */
8
+ suggestedOwnerUserIdByTeamId: Record<string, string | undefined>;
9
+ teamRows: CardsTeamRow[];
10
+ /** Existing step-2 rows; preserved row-for-row when the team is still checked. */
11
+ prevCardRows?: CardsCardRow[];
12
+ }
13
+ /**
14
+ * Derive the step-2 `cardRows` from the user's step-1 team selection.
15
+ *
16
+ * Behaviour:
17
+ * - One output row per `teamRow.isChecked === true`, in the same order.
18
+ * - When a team is still checked AND we have a previous row for it, the
19
+ * previous row is preserved verbatim — so user edits made in step 2
20
+ * aren't blown away when an upstream watchHandler re-derives.
21
+ * - Newly-included teams fall back to:
22
+ * - `cardOptionId = defaultCardOptionId`
23
+ * - `selectedUser = the User whose userId === suggestedOwnerUserIdByTeamId[teamId]`
24
+ * - `recommendedLimit = numeric parse of `teamRow.rightLabel` (e.g. "$20,000")`
25
+ */
26
+ export declare const deriveAiCardRowsFromTeams: ({ teamRows, prevCardRows, allUsers, defaultCardOptionId, suggestedOwnerUserIdByTeamId, }: DeriveAiCardRowsFromTeamsArgs) => CardsCardRow[];
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deriveAiCardRowsFromTeams = void 0;
4
+ /**
5
+ * Derive the step-2 `cardRows` from the user's step-1 team selection.
6
+ *
7
+ * Behaviour:
8
+ * - One output row per `teamRow.isChecked === true`, in the same order.
9
+ * - When a team is still checked AND we have a previous row for it, the
10
+ * previous row is preserved verbatim — so user edits made in step 2
11
+ * aren't blown away when an upstream watchHandler re-derives.
12
+ * - Newly-included teams fall back to:
13
+ * - `cardOptionId = defaultCardOptionId`
14
+ * - `selectedUser = the User whose userId === suggestedOwnerUserIdByTeamId[teamId]`
15
+ * - `recommendedLimit = numeric parse of `teamRow.rightLabel` (e.g. "$20,000")`
16
+ */
17
+ const deriveAiCardRowsFromTeams = ({ teamRows, prevCardRows = [], allUsers, defaultCardOptionId, suggestedOwnerUserIdByTeamId, }) => {
18
+ const prevById = new Map(prevCardRows.map((row) => [row.id, row]));
19
+ const userById = new Map(allUsers.map((user) => [user.userId, user]));
20
+ return teamRows
21
+ .filter((row) => row.isChecked)
22
+ .map((teamRow) => {
23
+ const previous = prevById.get(teamRow.id);
24
+ if (previous != null) {
25
+ return previous;
26
+ }
27
+ const suggestedUserId = suggestedOwnerUserIdByTeamId[teamRow.id];
28
+ const selectedUser = suggestedUserId != null ? userById.get(suggestedUserId) : undefined;
29
+ return {
30
+ cardKind: teamRow.cardKind,
31
+ id: teamRow.id,
32
+ label: teamRow.label,
33
+ cardOptionId: defaultCardOptionId ?? '',
34
+ owner: {
35
+ allUsers,
36
+ selectedUser,
37
+ },
38
+ recommendedLimit: parseLimitToFloat(teamRow.rightLabel),
39
+ };
40
+ });
41
+ };
42
+ exports.deriveAiCardRowsFromTeams = deriveAiCardRowsFromTeams;
43
+ // Best-effort numeric parse of an AI-provided limit string like "$20,000".
44
+ const parseLimitToFloat = (raw) => {
45
+ const cleaned = raw.replace(/[^0-9.-]/g, '');
46
+ if (cleaned.length === 0) {
47
+ return undefined;
48
+ }
49
+ const parsed = Number(cleaned);
50
+ return Number.isFinite(parsed) ? parsed : undefined;
51
+ };
@@ -8,6 +8,6 @@ import { updateUserRoles } from '../../../../entity/userRole/userRoleReducer';
8
8
  import { RootState } from '../../../../reducer';
9
9
  import { ZeniAPI } from '../../../../zeniAPI';
10
10
  import { updateChargeCardList } from '../chargeCardList/chargeCardListReducer';
11
- import { issueChargeCardSuccessOrFailure, issueChargeCards, updateChargeCardCount, updateDebitCardCount, updateLastSelfIssuedDebitCardId } from './issueChargeCardReducer';
12
- export type ActionType = ReturnType<typeof issueChargeCards> | ReturnType<typeof updateChargeCards> | ReturnType<typeof updateAllUsers> | ReturnType<typeof updateUserRoles> | ReturnType<typeof openSnackbar> | ReturnType<typeof updateChargeCardList> | ReturnType<typeof updateChargeCardCount> | ReturnType<typeof updateDebitCardCount> | ReturnType<typeof updateLastSelfIssuedDebitCardId> | ReturnType<typeof issueChargeCardSuccessOrFailure> | ReturnType<typeof updateAddresses>;
11
+ import { issueChargeCardSuccessOrFailure, issueChargeCards, updateChargeCardCount, updateDebitCardCount, updateLastIssuedCardIds, updateLastSelfIssuedDebitCardId } from './issueChargeCardReducer';
12
+ export type ActionType = ReturnType<typeof issueChargeCards> | ReturnType<typeof updateChargeCards> | ReturnType<typeof updateAllUsers> | ReturnType<typeof updateUserRoles> | ReturnType<typeof openSnackbar> | ReturnType<typeof updateChargeCardList> | ReturnType<typeof updateChargeCardCount> | ReturnType<typeof updateDebitCardCount> | ReturnType<typeof updateLastSelfIssuedDebitCardId> | ReturnType<typeof updateLastIssuedCardIds> | ReturnType<typeof issueChargeCardSuccessOrFailure> | ReturnType<typeof updateAddresses>;
13
13
  export declare const issueChargeCardEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -90,7 +90,7 @@ const issueChargeCardEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, ope
90
90
  actions.push((0, chargeCardReducer_1.updateChargeCards)(issuedCards), (0, userReducer_1.updateAllUsers)({ users: response.data.users }), (0, userRoleReducer_1.updateUserRoles)(response.data.user_roles), (0, chargeCardListReducer_1.updateChargeCardList)({
91
91
  chargeCardListPayload: response.data,
92
92
  keepExistingListItems: true,
93
- }), (0, addressReducer_1.updateAddresses)(response.data.addresses), (0, issueChargeCardReducer_1.updateChargeCardCount)(response.data?.cards_count_by_user_id ?? []), (0, issueChargeCardReducer_1.updateDebitCardCount)(response.data?.debit_cards_count_by_deposit_account_id ?? {}), (0, issueChargeCardReducer_1.issueChargeCardSuccessOrFailure)({ fetchState: 'Completed' }));
93
+ }), (0, addressReducer_1.updateAddresses)(response.data.addresses), (0, issueChargeCardReducer_1.updateChargeCardCount)(response.data?.cards_count_by_user_id ?? []), (0, issueChargeCardReducer_1.updateDebitCardCount)(response.data?.debit_cards_count_by_deposit_account_id ?? {}), (0, issueChargeCardReducer_1.updateLastIssuedCardIds)(issuedCards.map((card) => card.card_id)), (0, issueChargeCardReducer_1.issueChargeCardSuccessOrFailure)({ fetchState: 'Completed' }));
94
94
  if (issuedCards.length === 1 &&
95
95
  (issuedCards[0].card_type.code ===
96
96
  'business_virtual_debit_card' ||
@@ -1,11 +1,18 @@
1
1
  import { FetchState, ID } from '../../../../commonStateTypes/common';
2
+ import { CardsCreationInitialData } from '../../../../entity/aiCfo/aiCfoState';
2
3
  import { CardCodeType } from '../../../../entity/chargeCard/chargeCard';
3
4
  import { DepositAccountWithLimitPayload } from '../../../../entity/depositAccount/depositAccountPayload';
5
+ import { User } from '../../../../entity/user/userState';
4
6
  import { ZeniAPIStatus } from '../../../../responsePayload';
5
7
  import { ActiveChargeCardCountPayload, ActiveDebitCardCountByUserIdPayload } from '../../../userListView/userListViewPayload';
8
+ import { CardsFormDraft } from './aiCardCreationFormDraftTypes';
6
9
  import { IssueChargeCardLocalData, IssueChargeCardState } from './issueChargeCardState';
7
10
  export declare const initialState: IssueChargeCardState;
8
- export declare const issueChargeCards: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[], {}, "issueChargeCard/issueChargeCards", never, never>, updateChargeCardsLocalStore: import("@reduxjs/toolkit").ActionCreatorWithPayload<IssueChargeCardLocalData[], "issueChargeCard/updateChargeCardsLocalStore">, updateLastSelfIssuedDebitCardId: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "issueChargeCard/updateLastSelfIssuedDebitCardId">, issueChargeCardSuccessOrFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
11
+ export declare const issueChargeCards: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload?: {
12
+ sourceChatSessionId?: ID;
13
+ } | undefined], {
14
+ sourceChatSessionId?: ID;
15
+ }, "issueChargeCard/issueChargeCards", never, never>, updateChargeCardsLocalStore: import("@reduxjs/toolkit").ActionCreatorWithPayload<IssueChargeCardLocalData[], "issueChargeCard/updateChargeCardsLocalStore">, updateLastSelfIssuedDebitCardId: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "issueChargeCard/updateLastSelfIssuedDebitCardId">, updateLastIssuedCardIds: import("@reduxjs/toolkit").ActionCreatorWithPayload<string[], "issueChargeCard/updateLastIssuedCardIds">, issueChargeCardSuccessOrFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
9
16
  fetchState: FetchState;
10
17
  error?: ZeniAPIStatus;
11
18
  }, "issueChargeCard/issueChargeCardSuccessOrFailure">, resetIssueChargeCardForm: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"issueChargeCard/resetIssueChargeCardForm">, updateCustomAddressId: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
@@ -19,6 +26,9 @@ export declare const issueChargeCards: import("@reduxjs/toolkit").ActionCreatorW
19
26
  }, "issueChargeCard/fetchIssueCardPage", never, never>, updateDepositAccountsInCards: import("@reduxjs/toolkit").ActionCreatorWithPayload<DepositAccountWithLimitPayload[], "issueChargeCard/updateDepositAccountsInCards">, fetchDepositAccountListForCards: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"issueChargeCard/fetchDepositAccountListForCards">, updateDepositAccountListForCardsFetchStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
20
27
  fetchState: FetchState;
21
28
  error?: ZeniAPIStatus;
22
- }, "issueChargeCard/updateDepositAccountListForCardsFetchStatus">, clearIssueChargeCard: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"issueChargeCard/clearIssueChargeCard">;
29
+ }, "issueChargeCard/updateDepositAccountListForCardsFetchStatus">, seedAiCardCreationFormDraft: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[allUsers: User[], initialData: CardsCreationInitialData], {
30
+ allUsers: User[];
31
+ initialData: CardsCreationInitialData;
32
+ }, "issueChargeCard/seedAiCardCreationFormDraft", never, never>, updateAiCardCreationFormDraft: import("@reduxjs/toolkit").ActionCreatorWithPayload<CardsFormDraft, "issueChargeCard/updateAiCardCreationFormDraft">, clearAiCardCreationFormDraft: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"issueChargeCard/clearAiCardCreationFormDraft">, clearIssueChargeCard: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"issueChargeCard/clearIssueChargeCard">;
23
33
  declare const _default: import("redux").Reducer<IssueChargeCardState>;
24
34
  export default _default;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.clearIssueChargeCard = exports.updateDepositAccountListForCardsFetchStatus = exports.fetchDepositAccountListForCards = exports.updateDepositAccountsInCards = exports.fetchIssueCardPage = exports.updateDebitCardCount = exports.updateChargeCardCount = exports.updateCustomAddressId = exports.resetIssueChargeCardForm = exports.issueChargeCardSuccessOrFailure = exports.updateLastSelfIssuedDebitCardId = exports.updateChargeCardsLocalStore = exports.issueChargeCards = exports.initialState = void 0;
4
+ exports.clearIssueChargeCard = exports.clearAiCardCreationFormDraft = exports.updateAiCardCreationFormDraft = exports.seedAiCardCreationFormDraft = exports.updateDepositAccountListForCardsFetchStatus = exports.fetchDepositAccountListForCards = exports.updateDepositAccountsInCards = exports.fetchIssueCardPage = exports.updateDebitCardCount = exports.updateChargeCardCount = exports.updateCustomAddressId = exports.resetIssueChargeCardForm = exports.issueChargeCardSuccessOrFailure = exports.updateLastIssuedCardIds = exports.updateLastSelfIssuedDebitCardId = exports.updateChargeCardsLocalStore = exports.issueChargeCards = exports.initialState = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
+ const applyAiCardCreationFormDraftUpdate_1 = require("./applyAiCardCreationFormDraftUpdate");
7
+ const buildAiCardCreationFormDraftSeed_1 = require("./buildAiCardCreationFormDraftSeed");
6
8
  exports.initialState = {
7
9
  depositAccountIds: [],
8
10
  depositAccountsFetchState: { fetchState: 'Not-Started', error: undefined },
@@ -18,6 +20,7 @@ exports.initialState = {
18
20
  },
19
21
  activeChargeCardCount: {},
20
22
  activeDebitCardCountByDepositAccountId: {},
23
+ lastIssuedCardIds: [],
21
24
  };
22
25
  const issueChargeCard = (0, toolkit_1.createSlice)({
23
26
  name: 'issueChargeCard',
@@ -38,14 +41,19 @@ const issueChargeCard = (0, toolkit_1.createSlice)({
38
41
  },
39
42
  },
40
43
  issueChargeCards: {
41
- prepare() {
42
- return { payload: {} };
44
+ prepare(payload) {
45
+ return { payload: payload ?? {} };
43
46
  },
44
- reducer(draft) {
47
+ reducer(draft, action) {
45
48
  draft.saveStatus.fetchState = 'In-Progress';
46
49
  draft.saveStatus.error = undefined;
50
+ draft.lastIssueSourceChatSessionId = action.payload.sourceChatSessionId;
51
+ draft.lastIssuedCardIds = [];
47
52
  },
48
53
  },
54
+ updateLastIssuedCardIds(draft, action) {
55
+ draft.lastIssuedCardIds = action.payload;
56
+ },
49
57
  updateChargeCardsLocalStore(draft, action) {
50
58
  draft.localData = action.payload;
51
59
  },
@@ -53,6 +61,8 @@ const issueChargeCard = (0, toolkit_1.createSlice)({
53
61
  draft.localData = [...exports.initialState.localData];
54
62
  draft.saveStatus = exports.initialState.saveStatus;
55
63
  draft.lastSelfIssuedDebitCardId = undefined;
64
+ draft.lastIssueSourceChatSessionId = undefined;
65
+ draft.lastIssuedCardIds = [];
56
66
  },
57
67
  updateLastSelfIssuedDebitCardId(draft, action) {
58
68
  draft.lastSelfIssuedDebitCardId = action.payload;
@@ -128,10 +138,44 @@ const issueChargeCard = (0, toolkit_1.createSlice)({
128
138
  draft.depositAccountsFetchState.fetchState = action.payload.fetchState;
129
139
  draft.depositAccountsFetchState.error = action.payload.error;
130
140
  },
141
+ /**
142
+ * Seed the AI card-creation form draft + companion context from the
143
+ * AI's `interactive_form` payload. Dispatched once when the
144
+ * `CardsCreationInteractiveForm` mounts (or the AI payload arrives).
145
+ */
146
+ seedAiCardCreationFormDraft: {
147
+ reducer(draft, action) {
148
+ const { draft: nextDraft, context } = (0, buildAiCardCreationFormDraftSeed_1.buildAiCardCreationFormDraftSeed)({
149
+ allUsers: action.payload.allUsers,
150
+ initialData: action.payload.initialData,
151
+ });
152
+ draft.aiCardCreationFormDraft = nextDraft;
153
+ draft.aiCardCreationFormDraftContext = context;
154
+ },
155
+ prepare(allUsers, initialData) {
156
+ return { payload: { allUsers, initialData } };
157
+ },
158
+ },
159
+ /**
160
+ * Replace the form draft from the component's `watchHandler`. Delegates
161
+ * to `applyAiCardCreationFormDraftUpdate` so the same derivation rules
162
+ * (review-mode `cardRows` re-derivation that preserves in-place edits)
163
+ * are shared with the Storybook owner harness.
164
+ */
165
+ updateAiCardCreationFormDraft(draft, action) {
166
+ draft.aiCardCreationFormDraft = (0, applyAiCardCreationFormDraftUpdate_1.applyAiCardCreationFormDraftUpdate)({
167
+ next: action.payload,
168
+ context: draft.aiCardCreationFormDraftContext,
169
+ });
170
+ },
171
+ clearAiCardCreationFormDraft(draft) {
172
+ draft.aiCardCreationFormDraft = undefined;
173
+ draft.aiCardCreationFormDraftContext = undefined;
174
+ },
131
175
  clearIssueChargeCard(draft) {
132
176
  Object.assign(draft, exports.initialState);
133
177
  },
134
178
  },
135
179
  });
136
- _a = issueChargeCard.actions, exports.issueChargeCards = _a.issueChargeCards, exports.updateChargeCardsLocalStore = _a.updateChargeCardsLocalStore, exports.updateLastSelfIssuedDebitCardId = _a.updateLastSelfIssuedDebitCardId, exports.issueChargeCardSuccessOrFailure = _a.issueChargeCardSuccessOrFailure, exports.resetIssueChargeCardForm = _a.resetIssueChargeCardForm, exports.updateCustomAddressId = _a.updateCustomAddressId, exports.updateChargeCardCount = _a.updateChargeCardCount, exports.updateDebitCardCount = _a.updateDebitCardCount, exports.fetchIssueCardPage = _a.fetchIssueCardPage, exports.updateDepositAccountsInCards = _a.updateDepositAccountsInCards, exports.fetchDepositAccountListForCards = _a.fetchDepositAccountListForCards, exports.updateDepositAccountListForCardsFetchStatus = _a.updateDepositAccountListForCardsFetchStatus, exports.clearIssueChargeCard = _a.clearIssueChargeCard;
180
+ _a = issueChargeCard.actions, exports.issueChargeCards = _a.issueChargeCards, exports.updateChargeCardsLocalStore = _a.updateChargeCardsLocalStore, exports.updateLastSelfIssuedDebitCardId = _a.updateLastSelfIssuedDebitCardId, exports.updateLastIssuedCardIds = _a.updateLastIssuedCardIds, exports.issueChargeCardSuccessOrFailure = _a.issueChargeCardSuccessOrFailure, exports.resetIssueChargeCardForm = _a.resetIssueChargeCardForm, exports.updateCustomAddressId = _a.updateCustomAddressId, exports.updateChargeCardCount = _a.updateChargeCardCount, exports.updateDebitCardCount = _a.updateDebitCardCount, exports.fetchIssueCardPage = _a.fetchIssueCardPage, exports.updateDepositAccountsInCards = _a.updateDepositAccountsInCards, exports.fetchDepositAccountListForCards = _a.fetchDepositAccountListForCards, exports.updateDepositAccountListForCardsFetchStatus = _a.updateDepositAccountListForCardsFetchStatus, exports.seedAiCardCreationFormDraft = _a.seedAiCardCreationFormDraft, exports.updateAiCardCreationFormDraft = _a.updateAiCardCreationFormDraft, exports.clearAiCardCreationFormDraft = _a.clearAiCardCreationFormDraft, exports.clearIssueChargeCard = _a.clearIssueChargeCard;
137
181
  exports.default = issueChargeCard.reducer;
@@ -7,6 +7,7 @@ import { RootState } from '../../../../reducer';
7
7
  import { Person } from '../../../people/peopleSelectorTypes';
8
8
  import { ChargeCardConfigState } from '../chargeCardConfig/chargeCardConfigState';
9
9
  import { CreditAccount } from '../chargeCardList/chargeCardList';
10
+ import { CardsFormDraft } from './aiCardCreationFormDraftTypes';
10
11
  import { ActiveChargeCardCount, ActiveDebitCardCountByUserId, IssueChargeCardLocalData } from './issueChargeCardState';
11
12
  export interface IssueChargeCardSelectorView extends SelectorView {
12
13
  activeChargeCardCount: Record<ID, ActiveChargeCardCount>;
@@ -25,3 +26,44 @@ export interface IssueChargeCardSelectorView extends SelectorView {
25
26
  lastSelfIssuedDebitCardId?: ID;
26
27
  }
27
28
  export declare const getIssueChargeCardView: (state: RootState, isCreditCardEnabled: boolean, isDebitCardEnabled: boolean) => IssueChargeCardSelectorView;
29
+ /**
30
+ * Returns the AI CFO chat session id that triggered the most recent
31
+ * `issueChargeCards` dispatch (if any). Used by the cards list screen to
32
+ * decide whether the in-flight bulk-create originated from an AI CFO
33
+ * interactive form submission and should therefore render a pending
34
+ * placeholder + synthetic AI CFO drawer bubble.
35
+ */
36
+ export declare const getLastIssueChargeCardsSourceChatSessionId: (state: RootState) => ID | undefined;
37
+ /**
38
+ * Returns the ids of the cards created by the most recent successful
39
+ * `issueChargeCards` call. Used by the AI CFO drawer's "Created" success
40
+ * bubble to map back to the actual created entities.
41
+ */
42
+ export declare const getLastIssuedChargeCardIds: (state: RootState) => ID[];
43
+ /**
44
+ * Returns the save-status fetch state for the most recent `issueChargeCards`
45
+ * dispatch. Useful for gating pending placeholder rows on `In-Progress` /
46
+ * swapping them out on `Completed`.
47
+ */
48
+ export declare const getIssueChargeCardsSaveStatus: (state: RootState) => FetchStateAndError;
49
+ /**
50
+ * Returns the number of card rows currently being bulk-issued via the most
51
+ * recent `issueChargeCards` dispatch. Mirrors `localData.length` while the
52
+ * call is in flight so the cards list screen can render N skeleton rows at
53
+ * the top of the table.
54
+ */
55
+ export declare const getInFlightIssueChargeCardsCount: (state: RootState) => number;
56
+ /**
57
+ * Returns the current AI card-creation form draft, or `undefined` before
58
+ * `seedAiCardCreationFormDraft` runs / after `clearAiCardCreationFormDraft`.
59
+ * Used by the connected screens to hydrate the
60
+ * `CardsCreationInteractiveForm`'s RHF.
61
+ */
62
+ export declare const getAiCardCreationFormDraft: (state: RootState) => CardsFormDraft | undefined;
63
+ /**
64
+ * Project the AI card-creation form draft into the wire-ready
65
+ * `IssueChargeCardLocalData[]` payload `issueChargeCardEpic` expects.
66
+ * Returns an empty array when the draft is absent so callers can
67
+ * short-circuit submission without dispatching a no-op bulk POST.
68
+ */
69
+ export declare const selectIssueChargeCardLocalDataFromDraft: (state: RootState) => IssueChargeCardLocalData[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIssueChargeCardView = void 0;
3
+ exports.selectIssueChargeCardLocalDataFromDraft = exports.getAiCardCreationFormDraft = exports.getInFlightIssueChargeCardsCount = exports.getIssueChargeCardsSaveStatus = exports.getLastIssuedChargeCardIds = exports.getLastIssueChargeCardsSourceChatSessionId = exports.getIssueChargeCardView = void 0;
4
4
  const reduceFetchState_1 = require("../../../../commonStateTypes/reduceFetchState");
5
5
  const addressSelector_1 = require("../../../../entity/address/addressSelector");
6
6
  const classSelector_1 = require("../../../../entity/class/classSelector");
@@ -8,6 +8,7 @@ const depositAccountSelector_1 = require("../../../../entity/depositAccount/depo
8
8
  const tenantSelector_1 = require("../../../../entity/tenant/tenantSelector");
9
9
  const addressViewSelector_1 = require("../../../addressView/addressViewSelector");
10
10
  const userListViewSelector_1 = require("../../../userListView/userListViewSelector");
11
+ const toIssueChargeCardLocalDataFromDraft_1 = require("./toIssueChargeCardLocalDataFromDraft");
11
12
  const getIssueChargeCardView = (state, isCreditCardEnabled, isDebitCardEnabled) => {
12
13
  const { issueChargeCardState, userState, userRoleState, userListViewState, chargeCardConfigState, chargeCardListState, addressState, classState, depositAccountState, classListState, } = state;
13
14
  const userListSelectorView = (0, userListViewSelector_1.getUserList)(userState, userRoleState, userListViewState, 'cardHolderCandidate');
@@ -97,3 +98,69 @@ const getIssueChargeCardView = (state, isCreditCardEnabled, isDebitCardEnabled)
97
98
  };
98
99
  };
99
100
  exports.getIssueChargeCardView = getIssueChargeCardView;
101
+ /**
102
+ * Returns the AI CFO chat session id that triggered the most recent
103
+ * `issueChargeCards` dispatch (if any). Used by the cards list screen to
104
+ * decide whether the in-flight bulk-create originated from an AI CFO
105
+ * interactive form submission and should therefore render a pending
106
+ * placeholder + synthetic AI CFO drawer bubble.
107
+ */
108
+ const getLastIssueChargeCardsSourceChatSessionId = (state) => {
109
+ return state.issueChargeCardState.lastIssueSourceChatSessionId;
110
+ };
111
+ exports.getLastIssueChargeCardsSourceChatSessionId = getLastIssueChargeCardsSourceChatSessionId;
112
+ /**
113
+ * Returns the ids of the cards created by the most recent successful
114
+ * `issueChargeCards` call. Used by the AI CFO drawer's "Created" success
115
+ * bubble to map back to the actual created entities.
116
+ */
117
+ const getLastIssuedChargeCardIds = (state) => {
118
+ return state.issueChargeCardState.lastIssuedCardIds;
119
+ };
120
+ exports.getLastIssuedChargeCardIds = getLastIssuedChargeCardIds;
121
+ /**
122
+ * Returns the save-status fetch state for the most recent `issueChargeCards`
123
+ * dispatch. Useful for gating pending placeholder rows on `In-Progress` /
124
+ * swapping them out on `Completed`.
125
+ */
126
+ const getIssueChargeCardsSaveStatus = (state) => {
127
+ return state.issueChargeCardState.saveStatus;
128
+ };
129
+ exports.getIssueChargeCardsSaveStatus = getIssueChargeCardsSaveStatus;
130
+ /**
131
+ * Returns the number of card rows currently being bulk-issued via the most
132
+ * recent `issueChargeCards` dispatch. Mirrors `localData.length` while the
133
+ * call is in flight so the cards list screen can render N skeleton rows at
134
+ * the top of the table.
135
+ */
136
+ const getInFlightIssueChargeCardsCount = (state) => {
137
+ if (state.issueChargeCardState.saveStatus.fetchState !== 'In-Progress') {
138
+ return 0;
139
+ }
140
+ return state.issueChargeCardState.localData.length;
141
+ };
142
+ exports.getInFlightIssueChargeCardsCount = getInFlightIssueChargeCardsCount;
143
+ /**
144
+ * Returns the current AI card-creation form draft, or `undefined` before
145
+ * `seedAiCardCreationFormDraft` runs / after `clearAiCardCreationFormDraft`.
146
+ * Used by the connected screens to hydrate the
147
+ * `CardsCreationInteractiveForm`'s RHF.
148
+ */
149
+ const getAiCardCreationFormDraft = (state) => {
150
+ return state.issueChargeCardState.aiCardCreationFormDraft;
151
+ };
152
+ exports.getAiCardCreationFormDraft = getAiCardCreationFormDraft;
153
+ /**
154
+ * Project the AI card-creation form draft into the wire-ready
155
+ * `IssueChargeCardLocalData[]` payload `issueChargeCardEpic` expects.
156
+ * Returns an empty array when the draft is absent so callers can
157
+ * short-circuit submission without dispatching a no-op bulk POST.
158
+ */
159
+ const selectIssueChargeCardLocalDataFromDraft = (state) => {
160
+ const draft = state.issueChargeCardState.aiCardCreationFormDraft;
161
+ if (draft == null) {
162
+ return [];
163
+ }
164
+ return (0, toIssueChargeCardLocalDataFromDraft_1.toIssueChargeCardLocalDataFromDraft)(draft);
165
+ };
166
+ exports.selectIssueChargeCardLocalDataFromDraft = selectIssueChargeCardLocalDataFromDraft;
@@ -1,13 +1,31 @@
1
1
  import { Amount } from '../../../../commonStateTypes/amount';
2
2
  import { FetchStateAndError, FetchedState, ID } from '../../../../commonStateTypes/common';
3
3
  import { ChargeCardType, CreditCardCodeType, CreditLimitFrequencyCodeType, DebitCardCodeType, ShippingAddressType } from '../../../../entity/chargeCard/chargeCard';
4
+ import { AiCardCreationFormDraftSeedContext, CardsFormDraft } from './aiCardCreationFormDraftTypes';
4
5
  export interface IssueChargeCardState extends FetchedState {
5
6
  activeChargeCardCount: Record<ID, ActiveChargeCardCount>;
6
7
  activeDebitCardCountByDepositAccountId: Record<ID, ActiveDebitCardCountByUserId>;
7
8
  depositAccountIds: ID[];
8
9
  depositAccountsFetchState: FetchStateAndError;
10
+ lastIssuedCardIds: ID[];
9
11
  localData: IssueChargeCardLocalData[];
10
12
  saveStatus: FetchStateAndError;
13
+ /**
14
+ * Current AI CFO card-creation form draft. Hydrates the
15
+ * `CardsCreationInteractiveForm` and is replaced wholesale on every
16
+ * `watchHandler` tick via `updateAiCardCreationFormDraft`. `undefined`
17
+ * before `seedAiCardCreationFormDraft` runs and after
18
+ * `clearAiCardCreationFormDraft`.
19
+ */
20
+ aiCardCreationFormDraft?: CardsFormDraft;
21
+ /**
22
+ * Companion seed context for `aiCardCreationFormDraft`. The reducer
23
+ * uses this to re-derive step-2 `cardRows` from step-1 `teamRows`
24
+ * selections on subsequent `updateAiCardCreationFormDraft` dispatches
25
+ * without the component re-passing the AI's full universe.
26
+ */
27
+ aiCardCreationFormDraftContext?: AiCardCreationFormDraftSeedContext;
28
+ lastIssueSourceChatSessionId?: ID;
11
29
  lastSelfIssuedDebitCardId?: ID;
12
30
  }
13
31
  export interface ActiveChargeCardCount {
@@ -0,0 +1,11 @@
1
+ import { CardsFormDraft } from './aiCardCreationFormDraftTypes';
2
+ import { IssueChargeCardLocalData } from './issueChargeCardState';
3
+ /**
4
+ * Convert a `CardsFormDraft` into the `IssueChargeCardLocalData[]`
5
+ * payload `issueChargeCardEpic` expects in
6
+ * `state.issueChargeCardState.localData`.
7
+ *
8
+ * Returns an empty array when `cardRows` is empty so callers can
9
+ * short-circuit without dispatching a no-op bulk POST.
10
+ */
11
+ export declare const toIssueChargeCardLocalDataFromDraft: (draft: CardsFormDraft) => IssueChargeCardLocalData[];
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toIssueChargeCardLocalDataFromDraft = void 0;
4
+ /**
5
+ * Default credit limit frequency emitted on the wire when the AI CFO
6
+ * card creation form is submitted. The interactive form has no
7
+ * frequency field today (v1 product decision: AI CFO only ever issues
8
+ * monthly virtual credit cards).
9
+ */
10
+ const DEFAULT_FREQUENCY = 'monthly';
11
+ const DEFAULT_CURRENCY_CODE = 'USD';
12
+ const DEFAULT_CURRENCY_SYMBOL = '$';
13
+ /**
14
+ * Map a single AI card-creation row to the `IssueChargeCardLocalData`
15
+ * shape consumed by `issueChargeCardEpic`.
16
+ *
17
+ * AI CFO only issues `business_virtual_credit_card`s in v1, so:
18
+ * - `chargeCardType` is hard-coded to `'credit_card'`
19
+ * - `creditCard.cardType` is hard-coded to `'business_virtual_credit_card'`
20
+ * - the physicalCard / debitCard.* slots are populated with empty
21
+ * defaults that the epic ignores.
22
+ *
23
+ * The form's `cardOptionId` is intentionally ignored: it's a UI-only
24
+ * selector ("physical" / "virtual") that the AI uses to suggest a
25
+ * flavour, but the bulk-create wire contract only supports the virtual
26
+ * branch in this iteration.
27
+ */
28
+ const mapCardRow = (row) => {
29
+ const ownerUserId = row.owner.selectedUser?.userId;
30
+ return {
31
+ lineId: row.id,
32
+ chargeCardType: 'credit_card',
33
+ creditCard: {
34
+ cardType: 'business_virtual_credit_card',
35
+ virtualCard: {
36
+ cardName: row.label,
37
+ frequency: DEFAULT_FREQUENCY,
38
+ userIds: ownerUserId != null ? [ownerUserId] : [],
39
+ amount: {
40
+ amount: row.recommendedLimit ?? 0,
41
+ currencyCode: DEFAULT_CURRENCY_CODE,
42
+ currencySymbol: DEFAULT_CURRENCY_SYMBOL,
43
+ },
44
+ },
45
+ physicalCard: {
46
+ cardName: '',
47
+ frequency: DEFAULT_FREQUENCY,
48
+ },
49
+ },
50
+ debitCard: {
51
+ cardType: 'business_virtual_debit_card',
52
+ virtualCard: {
53
+ cardName: '',
54
+ frequency: DEFAULT_FREQUENCY,
55
+ userIds: [],
56
+ },
57
+ physicalCard: {
58
+ cardName: '',
59
+ frequency: DEFAULT_FREQUENCY,
60
+ },
61
+ },
62
+ };
63
+ };
64
+ /**
65
+ * Convert a `CardsFormDraft` into the `IssueChargeCardLocalData[]`
66
+ * payload `issueChargeCardEpic` expects in
67
+ * `state.issueChargeCardState.localData`.
68
+ *
69
+ * Returns an empty array when `cardRows` is empty so callers can
70
+ * short-circuit without dispatching a no-op bulk POST.
71
+ */
72
+ const toIssueChargeCardLocalDataFromDraft = (draft) => draft.cardRows.map(mapCardRow);
73
+ exports.toIssueChargeCardLocalDataFromDraft = toIssueChargeCardLocalDataFromDraft;
@@ -14,7 +14,7 @@ export declare const fetchTaskListPage: import("@reduxjs/toolkit").ActionCreator
14
14
  archived?: TaskPayload[];
15
15
  deleted?: TaskPayload[];
16
16
  snoozed?: TaskPayload[];
17
- }, "taskList/updateTaskList">, updateTaskListTab: import("@reduxjs/toolkit").ActionCreatorWithPayload<"deleted" | "live" | "archived" | "snoozed", "taskList/updateTaskListTab">, updateTaskListFetchStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
17
+ }, "taskList/updateTaskList">, updateTaskListTab: import("@reduxjs/toolkit").ActionCreatorWithPayload<"deleted" | "archived" | "live" | "snoozed", "taskList/updateTaskListTab">, updateTaskListFetchStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
18
18
  fetchState: FetchState;
19
19
  error?: ZeniAPIStatus;
20
20
  }, "taskList/updateTaskListFetchStatus">, updateTaskListSearchText: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.0.82",
3
+ "version": "5.0.83-betaRR1",
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",