@zeniai/client-epic-state 5.2.53-beta0ND → 5.2.54-betaRD1

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 (61) hide show
  1. package/lib/entity/jeSchedules/jeSchedulesReducer.d.ts +4 -1
  2. package/lib/entity/jeSchedules/jeSchedulesReducer.js +79 -5
  3. package/lib/entity/notificationRegistry/notificationRegistryReducer.d.ts +1 -2
  4. package/lib/entity/notificationRegistry/notificationRegistryReducer.js +9 -20
  5. package/lib/entity/notificationRegistry/notificationRegistrySelector.d.ts +1 -2
  6. package/lib/entity/notificationRegistry/notificationRegistrySelector.js +1 -7
  7. package/lib/entity/notificationRegistry/notificationRegistryState.d.ts +0 -5
  8. package/lib/entity/notificationRegistry/notificationRegistryState.js +1 -7
  9. package/lib/entity/sectionProjectView/sectionProjectViewReducer.js +1 -3
  10. package/lib/epic.d.ts +2 -1
  11. package/lib/epic.js +2 -0
  12. package/lib/esm/entity/jeSchedules/jeSchedulesReducer.js +78 -4
  13. package/lib/esm/entity/notificationRegistry/notificationRegistryReducer.js +9 -20
  14. package/lib/esm/entity/notificationRegistry/notificationRegistrySelector.js +0 -5
  15. package/lib/esm/entity/notificationRegistry/notificationRegistryState.js +0 -5
  16. package/lib/esm/entity/sectionProjectView/sectionProjectViewReducer.js +1 -3
  17. package/lib/esm/epic.js +2 -0
  18. package/lib/esm/index.js +7 -7
  19. package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +2 -4
  20. package/lib/esm/view/aiCfoView/epics/fetchRoutineRunsEpic.js +1 -3
  21. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +39 -0
  22. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +14 -1
  23. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +10 -13
  24. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +38 -17
  25. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +17 -1
  26. package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +74 -1
  27. package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +49 -14
  28. package/lib/esm/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +7 -20
  29. package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewReducer.js +17 -43
  30. package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewSelector.js +4 -24
  31. package/lib/esm/view/settingsView/epic/fetchNotificationSettingsEpic.js +2 -12
  32. package/lib/index.d.ts +7 -7
  33. package/lib/index.js +50 -56
  34. package/lib/tsconfig.mocks.tsbuildinfo +1 -0
  35. package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
  36. package/lib/view/aiCfoView/aiCfoViewReducer.js +2 -4
  37. package/lib/view/aiCfoView/aiCfoViewSelector.d.ts +1 -1
  38. package/lib/view/aiCfoView/epics/fetchRoutineRunsEpic.js +1 -3
  39. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.d.ts +20 -0
  40. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +43 -0
  41. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.d.ts +2 -2
  42. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +13 -0
  43. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +8 -11
  44. package/lib/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +38 -17
  45. package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.d.ts +2 -2
  46. package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +17 -1
  47. package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +18 -0
  48. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +10 -3
  49. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +76 -3
  50. package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +3 -0
  51. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +49 -14
  52. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +16 -0
  53. package/lib/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +6 -19
  54. package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.d.ts +5 -8
  55. package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.js +17 -43
  56. package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.d.ts +0 -4
  57. package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.js +5 -30
  58. package/lib/view/notificationPreferencesView/notificationPreferencesViewState.d.ts +3 -4
  59. package/lib/view/settingsView/epic/fetchNotificationSettingsEpic.js +2 -12
  60. package/lib/view/settingsView/settingsViewPayload.d.ts +0 -2
  61. package/package.json +1 -1
@@ -225,7 +225,7 @@ function getExpenseAutomationJESchedulesView(state) {
225
225
  const accruedSchedules = [];
226
226
  const oneTimeAccruals = [];
227
227
  const { accountState, accountListState, classState, classListState, expenseAutomationJESchedulesViewState, expenseAutomationViewState, monthEndCloseChecksState, } = state;
228
- const { jeScheduleTransactionKeysByPeriodAndTab, jeScheduleAccruedKeysByPeriodAndTab, jeScheduleOneTimeAccrualKeysByPeriodAndTab, failedJeScheduleTransactionKeysByPeriodAndTab, jeScheduleLocalDataById, postStatusById, ignoreStatusById, revertStatusById, oneTimeAccrualActionStatusById, uiState, error, fetchState, refreshStatus, newSchedule, } = expenseAutomationJESchedulesViewState;
228
+ const { jeScheduleTransactionKeysByPeriodAndTab, jeScheduleAccruedKeysByPeriodAndTab, jeScheduleOneTimeAccrualKeysByPeriodAndTab, failedJePostings, jeScheduleLocalDataById, postStatusById, ignoreStatusById, revertStatusById, oneTimeAccrualActionStatusById, uiState, error, fetchState, refreshStatus, newSchedule, } = expenseAutomationJESchedulesViewState;
229
229
  const accountSettingsView = (0, jeAccountSettingsViewSelector_1.getJEAccountSettingsView)(state);
230
230
  const newScheduleView = newSchedule.selectedDetailScheduleType === 'fixed_assets' ||
231
231
  newSchedule.selectedDetailScheduleType === 'prepaid_expenses'
@@ -264,15 +264,11 @@ function getExpenseAutomationJESchedulesView(state) {
264
264
  const jeScheduleTransactionKeysForSelectedTab = selectedPeriodTabKey != null
265
265
  ? jeScheduleTransactionKeysByPeriodAndTab[selectedPeriodTabKey]
266
266
  : undefined;
267
- const failedJeScheduleTransactionKeysForSelectedTab = selectedPeriodTabKey != null
268
- ? failedJeScheduleTransactionKeysByPeriodAndTab[selectedPeriodTabKey]
269
- : undefined;
270
267
  // Distinguishes "this tab has never been fetched for this period" from "fetched and genuinely
271
268
  // empty". Without it the page cannot tell a first visit from a real empty state, and renders an
272
269
  // empty table where it should render a skeleton.
273
270
  const hasLoadedForSelectedTab = jeScheduleTransactionKeysForSelectedTab != null;
274
271
  const jeScheduleTransactionKeys = jeScheduleTransactionKeysForSelectedTab ?? [];
275
- const failedJeScheduleTransactionKeys = failedJeScheduleTransactionKeysForSelectedTab ?? [];
276
272
  const jeScheduleAccruedKeys = (selectedPeriodTabKey != null
277
273
  ? jeScheduleAccruedKeysByPeriodAndTab[selectedPeriodTabKey]
278
274
  : undefined) ?? [];
@@ -295,24 +291,57 @@ function getExpenseAutomationJESchedulesView(state) {
295
291
  accruedSchedules.push(accruedScheduleDetails);
296
292
  }
297
293
  });
298
- failedJeScheduleTransactionKeys.forEach((jeScheduleKey) => {
299
- const jeScheduleDetails = (0, jeSchedulesSelector_1.getJEScheduledTransactionByJEScheduleTransactionKey)(jeScheduleKey, state);
300
- failedJeScheduledTransaction.push(jeScheduleDetails);
294
+ // Sourced from the tenant-wide bucket, not the per-period one: a failed posting belongs to no
295
+ // close month, and windowing it is what kept older failures off the only tab that can resolve
296
+ // them.
297
+ failedJePostings.jeScheduleTransactionKeys.forEach((jeScheduleKey) => {
298
+ // getJEScheduledTransactionByJEScheduleTransactionKey throws three different ways: it
299
+ // destructures the result of recordGet without a null check, and it raises explicitly for a
300
+ // missing vendor and for a missing base transaction. Catching rather than pre-checking each
301
+ // one keeps this correct if a fourth is added, and none of the three is recoverable here --
302
+ // the row cannot be drawn either way.
303
+ //
304
+ // This matters more for this bucket than anywhere else on the page. It is tenant-wide, so it
305
+ // names schedules the close-month list never loaded, and the group is defined by deleted
306
+ // vendors and deleted categories -- precisely the rows whose entities are most likely to be
307
+ // missing. Unguarded, one such key takes down the whole JE tab instead of dropping one row.
308
+ try {
309
+ failedJeScheduledTransaction.push((0, jeSchedulesSelector_1.getJEScheduledTransactionByJEScheduleTransactionKey)(jeScheduleKey, state));
310
+ }
311
+ catch {
312
+ // Intentionally swallowed: a failed posting we cannot resolve is one missing row, and the
313
+ // alternative is a blank page for every other row too.
314
+ }
301
315
  });
316
+ // What the endpoint last reported as failing. The entity store keeps every month a schedule
317
+ // has and an entry resolved by someone else keeps its old `error` array, so `error` alone would
318
+ // leave a Retry button on a posting that is no longer failing.
319
+ const failedScheduledJournalEntryIDs = new Set(failedJePostings.scheduledJournalEntryIDs);
302
320
  const { sortKey, sortOrder, selectedJETypeFilter } = uiState;
321
+ const matchesTypeFilter = (schedule) => selectedJETypeFilter == null ||
322
+ getJEScheduleRowType(schedule) === selectedJETypeFilter;
303
323
  const unsortedResolveSchedules = [];
304
324
  failedJeScheduledTransaction.forEach((schedule) => {
305
- schedule.scheduledJournalEntry.forEach((journalEntry) => {
325
+ // Only the entries that actually carry an error. The schedule's entry array is shared state:
326
+ // opening a schedule's detail page or Quick View replaces it with every month the schedule
327
+ // has, posted ones included, so fanning out over all of them turned one failed posting into a
328
+ // row per month -- and a month that never failed has nothing to resolve, so it rendered with
329
+ // an empty action column.
330
+ //
331
+ // Intersected with the ids the endpoint actually returned, not just `error`: the entry array
332
+ // is a cache of every month, and an entry whose failure someone else resolved keeps its stale
333
+ // error array until something overwrites it. Only what the last fetch named is still failing.
334
+ schedule.scheduledJournalEntry
335
+ .filter((journalEntry) => journalEntry.error.length > 0 &&
336
+ failedScheduledJournalEntryIDs.has(journalEntry.scheduledJournalEntryID))
337
+ .forEach((journalEntry) => {
306
338
  unsortedResolveSchedules.push({
307
339
  ...schedule,
308
340
  scheduledJournalEntry: journalEntry,
309
341
  });
310
342
  });
311
343
  });
312
- const resolveSchedules = sortJEScheduledTransactions(unsortedResolveSchedules, sortKey, sortOrder);
313
- const validResolveForPending = unsortedResolveSchedules.filter((r) => jeScheduleLocalDataById[r.scheduledJournalEntry.scheduledJournalEntryID] != null);
314
- const matchesTypeFilter = (schedule) => selectedJETypeFilter == null ||
315
- getJEScheduleRowType(schedule) === selectedJETypeFilter;
344
+ const resolveSchedules = sortJEScheduledTransactions(unsortedResolveSchedules.filter(matchesTypeFilter), sortKey, sortOrder);
316
345
  const isCreatedStatus = (schedule) => {
317
346
  // An accrual is "created" once it is not review work: posted, reversing, reversed, or in a
318
347
  // transient posting claim.
@@ -330,7 +359,6 @@ function getExpenseAutomationJESchedulesView(state) {
330
359
  ];
331
360
  const pendingReviewSchedules = sortJEScheduledTransactions([
332
361
  ...allScheduleRows.filter((schedule) => isPendingReviewRow(schedule) && matchesTypeFilter(schedule)),
333
- ...validResolveForPending,
334
362
  ], sortKey, sortOrder);
335
363
  const createdSchedules = sortJEScheduledTransactions(allScheduleRows.filter((schedule) => isCreatedStatus(schedule) && matchesTypeFilter(schedule)), sortKey, sortOrder);
336
364
  // KPI summary — derived from unfiltered schedules so counts are always accurate
@@ -449,6 +477,13 @@ function getExpenseAutomationJESchedulesView(state) {
449
477
  kpiSummary,
450
478
  pendingReviewSchedules,
451
479
  pendingReviewTotal,
480
+ failedPostings: resolveSchedules,
481
+ // Exposed so a consumer can tell "still loading" and "the lookup failed" from "nothing has
482
+ // failed". The bucket keeps its rows on failure precisely so an error can be shown beside
483
+ // them, which is only possible if the state travels with them.
484
+ failedPostingsFetchState: failedJePostings.fetchState,
485
+ // Deprecated alias of failedPostings. Still read by the section's footer-form effect and by
486
+ // app-ui analytics; remove once both are repointed.
452
487
  resolveSchedules: resolveSchedules,
453
488
  accountSettingsView,
454
489
  newScheduleView,
@@ -19,6 +19,7 @@ export type JESchedulePeriodTabKey = `${JEPageTab}_${MonthYearPeriodId}`;
19
19
  export declare const getJESchedulePeriodTabKey: (selectedPageTab: JEPageTab, monthYearPeriodId: MonthYearPeriodId) => JESchedulePeriodTabKey;
20
20
  export interface JESchedulesViewUIState {
21
21
  createdGroupCollapsed: boolean;
22
+ failedGroupCollapsed: boolean;
22
23
  pendingGroupCollapsed: boolean;
23
24
  scrollPosition: {
24
25
  scrollTop: number;
@@ -41,8 +42,23 @@ export interface JEScheduleLocalData {
41
42
  updatedClassId?: ID;
42
43
  updatedVendor?: VendorBase;
43
44
  }
45
+ /**
46
+ * The Failed Postings bucket, and the only list on this page that is not scoped to a period.
47
+ *
48
+ * A failed posting is broken until someone resolves it, whatever month it belongs to, so windowing
49
+ * it the way the schedule lists are windowed is what hid a March failure from the September close.
50
+ * It therefore has no period-tab key, and its own fetch state rather than the slice's: the list is
51
+ * fetched separately from `/1.0/expenses_automation/failed_je_postings`, so a slow or failing
52
+ * lookup here must not blank the schedules table, or vice versa.
53
+ */
54
+ export interface FailedJePostingsState {
55
+ fetchState: FetchStateAndError;
56
+ jeScheduleTransactionKeys: JEScheduleTransactionKey[];
57
+ scheduledJournalEntryIDs: ID[];
58
+ }
44
59
  export interface JESchedulesViewState extends FetchedState {
45
60
  accountSettings: AccountSettingsState;
61
+ failedJePostings: FailedJePostingsState;
46
62
  failedJeScheduleTransactionKeysByPeriodAndTab: Record<JESchedulePeriodTabKey, JEScheduleTransactionKey[]>;
47
63
  ignoreStatusById: Record<JEScheduleTransactionKey, FetchStateAndError>;
48
64
  jeScheduleAccruedKeysByPeriodAndTab: Record<JESchedulePeriodTabKey, JEScheduleKey[]>;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.saveNotificationPreferencesEpic = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const operators_1 = require("rxjs/operators");
6
- const notificationRegistryState_1 = require("../../../entity/notificationRegistry/notificationRegistryState");
7
6
  const snackbarReducer_1 = require("../../../entity/snackbar/snackbarReducer");
8
7
  const responsePayload_1 = require("../../../responsePayload");
9
8
  const notificationPreferencesEndpoint_1 = require("../notificationPreferencesEndpoint");
@@ -17,19 +16,9 @@ const saveNotificationPreferencesEpic = (actions$, state$, zeniAPI) => actions$.
17
16
  // ignored, so stale success/failure actions cannot clobber the newer
18
17
  // batch's state. Server-side ordering is arrival-order LWW.
19
18
  (0, operators_1.switchMap)(([, state]) => {
20
- // A clean domain is omitted entirely: an empty patch is still a write against it.
21
- const overridesByDomain = {};
22
- const body = {};
23
- notificationRegistryState_1.NOTIFICATION_DOMAINS.forEach((domain) => {
24
- const overrides = (0, notificationPreferencesViewSelector_1.getNotificationLocalOverridesForDomain)(state, domain);
25
- const preferencesPatch = (0, notificationPreferencesViewPayload_1.mapPreferencesToPayload)(overrides);
26
- if (Object.keys(preferencesPatch).length === 0) {
27
- return;
28
- }
29
- overridesByDomain[domain] = overrides;
30
- body[`${domain}_preferences`] = preferencesPatch;
31
- });
32
- if (Object.keys(body).length === 0) {
19
+ const overrides = (0, notificationPreferencesViewSelector_1.getNotificationLocalOverrides)(state);
20
+ const preferencesPatch = (0, notificationPreferencesViewPayload_1.mapPreferencesToPayload)(overrides);
21
+ if (Object.keys(preferencesPatch).length === 0) {
33
22
  // No diff → do not dispatch a synthetic success (that would wipe
34
23
  // stored preferences via the reducer). Simply no-op.
35
24
  return rxjs_1.EMPTY;
@@ -42,6 +31,7 @@ const saveNotificationPreferencesEpic = (actions$, state$, zeniAPI) => actions$.
42
31
  // in-flight save's response (Success/Failure never dispatched, so
43
32
  // the counter never drained and future saves got their merge dropped).
44
33
  const cancelEpochAtDispatch = state.notificationPreferencesViewState.cancelEpoch;
34
+ const body = { task_checklist_preferences: preferencesPatch };
45
35
  // Suppress the error snackbar when the response lands AFTER the user
46
36
  // pressed Cancel — the Failure reducer already swallows the state
47
37
  // update, so the toast would be a stale error for a save the user
@@ -70,11 +60,8 @@ const saveNotificationPreferencesEpic = (actions$, state$, zeniAPI) => actions$.
70
60
  if ((0, responsePayload_1.isSuccessResponse)(response)) {
71
61
  return (0, rxjs_1.of)((0, notificationPreferencesViewReducer_1.saveNotificationPreferencesSuccess)({
72
62
  cancelEpochAtDispatch,
73
- savedOverridesByDomain: overridesByDomain,
74
- serverEchoByDomain: {
75
- task_checklist: response.data?.task_checklist_preferences,
76
- commenting: response.data?.commenting_preferences,
77
- },
63
+ savedOverrides: overrides,
64
+ serverEcho: response.data?.task_checklist_preferences,
78
65
  }));
79
66
  }
80
67
  const actions = [
@@ -1,33 +1,30 @@
1
- import { NotificationChannel, NotificationDomain, NotificationFrequency } from '../../entity/notificationRegistry/notificationRegistryState';
1
+ import { NotificationChannel, NotificationFrequency } from '../../entity/notificationRegistry/notificationRegistryState';
2
2
  import { ZeniAPIStatus } from '../../responsePayload';
3
3
  import { NotificationPreferencesPayload } from './notificationPreferencesViewPayload';
4
- import { NotificationPreferencesByDomain, NotificationPreferencesViewState } from './notificationPreferencesViewState';
4
+ import { NotificationPreferences, NotificationPreferencesViewState } from './notificationPreferencesViewState';
5
5
  export declare const initialState: NotificationPreferencesViewState;
6
6
  export interface SetFrequencyPayload {
7
7
  frequency: NotificationFrequency;
8
8
  groupId: string;
9
- domain?: NotificationDomain;
10
9
  }
11
10
  export interface TogglePreferencePayload {
12
11
  channel: NotificationChannel;
13
12
  enabled: boolean;
14
13
  eventId: string;
15
- domain?: NotificationDomain;
16
14
  }
17
15
  export interface SetGroupChannelMasterPayload {
18
16
  channel: NotificationChannel;
19
17
  enabled: boolean;
20
18
  groupId: string;
21
- domain?: NotificationDomain;
22
19
  }
23
20
  export interface FetchNotificationPreferencesSuccessPayload {
24
- preferencesByDomain: Partial<Record<NotificationDomain, NotificationPreferencesPayload | undefined>>;
21
+ preferences: NotificationPreferencesPayload | undefined;
25
22
  saveEpochAtDispatch: number;
26
23
  }
27
24
  export interface SaveNotificationPreferencesSuccessPayload {
28
25
  cancelEpochAtDispatch: number;
29
- savedOverridesByDomain: NotificationPreferencesByDomain;
30
- serverEchoByDomain: Partial<Record<NotificationDomain, NotificationPreferencesPayload | undefined>>;
26
+ savedOverrides: NotificationPreferences;
27
+ serverEcho: NotificationPreferencesPayload | undefined;
31
28
  }
32
29
  export interface SaveNotificationPreferencesFailurePayload {
33
30
  cancelEpochAtDispatch: number;
@@ -3,27 +3,16 @@ var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.toggleEventChannel = exports.setGroupFrequency = exports.setGroupChannelMaster = exports.saveNotificationPreferencesSuccess = exports.saveNotificationPreferencesFailure = exports.saveNotificationPreferences = exports.fetchNotificationPreferencesSuccess = exports.clearNotificationPreferencesLocalOverrides = exports.clearAllNotificationPreferencesView = exports.initialState = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
- const notificationRegistryState_1 = require("../../entity/notificationRegistry/notificationRegistryState");
7
6
  const rootActions_1 = require("../../rootActions");
8
7
  const notificationPreferencesViewPayload_1 = require("./notificationPreferencesViewPayload");
9
8
  const notificationPreferencesViewState_1 = require("./notificationPreferencesViewState");
10
9
  exports.initialState = {
11
10
  cancelEpoch: 0,
12
- localOverridesByDomain: {},
13
- preferencesByDomain: {},
11
+ localOverrides: (0, notificationPreferencesViewState_1.emptyNotificationPreferences)(),
12
+ preferences: (0, notificationPreferencesViewState_1.emptyNotificationPreferences)(),
14
13
  saveEpoch: 0,
15
14
  savePreferencesState: { fetchState: 'Not-Started' },
16
15
  };
17
- // Lazy: a gate-off tenant never receives that domain's key at all.
18
- const overridesFor = (byDomain, domain) => {
19
- const existing = byDomain[domain];
20
- if (existing != null) {
21
- return existing;
22
- }
23
- const created = (0, notificationPreferencesViewState_1.emptyNotificationPreferences)();
24
- byDomain[domain] = created;
25
- return created;
26
- };
27
16
  const mergePreferences = (base, patch) => {
28
17
  const eventEnabledByChannel = {
29
18
  ...base.eventEnabledByChannel,
@@ -161,8 +150,7 @@ const notificationPreferencesView = (0, toolkit_1.createSlice)({
161
150
  // Success/Failure never dispatches, subsequent legitimate saves
162
151
  // still work because their captured epoch matches the current one.
163
152
  draft.cancelEpoch += 1;
164
- // One shared Save/Cancel footer, so Cancel discards every domain.
165
- draft.localOverridesByDomain = {};
153
+ draft.localOverrides = (0, notificationPreferencesViewState_1.emptyNotificationPreferences)();
166
154
  // Also drop `savePreferencesState` back to Not-Started so any
167
155
  // "Saving…" affordance bound to `getNotificationPreferencesSaveState`
168
156
  // clears on Cancel. Without this, a Cancel-during-save whose stale
@@ -179,6 +167,9 @@ const notificationPreferencesView = (0, toolkit_1.createSlice)({
179
167
  // them; the save-success path is the only clearer.
180
168
  // A `null`/`undefined` payload isn't a snapshot at all (e.g. the
181
169
  // envelope key was omitted); no-op instead of wiping preferences.
170
+ if (action.payload.preferences == null) {
171
+ return;
172
+ }
182
173
  // Stale-GET guard (Cursor Bugbot 3632510237): if the fetch epic
183
174
  // captured a `saveEpoch` lower than the current one, a save has
184
175
  // succeeded since this GET dispatched — the response is carrying
@@ -188,13 +179,7 @@ const notificationPreferencesView = (0, toolkit_1.createSlice)({
188
179
  if (action.payload.saveEpochAtDispatch < draft.saveEpoch) {
189
180
  return;
190
181
  }
191
- Object.entries(action.payload.preferencesByDomain).forEach(([domain, payload]) => {
192
- if (payload == null) {
193
- return;
194
- }
195
- draft.preferencesByDomain[domain] =
196
- (0, notificationPreferencesViewPayload_1.mapPayloadToPreferences)(payload);
197
- });
182
+ draft.preferences = (0, notificationPreferencesViewPayload_1.mapPayloadToPreferences)(action.payload.preferences);
198
183
  },
199
184
  saveNotificationPreferences(draft) {
200
185
  draft.savePreferencesState = { fetchState: 'In-Progress' };
@@ -253,44 +238,33 @@ const notificationPreferencesView = (0, toolkit_1.createSlice)({
253
238
  // skip the `preferences` replace. Cursor Bugbot 3632510237.
254
239
  draft.saveEpoch += 1;
255
240
  draft.savePreferencesState = { fetchState: 'Completed' };
256
- Object.entries(action.payload.savedOverridesByDomain).forEach(([rawDomain, savedOverrides]) => {
257
- if (savedOverrides == null) {
258
- return;
259
- }
260
- const domain = rawDomain;
261
- const serverEcho = action.payload.serverEchoByDomain[domain];
262
- const patch = serverEcho == null
263
- ? savedOverrides
264
- : (0, notificationPreferencesViewPayload_1.mapPayloadToPreferences)(serverEcho);
265
- draft.preferencesByDomain[domain] = mergePreferences(draft.preferencesByDomain[domain] ?? (0, notificationPreferencesViewState_1.emptyNotificationPreferences)(), patch);
266
- draft.localOverridesByDomain[domain] = subtractSavedOverrides(draft.localOverridesByDomain[domain] ??
267
- (0, notificationPreferencesViewState_1.emptyNotificationPreferences)(), savedOverrides);
268
- });
241
+ const patch = action.payload.serverEcho == null
242
+ ? action.payload.savedOverrides
243
+ : (0, notificationPreferencesViewPayload_1.mapPayloadToPreferences)(action.payload.serverEcho);
244
+ draft.preferences = mergePreferences(draft.preferences, patch);
245
+ draft.localOverrides = subtractSavedOverrides(draft.localOverrides, action.payload.savedOverrides);
269
246
  },
270
247
  setGroupChannelMaster(draft, action) {
271
248
  // Mirror of `toggleEventChannel` but scoped to the group-channel master
272
249
  // held under `groupChannelEnabledByGroupId[groupId][channel]`.
273
250
  const { channel, enabled, groupId } = action.payload;
274
- const overrides = overridesFor(draft.localOverridesByDomain, action.payload.domain ?? notificationRegistryState_1.DEFAULT_NOTIFICATION_DOMAIN);
275
251
  const groupMap = {
276
- ...(overrides.groupChannelEnabledByGroupId[groupId] ?? {}),
252
+ ...(draft.localOverrides.groupChannelEnabledByGroupId[groupId] ?? {}),
277
253
  };
278
254
  groupMap[channel] = enabled;
279
- overrides.groupChannelEnabledByGroupId[groupId] = groupMap;
255
+ draft.localOverrides.groupChannelEnabledByGroupId[groupId] = groupMap;
280
256
  },
281
257
  setGroupFrequency(draft, action) {
282
- const overrides = overridesFor(draft.localOverridesByDomain, action.payload.domain ?? notificationRegistryState_1.DEFAULT_NOTIFICATION_DOMAIN);
283
- overrides.groupFrequencyByGroupId[action.payload.groupId] =
258
+ draft.localOverrides.groupFrequencyByGroupId[action.payload.groupId] =
284
259
  action.payload.frequency;
285
260
  },
286
261
  toggleEventChannel(draft, action) {
287
262
  const { channel, enabled, eventId } = action.payload;
288
- const overrides = overridesFor(draft.localOverridesByDomain, action.payload.domain ?? notificationRegistryState_1.DEFAULT_NOTIFICATION_DOMAIN);
289
263
  const eventMap = {
290
- ...(overrides.eventEnabledByChannel[eventId] ?? {}),
264
+ ...(draft.localOverrides.eventEnabledByChannel[eventId] ?? {}),
291
265
  };
292
266
  eventMap[channel] = enabled;
293
- overrides.eventEnabledByChannel[eventId] = eventMap;
267
+ draft.localOverrides.eventEnabledByChannel[eventId] = eventMap;
294
268
  },
295
269
  },
296
270
  extraReducers: (builder) => {
@@ -1,11 +1,7 @@
1
1
  import { FetchStateAndError } from '../../commonStateTypes/common';
2
- import { NotificationDomain } from '../../entity/notificationRegistry/notificationRegistryState';
3
2
  import { RootState } from '../../rootStateTypes';
4
3
  import { NotificationPreferences } from './notificationPreferencesViewState';
5
4
  export declare const getNotificationPreferencesSaveState: (state: RootState) => FetchStateAndError;
6
- export declare const getEffectiveNotificationPreferencesForDomain: (state: RootState, domain: NotificationDomain) => NotificationPreferences;
7
5
  export declare const getEffectiveNotificationPreferences: (state: RootState) => NotificationPreferences;
8
- export declare const getNotificationLocalOverridesForDomain: (state: RootState, domain: NotificationDomain) => NotificationPreferences;
9
6
  export declare const getNotificationLocalOverrides: (state: RootState) => NotificationPreferences;
10
- export declare const hasUnsavedNotificationPreferencesForDomain: (state: RootState, domain: NotificationDomain) => boolean;
11
7
  export declare const hasUnsavedNotificationPreferences: (state: RootState) => boolean;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasUnsavedNotificationPreferences = exports.hasUnsavedNotificationPreferencesForDomain = exports.getNotificationLocalOverrides = exports.getNotificationLocalOverridesForDomain = exports.getEffectiveNotificationPreferences = exports.getEffectiveNotificationPreferencesForDomain = exports.getNotificationPreferencesSaveState = void 0;
3
+ exports.hasUnsavedNotificationPreferences = exports.getNotificationLocalOverrides = exports.getEffectiveNotificationPreferences = exports.getNotificationPreferencesSaveState = void 0;
4
4
  const toolkit_1 = require("@reduxjs/toolkit");
5
- const notificationRegistryState_1 = require("../../entity/notificationRegistry/notificationRegistryState");
6
- const notificationPreferencesViewState_1 = require("./notificationPreferencesViewState");
7
5
  const getView = (state) => state.notificationPreferencesViewState;
8
6
  const getNotificationPreferencesSaveState = (state) => getView(state).savePreferencesState;
9
7
  exports.getNotificationPreferencesSaveState = getNotificationPreferencesSaveState;
@@ -11,12 +9,7 @@ exports.getNotificationPreferencesSaveState = getNotificationPreferencesSaveStat
11
9
  // stable reference while neither input changes — a plain function would
12
10
  // allocate a fresh object on every call and re-render every `useSelector`
13
11
  // consumer on any unrelated dispatch.
14
- const EMPTY_PREFERENCES = (0, notificationPreferencesViewState_1.emptyNotificationPreferences)();
15
- // One per domain: a shared createSelector has a cache of one and would thrash across two.
16
- const effectivePreferencesSelectorByDomain = new Map();
17
- const createEffectivePreferencesSelector = (domain) => (0, toolkit_1.createSelector)((state) => getView(state).preferencesByDomain[domain], (state) => getView(state).localOverridesByDomain[domain], (storedPreferences, storedOverrides) => {
18
- const preferences = storedPreferences ?? EMPTY_PREFERENCES;
19
- const localOverrides = storedOverrides ?? EMPTY_PREFERENCES;
12
+ exports.getEffectiveNotificationPreferences = (0, toolkit_1.createSelector)((state) => getView(state).preferences, (state) => getView(state).localOverrides, (preferences, localOverrides) => {
20
13
  const mergedEventEnabledByChannel = { ...preferences.eventEnabledByChannel };
21
14
  Object.entries(localOverrides.eventEnabledByChannel).forEach(([eventId, channels]) => {
22
15
  mergedEventEnabledByChannel[eventId] = {
@@ -40,26 +33,8 @@ const createEffectivePreferencesSelector = (domain) => (0, toolkit_1.createSelec
40
33
  },
41
34
  };
42
35
  });
43
- const getEffectiveNotificationPreferencesForDomain = (state, domain) => {
44
- let selector = effectivePreferencesSelectorByDomain.get(domain);
45
- if (selector == null) {
46
- selector = createEffectivePreferencesSelector(domain);
47
- effectivePreferencesSelectorByDomain.set(domain, selector);
48
- }
49
- return selector(state);
50
- };
51
- exports.getEffectiveNotificationPreferencesForDomain = getEffectiveNotificationPreferencesForDomain;
52
- const getEffectiveNotificationPreferences = (state) => (0, exports.getEffectiveNotificationPreferencesForDomain)(state, notificationRegistryState_1.DEFAULT_NOTIFICATION_DOMAIN);
53
- exports.getEffectiveNotificationPreferences = getEffectiveNotificationPreferences;
54
- const getNotificationLocalOverridesForDomain = (state, domain) => getView(state).localOverridesByDomain[domain] ?? EMPTY_PREFERENCES;
55
- exports.getNotificationLocalOverridesForDomain = getNotificationLocalOverridesForDomain;
56
- const getNotificationLocalOverrides = (state) => (0, exports.getNotificationLocalOverridesForDomain)(state, notificationRegistryState_1.DEFAULT_NOTIFICATION_DOMAIN);
36
+ const getNotificationLocalOverrides = (state) => getView(state).localOverrides;
57
37
  exports.getNotificationLocalOverrides = getNotificationLocalOverrides;
58
- const isDirty = (localOverrides) => Object.keys(localOverrides.eventEnabledByChannel).length > 0 ||
38
+ exports.hasUnsavedNotificationPreferences = (0, toolkit_1.createSelector)((state) => getView(state).localOverrides, (localOverrides) => Object.keys(localOverrides.eventEnabledByChannel).length > 0 ||
59
39
  Object.keys(localOverrides.groupChannelEnabledByGroupId).length > 0 ||
60
- Object.keys(localOverrides.groupFrequencyByGroupId).length > 0;
61
- const hasUnsavedNotificationPreferencesForDomain = (state, domain) => isDirty((0, exports.getNotificationLocalOverridesForDomain)(state, domain));
62
- exports.hasUnsavedNotificationPreferencesForDomain = hasUnsavedNotificationPreferencesForDomain;
63
- // Drives the shared page-level Save/Cancel footer.
64
- const hasUnsavedNotificationPreferences = (state) => Object.values(getView(state).localOverridesByDomain).some((localOverrides) => localOverrides != null && isDirty(localOverrides));
65
- exports.hasUnsavedNotificationPreferences = hasUnsavedNotificationPreferences;
40
+ Object.keys(localOverrides.groupFrequencyByGroupId).length > 0);
@@ -1,5 +1,5 @@
1
1
  import { FetchStateAndError } from '../../commonStateTypes/common';
2
- import { NotificationChannel, NotificationDomain, NotificationFrequency } from '../../entity/notificationRegistry/notificationRegistryState';
2
+ import { NotificationChannel, NotificationFrequency } from '../../entity/notificationRegistry/notificationRegistryState';
3
3
  export interface NotificationPreferences {
4
4
  eventEnabledByChannel: Record<string, Partial<Record<NotificationChannel, boolean>>>;
5
5
  groupChannelEnabledByGroupId: Record<string, Partial<Record<NotificationChannel, boolean>>>;
@@ -7,10 +7,9 @@ export interface NotificationPreferences {
7
7
  }
8
8
  export interface NotificationPreferencesViewState {
9
9
  cancelEpoch: number;
10
- localOverridesByDomain: NotificationPreferencesByDomain;
11
- preferencesByDomain: NotificationPreferencesByDomain;
10
+ localOverrides: NotificationPreferences;
11
+ preferences: NotificationPreferences;
12
12
  saveEpoch: number;
13
13
  savePreferencesState: FetchStateAndError;
14
14
  }
15
- export type NotificationPreferencesByDomain = Partial<Record<NotificationDomain, NotificationPreferences>>;
16
15
  export declare const emptyNotificationPreferences: () => NotificationPreferences;
@@ -41,21 +41,11 @@ const fetchNotificationSettingsEpic = (actions$, state$, zeniAPI) => actions$.pi
41
41
  // 67d6918e.
42
42
  updateActions.push((0, notificationRegistryReducer_1.updateNotificationRegistry)({
43
43
  registry: response.data.task_checklist_registry ?? undefined,
44
- // An absent `<domain>_registry` means that domain's gate is off.
45
- registriesByDomain: {
46
- task_checklist: response.data.task_checklist_registry ?? undefined,
47
- commenting: response.data.commenting_registry ?? undefined,
48
- },
49
44
  registryEpochAtDispatch,
50
45
  }));
51
- // One action so the domains cannot land on different store epochs.
52
- const preferencesByDomain = {
53
- task_checklist: response.data.task_checklist_preferences ?? undefined,
54
- commenting: response.data.commenting_preferences ?? undefined,
55
- };
56
- if (Object.values(preferencesByDomain).some((preferences) => preferences != null)) {
46
+ if (response.data.task_checklist_preferences != null) {
57
47
  updateActions.push((0, notificationPreferencesViewReducer_1.fetchNotificationPreferencesSuccess)({
58
- preferencesByDomain,
48
+ preferences: response.data.task_checklist_preferences,
59
49
  saveEpochAtDispatch,
60
50
  }));
61
51
  }
@@ -37,8 +37,6 @@ export interface NotificationSettingsPayload {
37
37
  pending_bill_approval_notification: RemindersPayload | null;
38
38
  pending_reimbursement_approval_notification: RemindersPayload | null;
39
39
  uncategorized_transaction_notification: RemindersPayload | null;
40
- commenting_preferences?: NotificationPreferencesPayload;
41
- commenting_registry?: NotificationRegistryPayload;
42
40
  month_end_email_recipient_email_ids?: string[];
43
41
  task_checklist_preferences?: NotificationPreferencesPayload;
44
42
  task_checklist_registry?: NotificationRegistryPayload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.2.53-beta0ND",
3
+ "version": "5.2.54-betaRD1",
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",