@zeniai/client-epic-state 5.1.54-betaDI0 → 5.1.54-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.
- package/lib/coreEpics.js +2 -3
- package/lib/entity/chargeCard/chargeCard.d.ts +1 -1
- package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +2 -0
- package/lib/entity/jeSchedules/jeSchedulesPayload.js +2 -0
- package/lib/entity/jeSchedules/jeSchedulesSelector.d.ts +4 -0
- package/lib/entity/jeSchedules/jeSchedulesSelector.js +11 -1
- package/lib/entity/jeSchedules/jeSchedulesState.d.ts +2 -0
- package/lib/entity/tenant/clearAllEpic.d.ts +1 -3
- package/lib/entity/tenant/clearAllEpic.js +0 -4
- package/lib/epic.d.ts +2 -2
- package/lib/epic.js +2 -2
- package/lib/esm/coreEpics.js +2 -3
- package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +2 -0
- package/lib/esm/entity/jeSchedules/jeSchedulesSelector.js +11 -1
- package/lib/esm/entity/tenant/clearAllEpic.js +0 -4
- package/lib/esm/epic.js +2 -2
- package/lib/esm/index.js +3 -8
- package/lib/esm/reducer.js +0 -6
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +15 -2
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +22 -0
- package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +20 -6
- package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +58 -10
- package/lib/esm/view/expenseAutomationView/types/jeSchedulesViewState.js +2 -6
- package/lib/esm/view/settingsView/epic/fetchNotificationSettingsEpic.js +2 -12
- package/lib/esm/view/settingsView/settingsViewHelpers.js +2 -3
- package/lib/index.d.ts +5 -11
- package/lib/index.js +44 -53
- package/lib/reducer.d.ts +0 -6
- package/lib/reducer.js +0 -6
- package/lib/view/common/recurringViewHelper.d.ts +2 -2
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +14 -1
- package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.d.ts +6 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +26 -0
- package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +1 -0
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +2 -2
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +21 -7
- package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +27 -4
- package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +58 -10
- package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +6 -3
- package/lib/view/expenseAutomationView/types/jeSchedulesViewState.js +4 -8
- package/lib/view/settingsView/epic/fetchNotificationSettingsEpic.d.ts +1 -9
- package/lib/view/settingsView/epic/fetchNotificationSettingsEpic.js +2 -12
- package/lib/view/settingsView/settingsViewHelpers.d.ts +1 -1
- package/lib/view/settingsView/settingsViewHelpers.js +2 -3
- package/lib/view/settingsView/settingsViewPayload.d.ts +0 -4
- package/lib/view/settingsView/settingsViewState.d.ts +1 -1
- package/package.json +1 -1
- package/lib/entity/notificationRegistry/notificationRegistryPayload.d.ts +0 -18
- package/lib/entity/notificationRegistry/notificationRegistryPayload.js +0 -28
- package/lib/entity/notificationRegistry/notificationRegistryReducer.d.ts +0 -6
- package/lib/entity/notificationRegistry/notificationRegistryReducer.js +0 -26
- package/lib/entity/notificationRegistry/notificationRegistrySelector.d.ts +0 -2
- package/lib/entity/notificationRegistry/notificationRegistrySelector.js +0 -10
- package/lib/entity/notificationRegistry/notificationRegistryState.d.ts +0 -31
- package/lib/entity/notificationRegistry/notificationRegistryState.js +0 -10
- package/lib/esm/entity/notificationRegistry/notificationRegistryPayload.js +0 -24
- package/lib/esm/entity/notificationRegistry/notificationRegistryReducer.js +0 -22
- package/lib/esm/entity/notificationRegistry/notificationRegistrySelector.js +0 -6
- package/lib/esm/entity/notificationRegistry/notificationRegistryState.js +0 -5
- package/lib/esm/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +0 -58
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesEndpoint.js +0 -5
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewPayload.js +0 -36
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewReducer.js +0 -124
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewSelector.js +0 -25
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewState.js +0 -4
- package/lib/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.d.ts +0 -30
- package/lib/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +0 -62
- package/lib/view/notificationPreferencesView/notificationPreferencesEndpoint.d.ts +0 -2
- package/lib/view/notificationPreferencesView/notificationPreferencesEndpoint.js +0 -9
- package/lib/view/notificationPreferencesView/notificationPreferencesViewPayload.d.ts +0 -7
- package/lib/view/notificationPreferencesView/notificationPreferencesViewPayload.js +0 -41
- package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.d.ts +0 -23
- package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.js +0 -128
- package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.d.ts +0 -7
- package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.js +0 -32
- package/lib/view/notificationPreferencesView/notificationPreferencesViewState.d.ts +0 -12
- package/lib/view/notificationPreferencesView/notificationPreferencesViewState.js +0 -8
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { toNotificationChannel, toNotificationFrequency, } from './notificationRegistryState';
|
|
2
|
-
const mapDefaultEnabled = (raw) => {
|
|
3
|
-
const out = {};
|
|
4
|
-
Object.entries(raw).forEach(([channel, enabled]) => {
|
|
5
|
-
out[toNotificationChannel(channel)] = enabled;
|
|
6
|
-
});
|
|
7
|
-
return out;
|
|
8
|
-
};
|
|
9
|
-
const mapEvent = (payload) => ({
|
|
10
|
-
channels: payload.channels.map(toNotificationChannel),
|
|
11
|
-
defaultEnabled: mapDefaultEnabled(payload.default_enabled),
|
|
12
|
-
displayName: payload.display_name,
|
|
13
|
-
eventId: payload.event_id,
|
|
14
|
-
suppressible: payload.suppressible,
|
|
15
|
-
});
|
|
16
|
-
const mapGroup = (payload) => ({
|
|
17
|
-
displayName: payload.display_name,
|
|
18
|
-
events: payload.events.map(mapEvent),
|
|
19
|
-
groupId: payload.group_id,
|
|
20
|
-
});
|
|
21
|
-
export const mapNotificationRegistryPayloadToRegistry = (payload) => ({
|
|
22
|
-
frequencyOptions: payload.frequency_options.map(toNotificationFrequency),
|
|
23
|
-
groups: payload.groups.map(mapGroup),
|
|
24
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { createSlice } from '@reduxjs/toolkit';
|
|
2
|
-
import { mapNotificationRegistryPayloadToRegistry, } from './notificationRegistryPayload';
|
|
3
|
-
export const initialState = {};
|
|
4
|
-
const notificationRegistry = createSlice({
|
|
5
|
-
name: 'notificationRegistry',
|
|
6
|
-
initialState,
|
|
7
|
-
reducers: {
|
|
8
|
-
clearAllNotificationRegistry() {
|
|
9
|
-
return initialState;
|
|
10
|
-
},
|
|
11
|
-
updateNotificationRegistry(draft, action) {
|
|
12
|
-
// Full-replace contract: the registry payload is atomic — every fetch
|
|
13
|
-
// returns the complete group/event tree. If the backend ever ships a
|
|
14
|
-
// partial registry response, this write MUST switch to a merge (mirror
|
|
15
|
-
// the preferences slice's `mergePreferences`). Do not assume the
|
|
16
|
-
// current payload is partial without also updating this reducer.
|
|
17
|
-
draft.registry = mapNotificationRegistryPayloadToRegistry(action.payload);
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
export const { clearAllNotificationRegistry, updateNotificationRegistry } = notificationRegistry.actions;
|
|
22
|
-
export default notificationRegistry.reducer;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// Current behavior: a null / undefined registry means the whole notification
|
|
2
|
-
// section is hidden by consumers. This conflates two distinct states —
|
|
3
|
-
// "user has no saved preferences yet" vs "the Task Checklist feature gate is
|
|
4
|
-
// off for this tenant". Both currently surface as `undefined`. Distinguishing
|
|
5
|
-
// them (e.g. an explicit `gate_off` signal from the server) is a follow-up.
|
|
6
|
-
export const getNotificationRegistry = (slice) => slice.registry;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { stringToUnion } from '../../commonStateTypes/stringToUnion';
|
|
2
|
-
export const NOTIFICATION_CHANNELS = ['email', 'slack', 'in_app'];
|
|
3
|
-
export const toNotificationChannel = (raw) => stringToUnion(raw, NOTIFICATION_CHANNELS);
|
|
4
|
-
export const NOTIFICATION_FREQUENCIES = ['instant', 'daily'];
|
|
5
|
-
export const toNotificationFrequency = (raw) => stringToUnion(raw, NOTIFICATION_FREQUENCIES);
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { EMPTY, concat, of } from 'rxjs';
|
|
2
|
-
import { catchError, debounceTime, filter, mergeMap, switchMap, withLatestFrom, } from 'rxjs/operators';
|
|
3
|
-
import { openSnackbar } from '../../../entity/snackbar/snackbarReducer';
|
|
4
|
-
import { createZeniAPIStatus, isSuccessResponse, } from '../../../responsePayload';
|
|
5
|
-
import { notificationPreferencesUrl } from '../notificationPreferencesEndpoint';
|
|
6
|
-
import { mapPreferencesToPayload, } from '../notificationPreferencesViewPayload';
|
|
7
|
-
import { saveNotificationPreferences, saveNotificationPreferencesFailure, saveNotificationPreferencesSuccess, setGroupFrequency, toggleEventChannel, } from '../notificationPreferencesViewReducer';
|
|
8
|
-
import { getNotificationLocalOverrides } from '../notificationPreferencesViewSelector';
|
|
9
|
-
const DEBOUNCE_MS = 300;
|
|
10
|
-
export const saveNotificationPreferencesEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter((action) => toggleEventChannel.match(action) || setGroupFrequency.match(action)),
|
|
11
|
-
// Coalesce bursts of toggles into a single PUT. Trade-off: rapid clickers
|
|
12
|
-
// defer saves until they pause. Consider a max-wait wrapper if this
|
|
13
|
-
// becomes a UX problem.
|
|
14
|
-
debounceTime(DEBOUNCE_MS), withLatestFrom(state$),
|
|
15
|
-
// `switchMap` unsubscribes from any in-flight PUT observable when a new
|
|
16
|
-
// debounced batch fires. The prior HTTP request has already left the
|
|
17
|
-
// client — the network call is NOT cancelled — but its response is
|
|
18
|
-
// ignored, so stale success/failure actions cannot clobber the newer
|
|
19
|
-
// batch's state. Server-side ordering is arrival-order LWW.
|
|
20
|
-
switchMap(([, state]) => {
|
|
21
|
-
const overrides = getNotificationLocalOverrides(state);
|
|
22
|
-
const preferencesPatch = mapPreferencesToPayload(overrides);
|
|
23
|
-
if (Object.keys(preferencesPatch).length === 0) {
|
|
24
|
-
// No diff → do not dispatch a synthetic success (that would wipe
|
|
25
|
-
// stored preferences via the reducer). Simply no-op.
|
|
26
|
-
return EMPTY;
|
|
27
|
-
}
|
|
28
|
-
const body = { task_checklist_preferences: preferencesPatch };
|
|
29
|
-
const request$ = zeniAPI
|
|
30
|
-
.putAndGetJSON(notificationPreferencesUrl(zeniAPI), body)
|
|
31
|
-
.pipe(mergeMap((response) => {
|
|
32
|
-
if (isSuccessResponse(response)) {
|
|
33
|
-
return of(saveNotificationPreferencesSuccess({
|
|
34
|
-
savedOverrides: overrides,
|
|
35
|
-
serverEcho: response.data?.task_checklist_preferences,
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
return of(saveNotificationPreferencesFailure({ error: response.status }),
|
|
39
|
-
// Surface a user-visible error — without it the UI reverts to
|
|
40
|
-
// server truth after debounce and the failed toggle looks like
|
|
41
|
-
// a mystery UI bug.
|
|
42
|
-
openSnackbar({
|
|
43
|
-
messageSection: 'notification_settings_saved',
|
|
44
|
-
messageText: 'failed',
|
|
45
|
-
type: 'error',
|
|
46
|
-
}));
|
|
47
|
-
}), catchError((error) => of(saveNotificationPreferencesFailure({
|
|
48
|
-
error: createZeniAPIStatus('Unexpected Error', 'Save notification preferences failed: ' +
|
|
49
|
-
JSON.stringify(error)),
|
|
50
|
-
}), openSnackbar({
|
|
51
|
-
messageSection: 'notification_settings_saved',
|
|
52
|
-
messageText: 'failed',
|
|
53
|
-
type: 'error',
|
|
54
|
-
}))));
|
|
55
|
-
// Flip savePreferencesState to In-Progress BEFORE the network call so
|
|
56
|
-
// any "saving…" UI can render.
|
|
57
|
-
return concat(of(saveNotificationPreferences()), request$);
|
|
58
|
-
}));
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// Shared endpoint used by both the GET (envelope refresh in
|
|
2
|
-
// `fetchNotificationSettingsEpic`) and the PUT (patch in
|
|
3
|
-
// `saveNotificationPreferencesEpic`). Kept as a helper so an endpoint rename
|
|
4
|
-
// can't drift between the two callers.
|
|
5
|
-
export const notificationPreferencesUrl = (zeniAPI) => `${zeniAPI.apiEndPoints.notificationMicroServiceBaseUrl}/1.0/notification-preferences`;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { toNotificationChannel, toNotificationFrequency, } from '../../entity/notificationRegistry/notificationRegistryState';
|
|
2
|
-
const mapEventEnabledByChannel = (raw) => {
|
|
3
|
-
if (raw == null) {
|
|
4
|
-
return {};
|
|
5
|
-
}
|
|
6
|
-
const out = {};
|
|
7
|
-
Object.entries(raw).forEach(([eventId, channelMap]) => {
|
|
8
|
-
const mapped = {};
|
|
9
|
-
Object.entries(channelMap).forEach(([channel, enabled]) => {
|
|
10
|
-
mapped[toNotificationChannel(channel)] = enabled;
|
|
11
|
-
});
|
|
12
|
-
out[eventId] = mapped;
|
|
13
|
-
});
|
|
14
|
-
return out;
|
|
15
|
-
};
|
|
16
|
-
export const mapPayloadToPreferences = (payload) => {
|
|
17
|
-
const groupFrequencyRaw = payload?.group_frequency_by_group_id ?? {};
|
|
18
|
-
const groupFrequencyByGroupId = Object.fromEntries(Object.entries(groupFrequencyRaw).map(([groupId, frequency]) => [
|
|
19
|
-
groupId,
|
|
20
|
-
toNotificationFrequency(frequency),
|
|
21
|
-
]));
|
|
22
|
-
return {
|
|
23
|
-
eventEnabledByChannel: mapEventEnabledByChannel(payload?.event_enabled_by_channel),
|
|
24
|
-
groupFrequencyByGroupId,
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
export const mapPreferencesToPayload = (preferences) => {
|
|
28
|
-
const payload = {};
|
|
29
|
-
if (Object.keys(preferences.eventEnabledByChannel).length > 0) {
|
|
30
|
-
payload.event_enabled_by_channel = preferences.eventEnabledByChannel;
|
|
31
|
-
}
|
|
32
|
-
if (Object.keys(preferences.groupFrequencyByGroupId).length > 0) {
|
|
33
|
-
payload.group_frequency_by_group_id = preferences.groupFrequencyByGroupId;
|
|
34
|
-
}
|
|
35
|
-
return payload;
|
|
36
|
-
};
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { createSlice } from '@reduxjs/toolkit';
|
|
2
|
-
import { mapPayloadToPreferences, } from './notificationPreferencesViewPayload';
|
|
3
|
-
import { emptyNotificationPreferences, } from './notificationPreferencesViewState';
|
|
4
|
-
export const initialState = {
|
|
5
|
-
localOverrides: emptyNotificationPreferences(),
|
|
6
|
-
preferences: emptyNotificationPreferences(),
|
|
7
|
-
savePreferencesState: { fetchState: 'Not-Started' },
|
|
8
|
-
};
|
|
9
|
-
const mergePreferences = (base, patch) => {
|
|
10
|
-
const eventEnabledByChannel = {
|
|
11
|
-
...base.eventEnabledByChannel,
|
|
12
|
-
};
|
|
13
|
-
Object.entries(patch.eventEnabledByChannel).forEach(([eventId, channels]) => {
|
|
14
|
-
eventEnabledByChannel[eventId] = {
|
|
15
|
-
...(base.eventEnabledByChannel[eventId] ?? {}),
|
|
16
|
-
...channels,
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
return {
|
|
20
|
-
eventEnabledByChannel,
|
|
21
|
-
groupFrequencyByGroupId: {
|
|
22
|
-
...base.groupFrequencyByGroupId,
|
|
23
|
-
...patch.groupFrequencyByGroupId,
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
// Remove only the (eventId, channel) and groupId keys that were actually saved
|
|
28
|
-
// to the server from `localOverrides`. Any new edits the user added while the
|
|
29
|
-
// PUT was in flight (i.e. keys in `current` not present in `saved`) are
|
|
30
|
-
// preserved so the next debounce cycle picks them up.
|
|
31
|
-
const subtractSavedOverrides = (current, saved) => {
|
|
32
|
-
const eventEnabledByChannel = {};
|
|
33
|
-
Object.entries(current.eventEnabledByChannel).forEach(([eventId, channels]) => {
|
|
34
|
-
const savedChannels = saved.eventEnabledByChannel[eventId];
|
|
35
|
-
if (savedChannels == null) {
|
|
36
|
-
eventEnabledByChannel[eventId] = channels;
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const remainingChannels = {};
|
|
40
|
-
Object.keys(channels).forEach((channel) => {
|
|
41
|
-
if (!(channel in savedChannels)) {
|
|
42
|
-
remainingChannels[channel] = channels[channel];
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
if (Object.keys(remainingChannels).length > 0) {
|
|
46
|
-
eventEnabledByChannel[eventId] = remainingChannels;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
const groupFrequencyByGroupId = {};
|
|
50
|
-
Object.entries(current.groupFrequencyByGroupId).forEach(([groupId, frequency]) => {
|
|
51
|
-
if (!(groupId in saved.groupFrequencyByGroupId)) {
|
|
52
|
-
groupFrequencyByGroupId[groupId] = frequency;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
return { eventEnabledByChannel, groupFrequencyByGroupId };
|
|
56
|
-
};
|
|
57
|
-
const notificationPreferencesView = createSlice({
|
|
58
|
-
name: 'notificationPreferencesView',
|
|
59
|
-
initialState,
|
|
60
|
-
reducers: {
|
|
61
|
-
clearAllNotificationPreferencesView() {
|
|
62
|
-
return initialState;
|
|
63
|
-
},
|
|
64
|
-
fetchNotificationPreferencesSuccess(draft, action) {
|
|
65
|
-
// Piggybacks on the settings-envelope fetch. Merge server data into
|
|
66
|
-
// `preferences` and DO NOT touch `localOverrides` — a refetch that fires
|
|
67
|
-
// while the user has in-flight edits (pre-debounce) must not silently
|
|
68
|
-
// drop them. `localOverrides` is cleared only by the save-success path
|
|
69
|
-
// once the edits are persisted.
|
|
70
|
-
const patch = mapPayloadToPreferences(action.payload);
|
|
71
|
-
draft.preferences = mergePreferences(draft.preferences, patch);
|
|
72
|
-
},
|
|
73
|
-
saveNotificationPreferences(draft) {
|
|
74
|
-
draft.savePreferencesState = { fetchState: 'In-Progress' };
|
|
75
|
-
},
|
|
76
|
-
saveNotificationPreferencesFailure(draft, action) {
|
|
77
|
-
// Preserve `localOverrides` so the user's in-flight edits survive a
|
|
78
|
-
// transient network blip. UI should surface an error affordance and
|
|
79
|
-
// allow retry.
|
|
80
|
-
draft.savePreferencesState = {
|
|
81
|
-
fetchState: 'Error',
|
|
82
|
-
error: action.payload.error,
|
|
83
|
-
};
|
|
84
|
-
},
|
|
85
|
-
saveNotificationPreferencesSuccess(draft, action) {
|
|
86
|
-
// Preserve-on-partial: PUT /preferences is patch-semantic. The response
|
|
87
|
-
// echoes only the fields that changed, so merge into `preferences`
|
|
88
|
-
// instead of replacing — otherwise a single-channel toggle would wipe
|
|
89
|
-
// every other stored preference.
|
|
90
|
-
//
|
|
91
|
-
// Rollback invariant (F5): `serverEcho` may be `undefined` if the server
|
|
92
|
-
// rolls back to an older shape that omits the echo entirely.
|
|
93
|
-
// `mapPayloadToPreferences(undefined)` intentionally returns an empty
|
|
94
|
-
// patch, so `mergePreferences` becomes a no-op — the user's stored
|
|
95
|
-
// preferences remain intact and no error is surfaced. Do NOT change
|
|
96
|
-
// this to throw or reset on nullish payload.
|
|
97
|
-
//
|
|
98
|
-
// In-flight-edit invariant: `savedOverrides` is the exact snapshot the
|
|
99
|
-
// epic PUT to the server. Subtracting those keys from `localOverrides`
|
|
100
|
-
// (instead of clearing it wholesale) preserves any edits the user
|
|
101
|
-
// added AFTER the debounce fired but BEFORE the response landed. The
|
|
102
|
-
// next debounce cycle will pick them up. Clearing wholesale drops
|
|
103
|
-
// in-flight edits from both UI (once server echo lands) and server.
|
|
104
|
-
const patch = mapPayloadToPreferences(action.payload.serverEcho);
|
|
105
|
-
draft.savePreferencesState = { fetchState: 'Completed' };
|
|
106
|
-
draft.preferences = mergePreferences(draft.preferences, patch);
|
|
107
|
-
draft.localOverrides = subtractSavedOverrides(draft.localOverrides, action.payload.savedOverrides);
|
|
108
|
-
},
|
|
109
|
-
setGroupFrequency(draft, action) {
|
|
110
|
-
draft.localOverrides.groupFrequencyByGroupId[action.payload.groupId] =
|
|
111
|
-
action.payload.frequency;
|
|
112
|
-
},
|
|
113
|
-
toggleEventChannel(draft, action) {
|
|
114
|
-
const { channel, enabled, eventId } = action.payload;
|
|
115
|
-
const eventMap = {
|
|
116
|
-
...(draft.localOverrides.eventEnabledByChannel[eventId] ?? {}),
|
|
117
|
-
};
|
|
118
|
-
eventMap[channel] = enabled;
|
|
119
|
-
draft.localOverrides.eventEnabledByChannel[eventId] = eventMap;
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
export const { clearAllNotificationPreferencesView, fetchNotificationPreferencesSuccess, saveNotificationPreferences, saveNotificationPreferencesFailure, saveNotificationPreferencesSuccess, setGroupFrequency, toggleEventChannel, } = notificationPreferencesView.actions;
|
|
124
|
-
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,30 +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: {
|
|
24
|
-
error?: import("../../../responsePayload").ZeniAPIStatus;
|
|
25
|
-
};
|
|
26
|
-
type: "notificationPreferencesView/saveNotificationPreferencesFailure";
|
|
27
|
-
} | {
|
|
28
|
-
payload: import("../notificationPreferencesViewReducer").SaveNotificationPreferencesSuccessPayload;
|
|
29
|
-
type: "notificationPreferencesView/saveNotificationPreferencesSuccess";
|
|
30
|
-
}>;
|
|
@@ -1,62 +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
|
-
const body = { task_checklist_preferences: preferencesPatch };
|
|
32
|
-
const request$ = zeniAPI
|
|
33
|
-
.putAndGetJSON((0, notificationPreferencesEndpoint_1.notificationPreferencesUrl)(zeniAPI), body)
|
|
34
|
-
.pipe((0, operators_1.mergeMap)((response) => {
|
|
35
|
-
if ((0, responsePayload_1.isSuccessResponse)(response)) {
|
|
36
|
-
return (0, rxjs_1.of)((0, notificationPreferencesViewReducer_1.saveNotificationPreferencesSuccess)({
|
|
37
|
-
savedOverrides: overrides,
|
|
38
|
-
serverEcho: response.data?.task_checklist_preferences,
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
41
|
-
return (0, rxjs_1.of)((0, notificationPreferencesViewReducer_1.saveNotificationPreferencesFailure)({ error: response.status }),
|
|
42
|
-
// Surface a user-visible error — without it the UI reverts to
|
|
43
|
-
// server truth after debounce and the failed toggle looks like
|
|
44
|
-
// a mystery UI bug.
|
|
45
|
-
(0, snackbarReducer_1.openSnackbar)({
|
|
46
|
-
messageSection: 'notification_settings_saved',
|
|
47
|
-
messageText: 'failed',
|
|
48
|
-
type: 'error',
|
|
49
|
-
}));
|
|
50
|
-
}), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, notificationPreferencesViewReducer_1.saveNotificationPreferencesFailure)({
|
|
51
|
-
error: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Save notification preferences failed: ' +
|
|
52
|
-
JSON.stringify(error)),
|
|
53
|
-
}), (0, snackbarReducer_1.openSnackbar)({
|
|
54
|
-
messageSection: 'notification_settings_saved',
|
|
55
|
-
messageText: 'failed',
|
|
56
|
-
type: 'error',
|
|
57
|
-
}))));
|
|
58
|
-
// Flip savePreferencesState to In-Progress BEFORE the network call so
|
|
59
|
-
// any "saving…" UI can render.
|
|
60
|
-
return (0, rxjs_1.concat)((0, rxjs_1.of)((0, notificationPreferencesViewReducer_1.saveNotificationPreferences)()), request$);
|
|
61
|
-
}));
|
|
62
|
-
exports.saveNotificationPreferencesEpic = saveNotificationPreferencesEpic;
|
|
@@ -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,23 +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 SaveNotificationPreferencesSuccessPayload {
|
|
16
|
-
savedOverrides: NotificationPreferences;
|
|
17
|
-
serverEcho: NotificationPreferencesPayload | undefined;
|
|
18
|
-
}
|
|
19
|
-
export declare const clearAllNotificationPreferencesView: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"notificationPreferencesView/clearAllNotificationPreferencesView">, fetchNotificationPreferencesSuccess: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<NotificationPreferencesPayload | undefined, "notificationPreferencesView/fetchNotificationPreferencesSuccess">, saveNotificationPreferences: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"notificationPreferencesView/saveNotificationPreferences">, saveNotificationPreferencesFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
20
|
-
error?: ZeniAPIStatus;
|
|
21
|
-
}, "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">;
|
|
22
|
-
declare const _default: import("redux").Reducer<NotificationPreferencesViewState>;
|
|
23
|
-
export default _default;
|
|
@@ -1,128 +0,0 @@
|
|
|
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.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
|
-
localOverrides: (0, notificationPreferencesViewState_1.emptyNotificationPreferences)(),
|
|
10
|
-
preferences: (0, notificationPreferencesViewState_1.emptyNotificationPreferences)(),
|
|
11
|
-
savePreferencesState: { fetchState: 'Not-Started' },
|
|
12
|
-
};
|
|
13
|
-
const mergePreferences = (base, patch) => {
|
|
14
|
-
const eventEnabledByChannel = {
|
|
15
|
-
...base.eventEnabledByChannel,
|
|
16
|
-
};
|
|
17
|
-
Object.entries(patch.eventEnabledByChannel).forEach(([eventId, channels]) => {
|
|
18
|
-
eventEnabledByChannel[eventId] = {
|
|
19
|
-
...(base.eventEnabledByChannel[eventId] ?? {}),
|
|
20
|
-
...channels,
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
return {
|
|
24
|
-
eventEnabledByChannel,
|
|
25
|
-
groupFrequencyByGroupId: {
|
|
26
|
-
...base.groupFrequencyByGroupId,
|
|
27
|
-
...patch.groupFrequencyByGroupId,
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
// Remove only the (eventId, channel) and groupId keys that were actually saved
|
|
32
|
-
// to the server from `localOverrides`. Any new edits the user added while the
|
|
33
|
-
// PUT was in flight (i.e. keys in `current` not present in `saved`) are
|
|
34
|
-
// preserved so the next debounce cycle picks them up.
|
|
35
|
-
const subtractSavedOverrides = (current, saved) => {
|
|
36
|
-
const eventEnabledByChannel = {};
|
|
37
|
-
Object.entries(current.eventEnabledByChannel).forEach(([eventId, channels]) => {
|
|
38
|
-
const savedChannels = saved.eventEnabledByChannel[eventId];
|
|
39
|
-
if (savedChannels == null) {
|
|
40
|
-
eventEnabledByChannel[eventId] = channels;
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const remainingChannels = {};
|
|
44
|
-
Object.keys(channels).forEach((channel) => {
|
|
45
|
-
if (!(channel in savedChannels)) {
|
|
46
|
-
remainingChannels[channel] = channels[channel];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
if (Object.keys(remainingChannels).length > 0) {
|
|
50
|
-
eventEnabledByChannel[eventId] = remainingChannels;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const groupFrequencyByGroupId = {};
|
|
54
|
-
Object.entries(current.groupFrequencyByGroupId).forEach(([groupId, frequency]) => {
|
|
55
|
-
if (!(groupId in saved.groupFrequencyByGroupId)) {
|
|
56
|
-
groupFrequencyByGroupId[groupId] = frequency;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return { eventEnabledByChannel, groupFrequencyByGroupId };
|
|
60
|
-
};
|
|
61
|
-
const notificationPreferencesView = (0, toolkit_1.createSlice)({
|
|
62
|
-
name: 'notificationPreferencesView',
|
|
63
|
-
initialState: exports.initialState,
|
|
64
|
-
reducers: {
|
|
65
|
-
clearAllNotificationPreferencesView() {
|
|
66
|
-
return exports.initialState;
|
|
67
|
-
},
|
|
68
|
-
fetchNotificationPreferencesSuccess(draft, action) {
|
|
69
|
-
// Piggybacks on the settings-envelope fetch. Merge server data into
|
|
70
|
-
// `preferences` and DO NOT touch `localOverrides` — a refetch that fires
|
|
71
|
-
// while the user has in-flight edits (pre-debounce) must not silently
|
|
72
|
-
// drop them. `localOverrides` is cleared only by the save-success path
|
|
73
|
-
// once the edits are persisted.
|
|
74
|
-
const patch = (0, notificationPreferencesViewPayload_1.mapPayloadToPreferences)(action.payload);
|
|
75
|
-
draft.preferences = mergePreferences(draft.preferences, patch);
|
|
76
|
-
},
|
|
77
|
-
saveNotificationPreferences(draft) {
|
|
78
|
-
draft.savePreferencesState = { fetchState: 'In-Progress' };
|
|
79
|
-
},
|
|
80
|
-
saveNotificationPreferencesFailure(draft, action) {
|
|
81
|
-
// Preserve `localOverrides` so the user's in-flight edits survive a
|
|
82
|
-
// transient network blip. UI should surface an error affordance and
|
|
83
|
-
// allow retry.
|
|
84
|
-
draft.savePreferencesState = {
|
|
85
|
-
fetchState: 'Error',
|
|
86
|
-
error: action.payload.error,
|
|
87
|
-
};
|
|
88
|
-
},
|
|
89
|
-
saveNotificationPreferencesSuccess(draft, action) {
|
|
90
|
-
// Preserve-on-partial: PUT /preferences is patch-semantic. The response
|
|
91
|
-
// echoes only the fields that changed, so merge into `preferences`
|
|
92
|
-
// instead of replacing — otherwise a single-channel toggle would wipe
|
|
93
|
-
// every other stored preference.
|
|
94
|
-
//
|
|
95
|
-
// Rollback invariant (F5): `serverEcho` may be `undefined` if the server
|
|
96
|
-
// rolls back to an older shape that omits the echo entirely.
|
|
97
|
-
// `mapPayloadToPreferences(undefined)` intentionally returns an empty
|
|
98
|
-
// patch, so `mergePreferences` becomes a no-op — the user's stored
|
|
99
|
-
// preferences remain intact and no error is surfaced. Do NOT change
|
|
100
|
-
// this to throw or reset on nullish payload.
|
|
101
|
-
//
|
|
102
|
-
// In-flight-edit invariant: `savedOverrides` is the exact snapshot the
|
|
103
|
-
// epic PUT to the server. Subtracting those keys from `localOverrides`
|
|
104
|
-
// (instead of clearing it wholesale) preserves any edits the user
|
|
105
|
-
// added AFTER the debounce fired but BEFORE the response landed. The
|
|
106
|
-
// next debounce cycle will pick them up. Clearing wholesale drops
|
|
107
|
-
// in-flight edits from both UI (once server echo lands) and server.
|
|
108
|
-
const patch = (0, notificationPreferencesViewPayload_1.mapPayloadToPreferences)(action.payload.serverEcho);
|
|
109
|
-
draft.savePreferencesState = { fetchState: 'Completed' };
|
|
110
|
-
draft.preferences = mergePreferences(draft.preferences, patch);
|
|
111
|
-
draft.localOverrides = subtractSavedOverrides(draft.localOverrides, action.payload.savedOverrides);
|
|
112
|
-
},
|
|
113
|
-
setGroupFrequency(draft, action) {
|
|
114
|
-
draft.localOverrides.groupFrequencyByGroupId[action.payload.groupId] =
|
|
115
|
-
action.payload.frequency;
|
|
116
|
-
},
|
|
117
|
-
toggleEventChannel(draft, action) {
|
|
118
|
-
const { channel, enabled, eventId } = action.payload;
|
|
119
|
-
const eventMap = {
|
|
120
|
-
...(draft.localOverrides.eventEnabledByChannel[eventId] ?? {}),
|
|
121
|
-
};
|
|
122
|
-
eventMap[channel] = enabled;
|
|
123
|
-
draft.localOverrides.eventEnabledByChannel[eventId] = eventMap;
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
_a = notificationPreferencesView.actions, exports.clearAllNotificationPreferencesView = _a.clearAllNotificationPreferencesView, exports.fetchNotificationPreferencesSuccess = _a.fetchNotificationPreferencesSuccess, exports.saveNotificationPreferences = _a.saveNotificationPreferences, exports.saveNotificationPreferencesFailure = _a.saveNotificationPreferencesFailure, exports.saveNotificationPreferencesSuccess = _a.saveNotificationPreferencesSuccess, exports.setGroupFrequency = _a.setGroupFrequency, exports.toggleEventChannel = _a.toggleEventChannel;
|
|
128
|
-
exports.default = notificationPreferencesView.reducer;
|
|
@@ -1,7 +0,0 @@
|
|
|
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;
|