@zeniai/client-epic-state 5.1.61 → 5.1.62
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.
- package/lib/coreEpics.js +3 -2
- package/lib/entity/chargeCard/chargeCard.d.ts +1 -1
- package/lib/entity/notificationRegistry/notificationRegistryPayload.d.ts +18 -0
- package/lib/entity/notificationRegistry/notificationRegistryPayload.js +28 -0
- package/lib/entity/notificationRegistry/notificationRegistryReducer.d.ts +10 -0
- package/lib/entity/notificationRegistry/notificationRegistryReducer.js +50 -0
- package/lib/entity/notificationRegistry/notificationRegistrySelector.d.ts +2 -0
- package/lib/entity/notificationRegistry/notificationRegistrySelector.js +10 -0
- package/lib/entity/notificationRegistry/notificationRegistryState.d.ts +32 -0
- package/lib/entity/notificationRegistry/notificationRegistryState.js +10 -0
- package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
- package/lib/entity/snackbar/snackbarTypes.js +3 -0
- package/lib/entity/tenant/clearAllEpic.d.ts +3 -1
- package/lib/entity/tenant/clearAllEpic.js +4 -0
- package/lib/entity/tenant/tenantReducer.d.ts +4 -1
- package/lib/entity/tenant/tenantReducer.js +8 -2
- package/lib/entity/tenant/tenantSelector.d.ts +1 -0
- package/lib/entity/tenant/tenantSelector.js +4 -0
- package/lib/epic.d.ts +5 -1
- package/lib/epic.js +5 -1
- package/lib/esm/coreEpics.js +3 -2
- package/lib/esm/entity/notificationRegistry/notificationRegistryPayload.js +24 -0
- package/lib/esm/entity/notificationRegistry/notificationRegistryReducer.js +46 -0
- package/lib/esm/entity/notificationRegistry/notificationRegistrySelector.js +6 -0
- package/lib/esm/entity/notificationRegistry/notificationRegistryState.js +5 -0
- package/lib/esm/entity/snackbar/snackbarTypes.js +3 -0
- package/lib/esm/entity/tenant/clearAllEpic.js +4 -0
- package/lib/esm/entity/tenant/tenantReducer.js +7 -1
- package/lib/esm/entity/tenant/tenantSelector.js +3 -0
- package/lib/esm/epic.js +5 -1
- package/lib/esm/index.js +7 -2
- package/lib/esm/reducer.js +6 -0
- package/lib/esm/view/companyView/companyViewReducer.js +68 -1
- package/lib/esm/view/companyView/epic/companyPassport/dismissCapitalizationOnboardingEpic.js +2 -1
- package/lib/esm/view/companyView/epic/companyPassport/projects/disableAccountingProjectsEpic.js +56 -0
- package/lib/esm/view/companyView/epic/companyPassport/projects/enableAccountingProjectsEpic.js +37 -0
- package/lib/esm/view/companyView/epic/companyPassport/projects/resumeEnableAccountingProjectsEpic.js +73 -0
- package/lib/esm/view/companyView/epic/companyPassport/updateAccountingClassesEnabledEpic.js +2 -1
- package/lib/esm/view/companyView/epic/companyPassport/updateCapitalizationAccountThresholdEpic.js +2 -1
- package/lib/esm/view/companyView/types/companyPassport/companyPassportViewState.js +5 -0
- package/lib/esm/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +116 -0
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesEndpoint.js +5 -0
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewPayload.js +36 -0
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewReducer.js +222 -0
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewSelector.js +25 -0
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewState.js +4 -0
- package/lib/esm/view/settingsView/epic/fetchNotificationSettingsEpic.js +34 -2
- package/lib/esm/view/settingsView/epic/saveNotificationSettingsEpic.js +2 -1
- package/lib/esm/view/settingsView/settingsViewHelpers.js +3 -2
- package/lib/index.d.ts +8 -2
- package/lib/index.js +52 -32
- package/lib/reducer.d.ts +6 -0
- package/lib/reducer.js +6 -0
- package/lib/view/common/recurringViewHelper.d.ts +2 -2
- package/lib/view/companyView/companyViewReducer.d.ts +9 -1
- package/lib/view/companyView/companyViewReducer.js +70 -3
- package/lib/view/companyView/epic/companyPassport/dismissCapitalizationOnboardingEpic.js +2 -1
- package/lib/view/companyView/epic/companyPassport/projects/disableAccountingProjectsEpic.d.ts +10 -0
- package/lib/view/companyView/epic/companyPassport/projects/disableAccountingProjectsEpic.js +60 -0
- package/lib/view/companyView/epic/companyPassport/projects/enableAccountingProjectsEpic.d.ts +11 -0
- package/lib/view/companyView/epic/companyPassport/projects/enableAccountingProjectsEpic.js +41 -0
- package/lib/view/companyView/epic/companyPassport/projects/resumeEnableAccountingProjectsEpic.d.ts +13 -0
- package/lib/view/companyView/epic/companyPassport/projects/resumeEnableAccountingProjectsEpic.js +77 -0
- package/lib/view/companyView/epic/companyPassport/updateAccountingClassesEnabledEpic.js +2 -1
- package/lib/view/companyView/epic/companyPassport/updateCapitalizationAccountThresholdEpic.js +2 -1
- package/lib/view/companyView/types/companyPassport/companyPassportViewState.d.ts +2 -0
- package/lib/view/companyView/types/companyPassport/companyPassportViewState.js +5 -0
- package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
- package/lib/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.d.ts +40 -0
- package/lib/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +120 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesEndpoint.d.ts +2 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesEndpoint.js +9 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewPayload.d.ts +7 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewPayload.js +41 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.d.ts +30 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.js +226 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.d.ts +7 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.js +32 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewState.d.ts +14 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewState.js +8 -0
- package/lib/view/settingsView/epic/fetchNotificationSettingsEpic.d.ts +9 -1
- package/lib/view/settingsView/epic/fetchNotificationSettingsEpic.js +34 -2
- package/lib/view/settingsView/epic/saveNotificationSettingsEpic.js +2 -1
- package/lib/view/settingsView/settingsViewHelpers.d.ts +1 -1
- package/lib/view/settingsView/settingsViewHelpers.js +3 -2
- package/lib/view/settingsView/settingsViewPayload.d.ts +4 -0
- package/lib/view/settingsView/settingsViewState.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,120 @@
|
|
|
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, unmount) OR the takeUntil
|
|
99
|
+
// below (Cancel fires) → abort the still-in-flight HTTP request.
|
|
100
|
+
// No-op if the request has already completed successfully or
|
|
101
|
+
// errored. Without this, the pre-Cancel PUT would still land on
|
|
102
|
+
// the server; under patch-semantic LWW, a slower older PUT
|
|
103
|
+
// arriving after Cancel silently reverts the user's just-cleared
|
|
104
|
+
// overrides on the server.
|
|
105
|
+
controller.abort();
|
|
106
|
+
}),
|
|
107
|
+
// Cancel and tenant-switch/logout do not flow through the outer
|
|
108
|
+
// `filter`, so switchMap would never dispose this observable on
|
|
109
|
+
// either. `takeUntil` completes request$ on Cancel OR clear-all,
|
|
110
|
+
// which triggers finalize above (aborts the in-flight HTTP
|
|
111
|
+
// request). Without matching clear-all, a tenant switch during
|
|
112
|
+
// an in-flight PUT would let the older PUT land on the server
|
|
113
|
+
// under patch-semantic LWW. Cursor Bugbot 3637969823 + 3641372002.
|
|
114
|
+
(0, operators_1.takeUntil)(actions$.pipe((0, operators_1.filter)((action) => notificationPreferencesViewReducer_1.clearNotificationPreferencesLocalOverrides.match(action) ||
|
|
115
|
+
notificationPreferencesViewReducer_1.clearAllNotificationPreferencesView.match(action)))));
|
|
116
|
+
// Flip savePreferencesState to In-Progress BEFORE the network call so
|
|
117
|
+
// any "saving…" UI can render.
|
|
118
|
+
return (0, rxjs_1.concat)((0, rxjs_1.of)((0, notificationPreferencesViewReducer_1.saveNotificationPreferences)()), request$);
|
|
119
|
+
}));
|
|
120
|
+
exports.saveNotificationPreferencesEpic = saveNotificationPreferencesEpic;
|
|
@@ -0,0 +1,9 @@
|
|
|
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
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>;
|
|
@@ -0,0 +1,41 @@
|
|
|
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;
|
|
@@ -0,0 +1,30 @@
|
|
|
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;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.toggleEventChannel = exports.setGroupFrequency = exports.saveNotificationPreferencesSuccess = exports.saveNotificationPreferencesFailure = exports.saveNotificationPreferences = exports.fetchNotificationPreferencesSuccess = exports.clearNotificationPreferencesLocalOverrides = exports.clearAllNotificationPreferencesView = exports.initialState = void 0;
|
|
5
|
+
const toolkit_1 = require("@reduxjs/toolkit");
|
|
6
|
+
const notificationPreferencesViewPayload_1 = require("./notificationPreferencesViewPayload");
|
|
7
|
+
const notificationPreferencesViewState_1 = require("./notificationPreferencesViewState");
|
|
8
|
+
exports.initialState = {
|
|
9
|
+
cancelEpoch: 0,
|
|
10
|
+
localOverrides: (0, notificationPreferencesViewState_1.emptyNotificationPreferences)(),
|
|
11
|
+
preferences: (0, notificationPreferencesViewState_1.emptyNotificationPreferences)(),
|
|
12
|
+
saveEpoch: 0,
|
|
13
|
+
savePreferencesState: { fetchState: 'Not-Started' },
|
|
14
|
+
};
|
|
15
|
+
const mergePreferences = (base, patch) => {
|
|
16
|
+
const eventEnabledByChannel = {
|
|
17
|
+
...base.eventEnabledByChannel,
|
|
18
|
+
};
|
|
19
|
+
Object.entries(patch.eventEnabledByChannel).forEach(([eventId, channels]) => {
|
|
20
|
+
eventEnabledByChannel[eventId] = {
|
|
21
|
+
...(base.eventEnabledByChannel[eventId] ?? {}),
|
|
22
|
+
...channels,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
eventEnabledByChannel,
|
|
27
|
+
groupFrequencyByGroupId: {
|
|
28
|
+
...base.groupFrequencyByGroupId,
|
|
29
|
+
...patch.groupFrequencyByGroupId,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
// Remove only the (eventId, channel) and groupId keys that were actually saved
|
|
34
|
+
// to the server from `localOverrides` — AND whose current value still equals
|
|
35
|
+
// what was saved. Any new edits the user added while the PUT was in flight
|
|
36
|
+
// (either new keys not present in `saved`, OR same keys the user flipped back
|
|
37
|
+
// to a different value) are preserved so the next debounce cycle picks them up.
|
|
38
|
+
//
|
|
39
|
+
// Presence-only subtraction (the prior implementation) silently dropped a
|
|
40
|
+
// same-key re-edit that landed AFTER debounce fired but BEFORE the response
|
|
41
|
+
// returned. Concrete case:
|
|
42
|
+
// 1. toggle evt1.email = false → localOverrides = {evt1:{email:false}}
|
|
43
|
+
// 2. debounce PUT #1 fires with savedOverrides = {evt1:{email:false}}
|
|
44
|
+
// 3. user re-toggles evt1.email = true → localOverrides = {evt1:{email:true}}
|
|
45
|
+
// 4. PUT #1 success → subtract dropped `email` on presence, so the true
|
|
46
|
+
// re-edit disappeared and next-debounce found nothing to send.
|
|
47
|
+
const subtractSavedOverrides = (current, saved) => {
|
|
48
|
+
const eventEnabledByChannel = {};
|
|
49
|
+
Object.entries(current.eventEnabledByChannel).forEach(([eventId, channels]) => {
|
|
50
|
+
const savedChannels = saved.eventEnabledByChannel[eventId];
|
|
51
|
+
if (savedChannels == null) {
|
|
52
|
+
eventEnabledByChannel[eventId] = channels;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const remainingChannels = {};
|
|
56
|
+
Object.keys(channels).forEach((channel) => {
|
|
57
|
+
// Preserve the key when it's a new channel OR when the user's
|
|
58
|
+
// current value differs from what was saved (same-key re-edit).
|
|
59
|
+
if (!(channel in savedChannels) ||
|
|
60
|
+
channels[channel] !== savedChannels[channel]) {
|
|
61
|
+
remainingChannels[channel] = channels[channel];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (Object.keys(remainingChannels).length > 0) {
|
|
65
|
+
eventEnabledByChannel[eventId] = remainingChannels;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const groupFrequencyByGroupId = {};
|
|
69
|
+
Object.entries(current.groupFrequencyByGroupId).forEach(([groupId, frequency]) => {
|
|
70
|
+
if (saved.groupFrequencyByGroupId[groupId] !== frequency) {
|
|
71
|
+
groupFrequencyByGroupId[groupId] = frequency;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return { eventEnabledByChannel, groupFrequencyByGroupId };
|
|
75
|
+
};
|
|
76
|
+
const notificationPreferencesView = (0, toolkit_1.createSlice)({
|
|
77
|
+
name: 'notificationPreferencesView',
|
|
78
|
+
initialState: exports.initialState,
|
|
79
|
+
reducers: {
|
|
80
|
+
clearAllNotificationPreferencesView(draft) {
|
|
81
|
+
// Reset everything EXCEPT `cancelEpoch`, which must stay monotonic
|
|
82
|
+
// across the lifetime of the app instance. `initialState.cancelEpoch`
|
|
83
|
+
// is `0`; returning `initialState` verbatim would rewind the counter
|
|
84
|
+
// to zero, and any in-flight save whose `cancelEpochAtDispatch` was
|
|
85
|
+
// captured pre-clearAll (>0) would then satisfy the "captured >=
|
|
86
|
+
// current" epoch guard and merge stale edits into fresh preferences.
|
|
87
|
+
// Bumping instead of resetting also invalidates the abandoned save
|
|
88
|
+
// for free — Cursor Bugbot bc7876f1 followup.
|
|
89
|
+
const nextCancelEpoch = draft.cancelEpoch + 1;
|
|
90
|
+
// saveEpoch must also stay monotonic across clearAll for the same
|
|
91
|
+
// reason (Cursor Bugbot 3632510237). Rewinding to 0 would let a
|
|
92
|
+
// stale-in-flight GET whose `saveEpochAtDispatch` was captured >0
|
|
93
|
+
// satisfy the "captured >= current" epoch guard and clobber fresh
|
|
94
|
+
// preferences on any subsequent save.
|
|
95
|
+
const nextSaveEpoch = draft.saveEpoch + 1;
|
|
96
|
+
return {
|
|
97
|
+
...exports.initialState,
|
|
98
|
+
cancelEpoch: nextCancelEpoch,
|
|
99
|
+
saveEpoch: nextSaveEpoch,
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
clearNotificationPreferencesLocalOverrides(draft) {
|
|
103
|
+
// Discards in-flight per-event/per-group edits held in `localOverrides`
|
|
104
|
+
// without touching the fetched `preferences` snapshot. Used by the
|
|
105
|
+
// settings-page Cancel affordance so the effective preferences revert
|
|
106
|
+
// to the last server-known state without triggering a refetch race.
|
|
107
|
+
//
|
|
108
|
+
// Cancel/in-flight-save race: every Cancel bumps `cancelEpoch`
|
|
109
|
+
// monotonically. Any save that captured a lower epoch value at
|
|
110
|
+
// dispatch time is treated as stale by the Success/Failure reducer
|
|
111
|
+
// — its merge is skipped. Unconditional bump (vs the earlier
|
|
112
|
+
// counter model) survives switchMap abandonment and double-Cancel
|
|
113
|
+
// (Cursor Bugbot 4aa021f7): even if the abandoned save's
|
|
114
|
+
// Success/Failure never dispatches, subsequent legitimate saves
|
|
115
|
+
// still work because their captured epoch matches the current one.
|
|
116
|
+
draft.cancelEpoch += 1;
|
|
117
|
+
draft.localOverrides = (0, notificationPreferencesViewState_1.emptyNotificationPreferences)();
|
|
118
|
+
// Also drop `savePreferencesState` back to Not-Started so any
|
|
119
|
+
// "Saving…" affordance bound to `getNotificationPreferencesSaveState`
|
|
120
|
+
// clears on Cancel. Without this, a Cancel-during-save whose stale
|
|
121
|
+
// Success/Failure never fires (switchMap abandonment) leaves the
|
|
122
|
+
// selector reporting In-Progress forever — Cursor Bugbot bc7876f1.
|
|
123
|
+
draft.savePreferencesState = { fetchState: 'Not-Started' };
|
|
124
|
+
},
|
|
125
|
+
fetchNotificationPreferencesSuccess(draft, action) {
|
|
126
|
+
// Piggybacks on the settings-envelope fetch. The GET response is a full
|
|
127
|
+
// snapshot of the server-known preferences (empty maps included), so
|
|
128
|
+
// REPLACE `preferences` rather than merging — merging would leak keys
|
|
129
|
+
// the server has since removed. DO NOT touch `localOverrides`: a refetch
|
|
130
|
+
// that fires while the user has in-flight edits (pre-debounce) must not
|
|
131
|
+
// silently drop them; the save-success path is the only clearer.
|
|
132
|
+
// A `null`/`undefined` payload isn't a snapshot at all (e.g. the
|
|
133
|
+
// envelope key was omitted); no-op instead of wiping preferences.
|
|
134
|
+
if (action.payload.preferences == null) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
// Stale-GET guard (Cursor Bugbot 3632510237): if the fetch epic
|
|
138
|
+
// captured a `saveEpoch` lower than the current one, a save has
|
|
139
|
+
// succeeded since this GET dispatched — the response is carrying
|
|
140
|
+
// the pre-PUT snapshot and would clobber the just-saved server
|
|
141
|
+
// truth back to the pre-edit state until the next refetch. Skip
|
|
142
|
+
// the replace; the store already reflects the fresher save.
|
|
143
|
+
if (action.payload.saveEpochAtDispatch < draft.saveEpoch) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
draft.preferences = (0, notificationPreferencesViewPayload_1.mapPayloadToPreferences)(action.payload.preferences);
|
|
147
|
+
},
|
|
148
|
+
saveNotificationPreferences(draft) {
|
|
149
|
+
draft.savePreferencesState = { fetchState: 'In-Progress' };
|
|
150
|
+
},
|
|
151
|
+
saveNotificationPreferencesFailure(draft, action) {
|
|
152
|
+
// Stale failure from a cancelled-since save — swallow silently so
|
|
153
|
+
// the UI doesn't surface an error banner for a save the user
|
|
154
|
+
// already abandoned.
|
|
155
|
+
if (action.payload.cancelEpochAtDispatch < draft.cancelEpoch) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
// Preserve `localOverrides` so the user's in-flight edits survive a
|
|
159
|
+
// transient network blip. UI should surface an error affordance and
|
|
160
|
+
// allow retry.
|
|
161
|
+
draft.savePreferencesState = {
|
|
162
|
+
fetchState: 'Error',
|
|
163
|
+
error: action.payload.error,
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
saveNotificationPreferencesSuccess(draft, action) {
|
|
167
|
+
// Preserve-on-partial: PUT /preferences is patch-semantic. The response
|
|
168
|
+
// echoes only the fields that changed, so merge into `preferences`
|
|
169
|
+
// instead of replacing — otherwise a single-channel toggle would wipe
|
|
170
|
+
// every other stored preference.
|
|
171
|
+
//
|
|
172
|
+
// Rollback invariant (F5): `serverEcho` may be `undefined` if the server
|
|
173
|
+
// rolls back to an older shape that omits the echo entirely. In that
|
|
174
|
+
// case fall back to merging `savedOverrides` into `preferences` — the
|
|
175
|
+
// PUT succeeded (2xx), so the values we sent are now server truth. If
|
|
176
|
+
// we merged an empty patch instead, `subtractSavedOverrides` would
|
|
177
|
+
// still strip the just-saved keys from `localOverrides`, leaving the
|
|
178
|
+
// effective preferences (preferences ∪ localOverrides) reverted to the
|
|
179
|
+
// pre-edit server snapshot until the next refetch.
|
|
180
|
+
//
|
|
181
|
+
// In-flight-edit invariant: `savedOverrides` is the exact snapshot the
|
|
182
|
+
// epic PUT to the server. Subtracting those keys from `localOverrides`
|
|
183
|
+
// (instead of clearing it wholesale) preserves any edits the user
|
|
184
|
+
// added AFTER the debounce fired but BEFORE the response landed. The
|
|
185
|
+
// next debounce cycle will pick them up. Clearing wholesale drops
|
|
186
|
+
// in-flight edits from both UI (once server echo lands) and server.
|
|
187
|
+
// Cancel/in-flight-save race: `cancelEpoch` monotonically increases
|
|
188
|
+
// on every Cancel. If the save captured a lower epoch at dispatch,
|
|
189
|
+
// the user has pressed Cancel since — skip the `preferences` merge
|
|
190
|
+
// and the `localOverrides` subtract (Cancel already emptied it).
|
|
191
|
+
// Do NOT flip fetchState so a subsequent legit save can still show
|
|
192
|
+
// its own In-Progress → Completed lifecycle. The server itself has
|
|
193
|
+
// accepted the write — reverting server-side is out of FE scope; UI
|
|
194
|
+
// reflects the cancelled intention until the next refetch merges
|
|
195
|
+
// whatever the server persisted.
|
|
196
|
+
if (action.payload.cancelEpochAtDispatch < draft.cancelEpoch) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
// Bump `saveEpoch` so any settings-envelope GET that was in flight
|
|
200
|
+
// BEFORE this PUT resolved is treated as stale. Its captured epoch
|
|
201
|
+
// will be lower than the new value, so its reducer branch will
|
|
202
|
+
// skip the `preferences` replace. Cursor Bugbot 3632510237.
|
|
203
|
+
draft.saveEpoch += 1;
|
|
204
|
+
draft.savePreferencesState = { fetchState: 'Completed' };
|
|
205
|
+
const patch = action.payload.serverEcho == null
|
|
206
|
+
? action.payload.savedOverrides
|
|
207
|
+
: (0, notificationPreferencesViewPayload_1.mapPayloadToPreferences)(action.payload.serverEcho);
|
|
208
|
+
draft.preferences = mergePreferences(draft.preferences, patch);
|
|
209
|
+
draft.localOverrides = subtractSavedOverrides(draft.localOverrides, action.payload.savedOverrides);
|
|
210
|
+
},
|
|
211
|
+
setGroupFrequency(draft, action) {
|
|
212
|
+
draft.localOverrides.groupFrequencyByGroupId[action.payload.groupId] =
|
|
213
|
+
action.payload.frequency;
|
|
214
|
+
},
|
|
215
|
+
toggleEventChannel(draft, action) {
|
|
216
|
+
const { channel, enabled, eventId } = action.payload;
|
|
217
|
+
const eventMap = {
|
|
218
|
+
...(draft.localOverrides.eventEnabledByChannel[eventId] ?? {}),
|
|
219
|
+
};
|
|
220
|
+
eventMap[channel] = enabled;
|
|
221
|
+
draft.localOverrides.eventEnabledByChannel[eventId] = eventMap;
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
_a = notificationPreferencesView.actions, exports.clearAllNotificationPreferencesView = _a.clearAllNotificationPreferencesView, exports.clearNotificationPreferencesLocalOverrides = _a.clearNotificationPreferencesLocalOverrides, exports.fetchNotificationPreferencesSuccess = _a.fetchNotificationPreferencesSuccess, exports.saveNotificationPreferences = _a.saveNotificationPreferences, exports.saveNotificationPreferencesFailure = _a.saveNotificationPreferencesFailure, exports.saveNotificationPreferencesSuccess = _a.saveNotificationPreferencesSuccess, exports.setGroupFrequency = _a.setGroupFrequency, exports.toggleEventChannel = _a.toggleEventChannel;
|
|
226
|
+
exports.default = notificationPreferencesView.reducer;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FetchStateAndError } from '../../commonStateTypes/common';
|
|
2
|
+
import { RootState } from '../../reducer';
|
|
3
|
+
import { NotificationPreferences } from './notificationPreferencesViewState';
|
|
4
|
+
export declare const getNotificationPreferencesSaveState: (state: RootState) => FetchStateAndError;
|
|
5
|
+
export declare const getEffectiveNotificationPreferences: (state: RootState) => NotificationPreferences;
|
|
6
|
+
export declare const getNotificationLocalOverrides: (state: RootState) => NotificationPreferences;
|
|
7
|
+
export declare const hasUnsavedNotificationPreferences: (state: RootState) => boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasUnsavedNotificationPreferences = exports.getNotificationLocalOverrides = exports.getEffectiveNotificationPreferences = exports.getNotificationPreferencesSaveState = void 0;
|
|
4
|
+
const getView = (state) => state.notificationPreferencesViewState;
|
|
5
|
+
const getNotificationPreferencesSaveState = (state) => getView(state).savePreferencesState;
|
|
6
|
+
exports.getNotificationPreferencesSaveState = getNotificationPreferencesSaveState;
|
|
7
|
+
const getEffectiveNotificationPreferences = (state) => {
|
|
8
|
+
const view = getView(state);
|
|
9
|
+
const mergedEventEnabledByChannel = { ...view.preferences.eventEnabledByChannel };
|
|
10
|
+
Object.entries(view.localOverrides.eventEnabledByChannel).forEach(([eventId, channels]) => {
|
|
11
|
+
mergedEventEnabledByChannel[eventId] = {
|
|
12
|
+
...(view.preferences.eventEnabledByChannel[eventId] ?? {}),
|
|
13
|
+
...channels,
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
eventEnabledByChannel: mergedEventEnabledByChannel,
|
|
18
|
+
groupFrequencyByGroupId: {
|
|
19
|
+
...view.preferences.groupFrequencyByGroupId,
|
|
20
|
+
...view.localOverrides.groupFrequencyByGroupId,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.getEffectiveNotificationPreferences = getEffectiveNotificationPreferences;
|
|
25
|
+
const getNotificationLocalOverrides = (state) => getView(state).localOverrides;
|
|
26
|
+
exports.getNotificationLocalOverrides = getNotificationLocalOverrides;
|
|
27
|
+
const hasUnsavedNotificationPreferences = (state) => {
|
|
28
|
+
const overrides = getView(state).localOverrides;
|
|
29
|
+
return (Object.keys(overrides.eventEnabledByChannel).length > 0 ||
|
|
30
|
+
Object.keys(overrides.groupFrequencyByGroupId).length > 0);
|
|
31
|
+
};
|
|
32
|
+
exports.hasUnsavedNotificationPreferences = hasUnsavedNotificationPreferences;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FetchStateAndError } from '../../commonStateTypes/common';
|
|
2
|
+
import { NotificationChannel, NotificationFrequency } from '../../entity/notificationRegistry/notificationRegistryState';
|
|
3
|
+
export interface NotificationPreferences {
|
|
4
|
+
eventEnabledByChannel: Record<string, Partial<Record<NotificationChannel, boolean>>>;
|
|
5
|
+
groupFrequencyByGroupId: Record<string, NotificationFrequency>;
|
|
6
|
+
}
|
|
7
|
+
export interface NotificationPreferencesViewState {
|
|
8
|
+
cancelEpoch: number;
|
|
9
|
+
localOverrides: NotificationPreferences;
|
|
10
|
+
preferences: NotificationPreferences;
|
|
11
|
+
saveEpoch: number;
|
|
12
|
+
savePreferencesState: FetchStateAndError;
|
|
13
|
+
}
|
|
14
|
+
export declare const emptyNotificationPreferences: () => NotificationPreferences;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emptyNotificationPreferences = void 0;
|
|
4
|
+
const emptyNotificationPreferences = () => ({
|
|
5
|
+
eventEnabledByChannel: {},
|
|
6
|
+
groupFrequencyByGroupId: {},
|
|
7
|
+
});
|
|
8
|
+
exports.emptyNotificationPreferences = emptyNotificationPreferences;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
2
|
+
import { updateNotificationRegistry } from '../../../entity/notificationRegistry/notificationRegistryReducer';
|
|
2
3
|
import { RootState } from '../../../reducer';
|
|
3
4
|
import { ZeniAPI } from '../../../zeniAPI';
|
|
5
|
+
import { fetchNotificationPreferencesSuccess } from '../../notificationPreferencesView/notificationPreferencesViewReducer';
|
|
4
6
|
import { fetchNotificationSettings, updateNotificationSettingsOnFailure, updateNotificationSettingsOnSuccess } from '../settingsViewReducer';
|
|
5
|
-
export type ActionType = ReturnType<typeof fetchNotificationSettings> | ReturnType<typeof updateNotificationSettingsOnSuccess> | ReturnType<typeof updateNotificationSettingsOnFailure>;
|
|
7
|
+
export type ActionType = ReturnType<typeof fetchNotificationSettings> | ReturnType<typeof updateNotificationSettingsOnSuccess> | ReturnType<typeof updateNotificationSettingsOnFailure> | ReturnType<typeof updateNotificationRegistry> | ReturnType<typeof fetchNotificationPreferencesSuccess>;
|
|
6
8
|
export declare const fetchNotificationSettingsEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => import("rxjs").Observable<{
|
|
7
9
|
payload: undefined;
|
|
8
10
|
type: "settings/fetchNotificationSettings";
|
|
@@ -15,4 +17,10 @@ export declare const fetchNotificationSettingsEpic: (actions$: ActionsObservable
|
|
|
15
17
|
} | {
|
|
16
18
|
payload: import("../../../responsePayload").ZeniAPIStatus<Record<string, unknown>>;
|
|
17
19
|
type: "settings/updateNotificationSettingsOnFailure";
|
|
20
|
+
} | {
|
|
21
|
+
payload: import("../../../entity/notificationRegistry/notificationRegistryReducer").UpdateNotificationRegistryPayload;
|
|
22
|
+
type: "notificationRegistry/updateNotificationRegistry";
|
|
23
|
+
} | {
|
|
24
|
+
payload: import("../../notificationPreferencesView/notificationPreferencesViewReducer").FetchNotificationPreferencesSuccessPayload;
|
|
25
|
+
type: "notificationPreferencesView/fetchNotificationPreferencesSuccess";
|
|
18
26
|
}>;
|
|
@@ -3,20 +3,52 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.fetchNotificationSettingsEpic = void 0;
|
|
4
4
|
const rxjs_1 = require("rxjs");
|
|
5
5
|
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const notificationRegistryReducer_1 = require("../../../entity/notificationRegistry/notificationRegistryReducer");
|
|
6
7
|
const responsePayload_1 = require("../../../responsePayload");
|
|
8
|
+
const notificationPreferencesEndpoint_1 = require("../../notificationPreferencesView/notificationPreferencesEndpoint");
|
|
9
|
+
const notificationPreferencesViewReducer_1 = require("../../notificationPreferencesView/notificationPreferencesViewReducer");
|
|
7
10
|
const settingsViewReducer_1 = require("../settingsViewReducer");
|
|
8
11
|
const fetchNotificationSettingsEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(settingsViewReducer_1.fetchNotificationSettings.match), (0, operators_1.switchMap)(() => {
|
|
9
12
|
const state = state$.value;
|
|
10
|
-
const URL = `${zeniAPI.apiEndPoints.notificationMicroServiceBaseUrl}/1.0/notification-preferences`;
|
|
11
13
|
const userEmail = state.tenantState.loggedInUser?.userEmail;
|
|
12
14
|
if (userEmail == null) {
|
|
13
15
|
return (0, rxjs_1.from)([]);
|
|
14
16
|
}
|
|
15
|
-
|
|
17
|
+
// Snapshot the save epoch at GET-dispatch time. The reducer compares
|
|
18
|
+
// the captured value against the current `saveEpoch` on response and
|
|
19
|
+
// skips the `preferences` replace when a save has landed in the
|
|
20
|
+
// meantime — the GET is carrying the pre-PUT snapshot and would
|
|
21
|
+
// otherwise clobber the fresh save. Cursor Bugbot 3632510237.
|
|
22
|
+
const saveEpochAtDispatch = state.notificationPreferencesViewState.saveEpoch;
|
|
23
|
+
// Snapshot the registry clear epoch at GET-dispatch time (same idiom as
|
|
24
|
+
// `saveEpochAtDispatch` above). The registry reducer compares it against
|
|
25
|
+
// the current `registryEpoch` and skips its write when a
|
|
26
|
+
// `clearAllNotificationRegistry` (tenant switch) has landed since — the
|
|
27
|
+
// GET is carrying the prior tenant's snapshot. Cursor Bugbot 67d6918e.
|
|
28
|
+
const registryEpochAtDispatch = state.notificationRegistryState.registryEpoch;
|
|
29
|
+
return zeniAPI
|
|
30
|
+
.getJSON((0, notificationPreferencesEndpoint_1.notificationPreferencesUrl)(zeniAPI))
|
|
31
|
+
.pipe((0, operators_1.mergeMap)((response) => {
|
|
16
32
|
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
17
33
|
const updateActions = [
|
|
18
34
|
(0, settingsViewReducer_1.updateNotificationSettingsOnSuccess)(response.data, userEmail),
|
|
19
35
|
];
|
|
36
|
+
// Always dispatch — an absent `task_checklist_registry` (gate
|
|
37
|
+
// off) must CLEAR the prior tenant's registry, not leave it in
|
|
38
|
+
// place. The reducer clears on `undefined` and full-replaces
|
|
39
|
+
// otherwise, both guarded by the registry epoch so a stale GET
|
|
40
|
+
// that lands after a tenant switch is skipped. Cursor Bugbot
|
|
41
|
+
// 67d6918e.
|
|
42
|
+
updateActions.push((0, notificationRegistryReducer_1.updateNotificationRegistry)({
|
|
43
|
+
registry: response.data.task_checklist_registry ?? undefined,
|
|
44
|
+
registryEpochAtDispatch,
|
|
45
|
+
}));
|
|
46
|
+
if (response.data.task_checklist_preferences != null) {
|
|
47
|
+
updateActions.push((0, notificationPreferencesViewReducer_1.fetchNotificationPreferencesSuccess)({
|
|
48
|
+
preferences: response.data.task_checklist_preferences,
|
|
49
|
+
saveEpochAtDispatch,
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
20
52
|
return (0, rxjs_1.of)(...updateActions);
|
|
21
53
|
}
|
|
22
54
|
else {
|
|
@@ -5,9 +5,10 @@ const rxjs_1 = require("rxjs");
|
|
|
5
5
|
const operators_1 = require("rxjs/operators");
|
|
6
6
|
const snackbarReducer_1 = require("../../../entity/snackbar/snackbarReducer");
|
|
7
7
|
const responsePayload_1 = require("../../../responsePayload");
|
|
8
|
+
const notificationPreferencesEndpoint_1 = require("../../notificationPreferencesView/notificationPreferencesEndpoint");
|
|
8
9
|
const settingsViewReducer_1 = require("../settingsViewReducer");
|
|
9
10
|
const saveNotificationSettingsEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(settingsViewReducer_1.saveNotificationSettings.match), (0, operators_1.switchMap)(() => {
|
|
10
|
-
const URL =
|
|
11
|
+
const URL = (0, notificationPreferencesEndpoint_1.notificationPreferencesUrl)(zeniAPI);
|
|
11
12
|
const { notificationSettings, notificationSettingsLocalData } = state$.value.settingsViewState.notification;
|
|
12
13
|
const payload = toSaveNotificationSettingsPayload(notificationSettingsLocalData, notificationSettings);
|
|
13
14
|
return zeniAPI
|
|
@@ -14,4 +14,4 @@ export declare const isMyBankConnectionsTabVisible: (currentTenant: CurrentTenan
|
|
|
14
14
|
export declare const isPerformanceTabVisible: (userRole: UserRoleType[], loggedInUser?: LoggedInUser) => boolean;
|
|
15
15
|
export declare const isRemindersSectionVisibleOnSettingsPage: (reminderNotificationSettings: ReminderNotificationSettingsData) => boolean;
|
|
16
16
|
export declare const isMonthEndNotificationsSectionVisibleOnSettingsPage: (monthEndInsightsNotificationSettings: MonthEndInsightsNotificationSettingsData, signedInUseEmail: string) => boolean;
|
|
17
|
-
export declare const isNotificationsTabVisible: (notificationSettings: NotificationSettingsData, signedInUseEmail: string, isDebitCardFlagEnabled: boolean, currentTenant: CurrentTenant | undefined) => boolean;
|
|
17
|
+
export declare const isNotificationsTabVisible: (notificationSettings: NotificationSettingsData, signedInUseEmail: string, isDebitCardFlagEnabled: boolean, currentTenant: CurrentTenant | undefined, hasTaskChecklistAccess: boolean) => boolean;
|
|
@@ -160,13 +160,14 @@ const isMonthEndNotificationsSectionVisibleOnSettingsPage = (monthEndInsightsNot
|
|
|
160
160
|
monthEndInsightsNotificationSettings.recipientEmailIds.includes(signedInUseEmail));
|
|
161
161
|
};
|
|
162
162
|
exports.isMonthEndNotificationsSectionVisibleOnSettingsPage = isMonthEndNotificationsSectionVisibleOnSettingsPage;
|
|
163
|
-
const isNotificationsTabVisible = (notificationSettings, signedInUseEmail, isDebitCardFlagEnabled, currentTenant) => {
|
|
163
|
+
const isNotificationsTabVisible = (notificationSettings, signedInUseEmail, isDebitCardFlagEnabled, currentTenant, hasTaskChecklistAccess) => {
|
|
164
164
|
if (currentTenant == null) {
|
|
165
165
|
return false;
|
|
166
166
|
}
|
|
167
167
|
const { reminderNotificationSettings, monthEndInsightsNotificationSettings } = notificationSettings;
|
|
168
168
|
return (((0, exports.isRemindersSectionVisibleOnSettingsPage)(reminderNotificationSettings) ||
|
|
169
|
-
(0, exports.isMonthEndNotificationsSectionVisibleOnSettingsPage)(monthEndInsightsNotificationSettings, signedInUseEmail)
|
|
169
|
+
(0, exports.isMonthEndNotificationsSectionVisibleOnSettingsPage)(monthEndInsightsNotificationSettings, signedInUseEmail) ||
|
|
170
|
+
hasTaskChecklistAccess) &&
|
|
170
171
|
((0, tenantSelector_1.isTenantAccountingServicesEnabled)(currentTenant) ||
|
|
171
172
|
((0, tenantSelector_1.isTenantBankingOnly)(isDebitCardFlagEnabled, currentTenant) === false &&
|
|
172
173
|
(0, tenantSelector_1.isTenantCardsOnly)(currentTenant) === false)));
|