@zeniai/client-epic-state 5.1.57-betaDI1 → 5.1.57-betaRD2

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 (100) hide show
  1. package/lib/coreEpics.js +2 -3
  2. package/lib/entity/chargeCard/chargeCard.d.ts +1 -1
  3. package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +2 -0
  4. package/lib/entity/jeSchedules/jeSchedulesPayload.js +2 -0
  5. package/lib/entity/jeSchedules/jeSchedulesSelector.d.ts +4 -0
  6. package/lib/entity/jeSchedules/jeSchedulesSelector.js +11 -1
  7. package/lib/entity/jeSchedules/jeSchedulesState.d.ts +2 -0
  8. package/lib/entity/tenant/clearAllEpic.d.ts +1 -3
  9. package/lib/entity/tenant/clearAllEpic.js +0 -4
  10. package/lib/entity/transaction/scheduleTransactionHelper.d.ts +15 -0
  11. package/lib/entity/transaction/scheduleTransactionHelper.js +43 -0
  12. package/lib/epic.d.ts +5 -2
  13. package/lib/epic.js +5 -2
  14. package/lib/esm/coreEpics.js +2 -3
  15. package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +2 -0
  16. package/lib/esm/entity/jeSchedules/jeSchedulesSelector.js +11 -1
  17. package/lib/esm/entity/tenant/clearAllEpic.js +0 -4
  18. package/lib/esm/entity/transaction/scheduleTransactionHelper.js +39 -0
  19. package/lib/esm/epic.js +5 -2
  20. package/lib/esm/index.js +7 -9
  21. package/lib/esm/reducer.js +0 -6
  22. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +15 -2
  23. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +21 -0
  24. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +110 -0
  25. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +53 -0
  26. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +22 -0
  27. package/lib/esm/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +152 -0
  28. package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +126 -6
  29. package/lib/esm/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +1 -0
  30. package/lib/esm/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +71 -0
  31. package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +65 -11
  32. package/lib/esm/view/expenseAutomationView/types/jeSchedulesViewState.js +3 -6
  33. package/lib/esm/view/settingsView/epic/fetchNotificationSettingsEpic.js +2 -21
  34. package/lib/esm/view/settingsView/epic/saveNotificationSettingsEpic.js +1 -2
  35. package/lib/esm/view/settingsView/settingsViewHelpers.js +2 -3
  36. package/lib/index.d.ts +9 -12
  37. package/lib/index.js +58 -56
  38. package/lib/reducer.d.ts +0 -6
  39. package/lib/reducer.js +0 -6
  40. package/lib/view/common/recurringViewHelper.d.ts +2 -2
  41. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +14 -1
  42. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.d.ts +8 -0
  43. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +25 -0
  44. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.d.ts +45 -0
  45. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +114 -0
  46. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.d.ts +8 -0
  47. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +57 -0
  48. package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.d.ts +6 -0
  49. package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +26 -0
  50. package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.d.ts +43 -0
  51. package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +158 -0
  52. package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +1 -0
  53. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +36 -8
  54. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +128 -7
  55. package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.d.ts +25 -0
  56. package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +2 -0
  57. package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +29 -4
  58. package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.d.ts +10 -0
  59. package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +76 -0
  60. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +65 -11
  61. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +53 -6
  62. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.js +5 -8
  63. package/lib/view/settingsView/epic/fetchNotificationSettingsEpic.d.ts +1 -9
  64. package/lib/view/settingsView/epic/fetchNotificationSettingsEpic.js +2 -21
  65. package/lib/view/settingsView/epic/saveNotificationSettingsEpic.js +1 -2
  66. package/lib/view/settingsView/settingsViewHelpers.d.ts +1 -1
  67. package/lib/view/settingsView/settingsViewHelpers.js +2 -3
  68. package/lib/view/settingsView/settingsViewPayload.d.ts +0 -4
  69. package/lib/view/settingsView/settingsViewState.d.ts +1 -1
  70. package/package.json +1 -1
  71. package/lib/entity/notificationRegistry/notificationRegistryPayload.d.ts +0 -18
  72. package/lib/entity/notificationRegistry/notificationRegistryPayload.js +0 -28
  73. package/lib/entity/notificationRegistry/notificationRegistryReducer.d.ts +0 -6
  74. package/lib/entity/notificationRegistry/notificationRegistryReducer.js +0 -26
  75. package/lib/entity/notificationRegistry/notificationRegistrySelector.d.ts +0 -2
  76. package/lib/entity/notificationRegistry/notificationRegistrySelector.js +0 -10
  77. package/lib/entity/notificationRegistry/notificationRegistryState.d.ts +0 -31
  78. package/lib/entity/notificationRegistry/notificationRegistryState.js +0 -10
  79. package/lib/esm/entity/notificationRegistry/notificationRegistryPayload.js +0 -24
  80. package/lib/esm/entity/notificationRegistry/notificationRegistryReducer.js +0 -22
  81. package/lib/esm/entity/notificationRegistry/notificationRegistrySelector.js +0 -6
  82. package/lib/esm/entity/notificationRegistry/notificationRegistryState.js +0 -5
  83. package/lib/esm/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +0 -103
  84. package/lib/esm/view/notificationPreferencesView/notificationPreferencesEndpoint.js +0 -5
  85. package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewPayload.js +0 -36
  86. package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewReducer.js +0 -222
  87. package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewSelector.js +0 -25
  88. package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewState.js +0 -4
  89. package/lib/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.d.ts +0 -34
  90. package/lib/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +0 -107
  91. package/lib/view/notificationPreferencesView/notificationPreferencesEndpoint.d.ts +0 -2
  92. package/lib/view/notificationPreferencesView/notificationPreferencesEndpoint.js +0 -9
  93. package/lib/view/notificationPreferencesView/notificationPreferencesViewPayload.d.ts +0 -7
  94. package/lib/view/notificationPreferencesView/notificationPreferencesViewPayload.js +0 -41
  95. package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.d.ts +0 -30
  96. package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.js +0 -226
  97. package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.d.ts +0 -7
  98. package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.js +0 -32
  99. package/lib/view/notificationPreferencesView/notificationPreferencesViewState.d.ts +0 -14
  100. package/lib/view/notificationPreferencesView/notificationPreferencesViewState.js +0 -8
@@ -1,222 +0,0 @@
1
- import { createSlice } from '@reduxjs/toolkit';
2
- import { mapPayloadToPreferences, } from './notificationPreferencesViewPayload';
3
- import { emptyNotificationPreferences, } from './notificationPreferencesViewState';
4
- export const initialState = {
5
- cancelEpoch: 0,
6
- localOverrides: emptyNotificationPreferences(),
7
- preferences: emptyNotificationPreferences(),
8
- saveEpoch: 0,
9
- savePreferencesState: { fetchState: 'Not-Started' },
10
- };
11
- const mergePreferences = (base, patch) => {
12
- const eventEnabledByChannel = {
13
- ...base.eventEnabledByChannel,
14
- };
15
- Object.entries(patch.eventEnabledByChannel).forEach(([eventId, channels]) => {
16
- eventEnabledByChannel[eventId] = {
17
- ...(base.eventEnabledByChannel[eventId] ?? {}),
18
- ...channels,
19
- };
20
- });
21
- return {
22
- eventEnabledByChannel,
23
- groupFrequencyByGroupId: {
24
- ...base.groupFrequencyByGroupId,
25
- ...patch.groupFrequencyByGroupId,
26
- },
27
- };
28
- };
29
- // Remove only the (eventId, channel) and groupId keys that were actually saved
30
- // to the server from `localOverrides` — AND whose current value still equals
31
- // what was saved. Any new edits the user added while the PUT was in flight
32
- // (either new keys not present in `saved`, OR same keys the user flipped back
33
- // to a different value) are preserved so the next debounce cycle picks them up.
34
- //
35
- // Presence-only subtraction (the prior implementation) silently dropped a
36
- // same-key re-edit that landed AFTER debounce fired but BEFORE the response
37
- // returned. Concrete case:
38
- // 1. toggle evt1.email = false → localOverrides = {evt1:{email:false}}
39
- // 2. debounce PUT #1 fires with savedOverrides = {evt1:{email:false}}
40
- // 3. user re-toggles evt1.email = true → localOverrides = {evt1:{email:true}}
41
- // 4. PUT #1 success → subtract dropped `email` on presence, so the true
42
- // re-edit disappeared and next-debounce found nothing to send.
43
- const subtractSavedOverrides = (current, saved) => {
44
- const eventEnabledByChannel = {};
45
- Object.entries(current.eventEnabledByChannel).forEach(([eventId, channels]) => {
46
- const savedChannels = saved.eventEnabledByChannel[eventId];
47
- if (savedChannels == null) {
48
- eventEnabledByChannel[eventId] = channels;
49
- return;
50
- }
51
- const remainingChannels = {};
52
- Object.keys(channels).forEach((channel) => {
53
- // Preserve the key when it's a new channel OR when the user's
54
- // current value differs from what was saved (same-key re-edit).
55
- if (!(channel in savedChannels) ||
56
- channels[channel] !== savedChannels[channel]) {
57
- remainingChannels[channel] = channels[channel];
58
- }
59
- });
60
- if (Object.keys(remainingChannels).length > 0) {
61
- eventEnabledByChannel[eventId] = remainingChannels;
62
- }
63
- });
64
- const groupFrequencyByGroupId = {};
65
- Object.entries(current.groupFrequencyByGroupId).forEach(([groupId, frequency]) => {
66
- if (saved.groupFrequencyByGroupId[groupId] !== frequency) {
67
- groupFrequencyByGroupId[groupId] = frequency;
68
- }
69
- });
70
- return { eventEnabledByChannel, groupFrequencyByGroupId };
71
- };
72
- const notificationPreferencesView = createSlice({
73
- name: 'notificationPreferencesView',
74
- initialState,
75
- reducers: {
76
- clearAllNotificationPreferencesView(draft) {
77
- // Reset everything EXCEPT `cancelEpoch`, which must stay monotonic
78
- // across the lifetime of the app instance. `initialState.cancelEpoch`
79
- // is `0`; returning `initialState` verbatim would rewind the counter
80
- // to zero, and any in-flight save whose `cancelEpochAtDispatch` was
81
- // captured pre-clearAll (>0) would then satisfy the "captured >=
82
- // current" epoch guard and merge stale edits into fresh preferences.
83
- // Bumping instead of resetting also invalidates the abandoned save
84
- // for free — Cursor Bugbot bc7876f1 followup.
85
- const nextCancelEpoch = draft.cancelEpoch + 1;
86
- // saveEpoch must also stay monotonic across clearAll for the same
87
- // reason (Cursor Bugbot 3632510237). Rewinding to 0 would let a
88
- // stale-in-flight GET whose `saveEpochAtDispatch` was captured >0
89
- // satisfy the "captured >= current" epoch guard and clobber fresh
90
- // preferences on any subsequent save.
91
- const nextSaveEpoch = draft.saveEpoch + 1;
92
- return {
93
- ...initialState,
94
- cancelEpoch: nextCancelEpoch,
95
- saveEpoch: nextSaveEpoch,
96
- };
97
- },
98
- clearNotificationPreferencesLocalOverrides(draft) {
99
- // Discards in-flight per-event/per-group edits held in `localOverrides`
100
- // without touching the fetched `preferences` snapshot. Used by the
101
- // settings-page Cancel affordance so the effective preferences revert
102
- // to the last server-known state without triggering a refetch race.
103
- //
104
- // Cancel/in-flight-save race: every Cancel bumps `cancelEpoch`
105
- // monotonically. Any save that captured a lower epoch value at
106
- // dispatch time is treated as stale by the Success/Failure reducer
107
- // — its merge is skipped. Unconditional bump (vs the earlier
108
- // counter model) survives switchMap abandonment and double-Cancel
109
- // (Cursor Bugbot 4aa021f7): even if the abandoned save's
110
- // Success/Failure never dispatches, subsequent legitimate saves
111
- // still work because their captured epoch matches the current one.
112
- draft.cancelEpoch += 1;
113
- draft.localOverrides = emptyNotificationPreferences();
114
- // Also drop `savePreferencesState` back to Not-Started so any
115
- // "Saving…" affordance bound to `getNotificationPreferencesSaveState`
116
- // clears on Cancel. Without this, a Cancel-during-save whose stale
117
- // Success/Failure never fires (switchMap abandonment) leaves the
118
- // selector reporting In-Progress forever — Cursor Bugbot bc7876f1.
119
- draft.savePreferencesState = { fetchState: 'Not-Started' };
120
- },
121
- fetchNotificationPreferencesSuccess(draft, action) {
122
- // Piggybacks on the settings-envelope fetch. The GET response is a full
123
- // snapshot of the server-known preferences (empty maps included), so
124
- // REPLACE `preferences` rather than merging — merging would leak keys
125
- // the server has since removed. DO NOT touch `localOverrides`: a refetch
126
- // that fires while the user has in-flight edits (pre-debounce) must not
127
- // silently drop them; the save-success path is the only clearer.
128
- // A `null`/`undefined` payload isn't a snapshot at all (e.g. the
129
- // envelope key was omitted); no-op instead of wiping preferences.
130
- if (action.payload.preferences == null) {
131
- return;
132
- }
133
- // Stale-GET guard (Cursor Bugbot 3632510237): if the fetch epic
134
- // captured a `saveEpoch` lower than the current one, a save has
135
- // succeeded since this GET dispatched — the response is carrying
136
- // the pre-PUT snapshot and would clobber the just-saved server
137
- // truth back to the pre-edit state until the next refetch. Skip
138
- // the replace; the store already reflects the fresher save.
139
- if (action.payload.saveEpochAtDispatch < draft.saveEpoch) {
140
- return;
141
- }
142
- draft.preferences = mapPayloadToPreferences(action.payload.preferences);
143
- },
144
- saveNotificationPreferences(draft) {
145
- draft.savePreferencesState = { fetchState: 'In-Progress' };
146
- },
147
- saveNotificationPreferencesFailure(draft, action) {
148
- // Stale failure from a cancelled-since save — swallow silently so
149
- // the UI doesn't surface an error banner for a save the user
150
- // already abandoned.
151
- if (action.payload.cancelEpochAtDispatch < draft.cancelEpoch) {
152
- return;
153
- }
154
- // Preserve `localOverrides` so the user's in-flight edits survive a
155
- // transient network blip. UI should surface an error affordance and
156
- // allow retry.
157
- draft.savePreferencesState = {
158
- fetchState: 'Error',
159
- error: action.payload.error,
160
- };
161
- },
162
- saveNotificationPreferencesSuccess(draft, action) {
163
- // Preserve-on-partial: PUT /preferences is patch-semantic. The response
164
- // echoes only the fields that changed, so merge into `preferences`
165
- // instead of replacing — otherwise a single-channel toggle would wipe
166
- // every other stored preference.
167
- //
168
- // Rollback invariant (F5): `serverEcho` may be `undefined` if the server
169
- // rolls back to an older shape that omits the echo entirely. In that
170
- // case fall back to merging `savedOverrides` into `preferences` — the
171
- // PUT succeeded (2xx), so the values we sent are now server truth. If
172
- // we merged an empty patch instead, `subtractSavedOverrides` would
173
- // still strip the just-saved keys from `localOverrides`, leaving the
174
- // effective preferences (preferences ∪ localOverrides) reverted to the
175
- // pre-edit server snapshot until the next refetch.
176
- //
177
- // In-flight-edit invariant: `savedOverrides` is the exact snapshot the
178
- // epic PUT to the server. Subtracting those keys from `localOverrides`
179
- // (instead of clearing it wholesale) preserves any edits the user
180
- // added AFTER the debounce fired but BEFORE the response landed. The
181
- // next debounce cycle will pick them up. Clearing wholesale drops
182
- // in-flight edits from both UI (once server echo lands) and server.
183
- // Cancel/in-flight-save race: `cancelEpoch` monotonically increases
184
- // on every Cancel. If the save captured a lower epoch at dispatch,
185
- // the user has pressed Cancel since — skip the `preferences` merge
186
- // and the `localOverrides` subtract (Cancel already emptied it).
187
- // Do NOT flip fetchState so a subsequent legit save can still show
188
- // its own In-Progress → Completed lifecycle. The server itself has
189
- // accepted the write — reverting server-side is out of FE scope; UI
190
- // reflects the cancelled intention until the next refetch merges
191
- // whatever the server persisted.
192
- if (action.payload.cancelEpochAtDispatch < draft.cancelEpoch) {
193
- return;
194
- }
195
- // Bump `saveEpoch` so any settings-envelope GET that was in flight
196
- // BEFORE this PUT resolved is treated as stale. Its captured epoch
197
- // will be lower than the new value, so its reducer branch will
198
- // skip the `preferences` replace. Cursor Bugbot 3632510237.
199
- draft.saveEpoch += 1;
200
- draft.savePreferencesState = { fetchState: 'Completed' };
201
- const patch = action.payload.serverEcho == null
202
- ? action.payload.savedOverrides
203
- : mapPayloadToPreferences(action.payload.serverEcho);
204
- draft.preferences = mergePreferences(draft.preferences, patch);
205
- draft.localOverrides = subtractSavedOverrides(draft.localOverrides, action.payload.savedOverrides);
206
- },
207
- setGroupFrequency(draft, action) {
208
- draft.localOverrides.groupFrequencyByGroupId[action.payload.groupId] =
209
- action.payload.frequency;
210
- },
211
- toggleEventChannel(draft, action) {
212
- const { channel, enabled, eventId } = action.payload;
213
- const eventMap = {
214
- ...(draft.localOverrides.eventEnabledByChannel[eventId] ?? {}),
215
- };
216
- eventMap[channel] = enabled;
217
- draft.localOverrides.eventEnabledByChannel[eventId] = eventMap;
218
- },
219
- },
220
- });
221
- export const { clearAllNotificationPreferencesView, clearNotificationPreferencesLocalOverrides, fetchNotificationPreferencesSuccess, saveNotificationPreferences, saveNotificationPreferencesFailure, saveNotificationPreferencesSuccess, setGroupFrequency, toggleEventChannel, } = notificationPreferencesView.actions;
222
- export default notificationPreferencesView.reducer;
@@ -1,25 +0,0 @@
1
- const getView = (state) => state.notificationPreferencesViewState;
2
- export const getNotificationPreferencesSaveState = (state) => getView(state).savePreferencesState;
3
- export const getEffectiveNotificationPreferences = (state) => {
4
- const view = getView(state);
5
- const mergedEventEnabledByChannel = { ...view.preferences.eventEnabledByChannel };
6
- Object.entries(view.localOverrides.eventEnabledByChannel).forEach(([eventId, channels]) => {
7
- mergedEventEnabledByChannel[eventId] = {
8
- ...(view.preferences.eventEnabledByChannel[eventId] ?? {}),
9
- ...channels,
10
- };
11
- });
12
- return {
13
- eventEnabledByChannel: mergedEventEnabledByChannel,
14
- groupFrequencyByGroupId: {
15
- ...view.preferences.groupFrequencyByGroupId,
16
- ...view.localOverrides.groupFrequencyByGroupId,
17
- },
18
- };
19
- };
20
- export const getNotificationLocalOverrides = (state) => getView(state).localOverrides;
21
- export const hasUnsavedNotificationPreferences = (state) => {
22
- const overrides = getView(state).localOverrides;
23
- return (Object.keys(overrides.eventEnabledByChannel).length > 0 ||
24
- Object.keys(overrides.groupFrequencyByGroupId).length > 0);
25
- };
@@ -1,4 +0,0 @@
1
- export const emptyNotificationPreferences = () => ({
2
- eventEnabledByChannel: {},
3
- groupFrequencyByGroupId: {},
4
- });
@@ -1,34 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { openSnackbar } from '../../../entity/snackbar/snackbarReducer';
3
- import { RootState } from '../../../reducer';
4
- import { ZeniAPI } from '../../../zeniAPI';
5
- import { saveNotificationPreferences, saveNotificationPreferencesFailure, saveNotificationPreferencesSuccess, setGroupFrequency, toggleEventChannel } from '../notificationPreferencesViewReducer';
6
- export type ActionType = ReturnType<typeof saveNotificationPreferences> | ReturnType<typeof saveNotificationPreferencesFailure> | ReturnType<typeof saveNotificationPreferencesSuccess> | ReturnType<typeof setGroupFrequency> | ReturnType<typeof toggleEventChannel> | ReturnType<typeof openSnackbar>;
7
- export declare const saveNotificationPreferencesEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => import("rxjs").Observable<{
8
- payload: {
9
- messageSection: import("../../..").SnackbarMessageSections;
10
- messageText: import("../../..").SnackbarMessageSectionTexts;
11
- type: import("../../..").SnackbarMessageType;
12
- showStatusIcon?: boolean;
13
- variables?: {
14
- variableName: string;
15
- variableValue: string;
16
- }[];
17
- };
18
- type: "snackbar/openSnackbar";
19
- } | {
20
- payload: undefined;
21
- type: "notificationPreferencesView/saveNotificationPreferences";
22
- } | {
23
- payload: import("../notificationPreferencesViewReducer").SaveNotificationPreferencesFailurePayload;
24
- type: "notificationPreferencesView/saveNotificationPreferencesFailure";
25
- } | {
26
- payload: import("../notificationPreferencesViewReducer").SaveNotificationPreferencesSuccessPayload;
27
- type: "notificationPreferencesView/saveNotificationPreferencesSuccess";
28
- } | {
29
- payload: import("../notificationPreferencesViewReducer").SetFrequencyPayload;
30
- type: "notificationPreferencesView/setGroupFrequency";
31
- } | {
32
- payload: import("../notificationPreferencesViewReducer").TogglePreferencePayload;
33
- type: "notificationPreferencesView/toggleEventChannel";
34
- }>;
@@ -1,107 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.saveNotificationPreferencesEpic = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- const snackbarReducer_1 = require("../../../entity/snackbar/snackbarReducer");
7
- const responsePayload_1 = require("../../../responsePayload");
8
- const notificationPreferencesEndpoint_1 = require("../notificationPreferencesEndpoint");
9
- const notificationPreferencesViewPayload_1 = require("../notificationPreferencesViewPayload");
10
- const notificationPreferencesViewReducer_1 = require("../notificationPreferencesViewReducer");
11
- const notificationPreferencesViewSelector_1 = require("../notificationPreferencesViewSelector");
12
- const DEBOUNCE_MS = 300;
13
- const saveNotificationPreferencesEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)((action) => notificationPreferencesViewReducer_1.toggleEventChannel.match(action) || notificationPreferencesViewReducer_1.setGroupFrequency.match(action)),
14
- // Coalesce bursts of toggles into a single PUT. Trade-off: rapid clickers
15
- // defer saves until they pause. Consider a max-wait wrapper if this
16
- // becomes a UX problem.
17
- (0, operators_1.debounceTime)(DEBOUNCE_MS), (0, operators_1.withLatestFrom)(state$),
18
- // `switchMap` unsubscribes from any in-flight PUT observable when a new
19
- // debounced batch fires. The prior HTTP request has already left the
20
- // client — the network call is NOT cancelled — but its response is
21
- // ignored, so stale success/failure actions cannot clobber the newer
22
- // batch's state. Server-side ordering is arrival-order LWW.
23
- (0, operators_1.switchMap)(([, state]) => {
24
- const overrides = (0, notificationPreferencesViewSelector_1.getNotificationLocalOverrides)(state);
25
- const preferencesPatch = (0, notificationPreferencesViewPayload_1.mapPreferencesToPayload)(overrides);
26
- if (Object.keys(preferencesPatch).length === 0) {
27
- // No diff → do not dispatch a synthetic success (that would wipe
28
- // stored preferences via the reducer). Simply no-op.
29
- return rxjs_1.EMPTY;
30
- }
31
- // Snapshot the Cancel epoch at PUT-dispatch time. Every Cancel bumps
32
- // `cancelEpoch`; the reducer compares the captured value on Success/
33
- // Failure and skips the merge when the value has advanced (user
34
- // pressed Cancel since this save started). See Cursor Bugbot 4aa021f7
35
- // — the earlier counter model failed when `switchMap` abandoned an
36
- // in-flight save's response (Success/Failure never dispatched, so
37
- // the counter never drained and future saves got their merge dropped).
38
- const cancelEpochAtDispatch = state.notificationPreferencesViewState.cancelEpoch;
39
- const body = { task_checklist_preferences: preferencesPatch };
40
- // Suppress the error snackbar when the response lands AFTER the user
41
- // pressed Cancel — the Failure reducer already swallows the state
42
- // update, so the toast would be a stale error for a save the user
43
- // abandoned. `StateObservable#value` reads the current cancelEpoch at
44
- // response time (not at dispatch time — that's what
45
- // `cancelEpochAtDispatch` captures). Cursor Bugbot da2f4fe2 + Nikunj.
46
- const errorSnackbar = (0, snackbarReducer_1.openSnackbar)({
47
- messageSection: 'notification_settings_saved',
48
- messageText: 'failed',
49
- type: 'error',
50
- });
51
- const isCancelledSince = () => cancelEpochAtDispatch <
52
- state$.value.notificationPreferencesViewState.cancelEpoch;
53
- // Abort the in-flight HTTP request when `switchMap` disposes this
54
- // observable (new debounced batch fires, tenant switch, unmount).
55
- // Without an AbortSignal, `switchMap` would drop the response
56
- // client-side but the older PUT would still land on the server —
57
- // under patch-semantic LWW, a slower older PUT arriving after a
58
- // newer one silently reverts the user's latest choice on the
59
- // server. Cursor Bugbot e3861a76. `AbortController.abort()` is
60
- // idempotent so it's safe if the request already completed.
61
- const controller = new AbortController();
62
- const request$ = zeniAPI
63
- .putAndGetJSON((0, notificationPreferencesEndpoint_1.notificationPreferencesUrl)(zeniAPI), body, undefined, controller.signal)
64
- .pipe((0, operators_1.mergeMap)((response) => {
65
- if ((0, responsePayload_1.isSuccessResponse)(response)) {
66
- return (0, rxjs_1.of)((0, notificationPreferencesViewReducer_1.saveNotificationPreferencesSuccess)({
67
- cancelEpochAtDispatch,
68
- savedOverrides: overrides,
69
- serverEcho: response.data?.task_checklist_preferences,
70
- }));
71
- }
72
- const actions = [
73
- (0, notificationPreferencesViewReducer_1.saveNotificationPreferencesFailure)({
74
- cancelEpochAtDispatch,
75
- error: response.status,
76
- }),
77
- ];
78
- if (!isCancelledSince()) {
79
- // Surface a user-visible error — without it the UI reverts to
80
- // server truth after debounce and the failed toggle looks like
81
- // a mystery UI bug.
82
- actions.push(errorSnackbar);
83
- }
84
- return (0, rxjs_1.of)(...actions);
85
- }), (0, operators_1.catchError)((error) => {
86
- const actions = [
87
- (0, notificationPreferencesViewReducer_1.saveNotificationPreferencesFailure)({
88
- cancelEpochAtDispatch,
89
- error: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Save notification preferences failed: ' +
90
- JSON.stringify(error)),
91
- }),
92
- ];
93
- if (!isCancelledSince()) {
94
- actions.push(errorSnackbar);
95
- }
96
- return (0, rxjs_1.of)(...actions);
97
- }), (0, operators_1.finalize)(() => {
98
- // switchMap disposal (new batch fires, cancel, unmount) → abort
99
- // the still-in-flight HTTP request. No-op if the request has
100
- // already completed successfully or errored.
101
- controller.abort();
102
- }));
103
- // Flip savePreferencesState to In-Progress BEFORE the network call so
104
- // any "saving…" UI can render.
105
- return (0, rxjs_1.concat)((0, rxjs_1.of)((0, notificationPreferencesViewReducer_1.saveNotificationPreferences)()), request$);
106
- }));
107
- exports.saveNotificationPreferencesEpic = saveNotificationPreferencesEpic;
@@ -1,2 +0,0 @@
1
- import { ZeniAPI } from '../../zeniAPI';
2
- export declare const notificationPreferencesUrl: (zeniAPI: ZeniAPI) => string;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.notificationPreferencesUrl = void 0;
4
- // Shared endpoint used by both the GET (envelope refresh in
5
- // `fetchNotificationSettingsEpic`) and the PUT (patch in
6
- // `saveNotificationPreferencesEpic`). Kept as a helper so an endpoint rename
7
- // can't drift between the two callers.
8
- const notificationPreferencesUrl = (zeniAPI) => `${zeniAPI.apiEndPoints.notificationMicroServiceBaseUrl}/1.0/notification-preferences`;
9
- exports.notificationPreferencesUrl = notificationPreferencesUrl;
@@ -1,7 +0,0 @@
1
- import { NotificationPreferences } from './notificationPreferencesViewState';
2
- export interface NotificationPreferencesPayload {
3
- event_enabled_by_channel?: Record<string, Record<string, boolean>>;
4
- group_frequency_by_group_id?: Record<string, string>;
5
- }
6
- export declare const mapPayloadToPreferences: (payload?: NotificationPreferencesPayload) => NotificationPreferences;
7
- export declare const mapPreferencesToPayload: (preferences: NotificationPreferences) => Record<string, unknown>;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapPreferencesToPayload = exports.mapPayloadToPreferences = void 0;
4
- const notificationRegistryState_1 = require("../../entity/notificationRegistry/notificationRegistryState");
5
- const mapEventEnabledByChannel = (raw) => {
6
- if (raw == null) {
7
- return {};
8
- }
9
- const out = {};
10
- Object.entries(raw).forEach(([eventId, channelMap]) => {
11
- const mapped = {};
12
- Object.entries(channelMap).forEach(([channel, enabled]) => {
13
- mapped[(0, notificationRegistryState_1.toNotificationChannel)(channel)] = enabled;
14
- });
15
- out[eventId] = mapped;
16
- });
17
- return out;
18
- };
19
- const mapPayloadToPreferences = (payload) => {
20
- const groupFrequencyRaw = payload?.group_frequency_by_group_id ?? {};
21
- const groupFrequencyByGroupId = Object.fromEntries(Object.entries(groupFrequencyRaw).map(([groupId, frequency]) => [
22
- groupId,
23
- (0, notificationRegistryState_1.toNotificationFrequency)(frequency),
24
- ]));
25
- return {
26
- eventEnabledByChannel: mapEventEnabledByChannel(payload?.event_enabled_by_channel),
27
- groupFrequencyByGroupId,
28
- };
29
- };
30
- exports.mapPayloadToPreferences = mapPayloadToPreferences;
31
- const mapPreferencesToPayload = (preferences) => {
32
- const payload = {};
33
- if (Object.keys(preferences.eventEnabledByChannel).length > 0) {
34
- payload.event_enabled_by_channel = preferences.eventEnabledByChannel;
35
- }
36
- if (Object.keys(preferences.groupFrequencyByGroupId).length > 0) {
37
- payload.group_frequency_by_group_id = preferences.groupFrequencyByGroupId;
38
- }
39
- return payload;
40
- };
41
- exports.mapPreferencesToPayload = mapPreferencesToPayload;
@@ -1,30 +0,0 @@
1
- import { NotificationChannel, NotificationFrequency } from '../../entity/notificationRegistry/notificationRegistryState';
2
- import { ZeniAPIStatus } from '../../responsePayload';
3
- import { NotificationPreferencesPayload } from './notificationPreferencesViewPayload';
4
- import { NotificationPreferences, NotificationPreferencesViewState } from './notificationPreferencesViewState';
5
- export declare const initialState: NotificationPreferencesViewState;
6
- export interface SetFrequencyPayload {
7
- frequency: NotificationFrequency;
8
- groupId: string;
9
- }
10
- export interface TogglePreferencePayload {
11
- channel: NotificationChannel;
12
- enabled: boolean;
13
- eventId: string;
14
- }
15
- export interface FetchNotificationPreferencesSuccessPayload {
16
- preferences: NotificationPreferencesPayload | undefined;
17
- saveEpochAtDispatch: number;
18
- }
19
- export interface SaveNotificationPreferencesSuccessPayload {
20
- cancelEpochAtDispatch: number;
21
- savedOverrides: NotificationPreferences;
22
- serverEcho: NotificationPreferencesPayload | undefined;
23
- }
24
- export interface SaveNotificationPreferencesFailurePayload {
25
- cancelEpochAtDispatch: number;
26
- error?: ZeniAPIStatus;
27
- }
28
- export declare const clearAllNotificationPreferencesView: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"notificationPreferencesView/clearAllNotificationPreferencesView">, clearNotificationPreferencesLocalOverrides: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"notificationPreferencesView/clearNotificationPreferencesLocalOverrides">, fetchNotificationPreferencesSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<FetchNotificationPreferencesSuccessPayload, "notificationPreferencesView/fetchNotificationPreferencesSuccess">, saveNotificationPreferences: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"notificationPreferencesView/saveNotificationPreferences">, saveNotificationPreferencesFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<SaveNotificationPreferencesFailurePayload, "notificationPreferencesView/saveNotificationPreferencesFailure">, saveNotificationPreferencesSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<SaveNotificationPreferencesSuccessPayload, "notificationPreferencesView/saveNotificationPreferencesSuccess">, setGroupFrequency: import("@reduxjs/toolkit").ActionCreatorWithPayload<SetFrequencyPayload, "notificationPreferencesView/setGroupFrequency">, toggleEventChannel: import("@reduxjs/toolkit").ActionCreatorWithPayload<TogglePreferencePayload, "notificationPreferencesView/toggleEventChannel">;
29
- declare const _default: import("redux").Reducer<NotificationPreferencesViewState>;
30
- export default _default;