/notification-preferences, opened from the profile tab. The code is src/features/notification-preferences.
Endpoint
Both calls use/v1/trainee/notification-preferences.
PATCH changes one group.
Groups
NotificationPreferenceGroup has six values. The screen maps each to an icon and two strings in GROUP_COPY.
The screen filters the server list to keys it has copy for:
GROUP_COPY, and to all six locale files.
The order on screen is the order the server returns.
Locked groups
A group withlocked: true renders a disabled switch. The app does not decide which groups are locked. It only honours the flag.
Saving
useSaveNotificationPreference() is an optimistic mutation.
onMutatecancels in-flight fetches for['notification-preferences']and flips the group in the cache, so the switch moves at once.- The mutation has a fixed
scopeid, so several quick toggles are sent one after another, in order. onSettledchecksqueryClient.isMutatingfor the same mutation key. If another save is still queued it does nothing. Otherwise it invalidates['notification-preferences']and['notification-configs'].- On error the screen shows the
notificationPrefsSaveFailedtoast. The invalidation inonSettledthen restores the real server state.
['notification-configs'] matters for the WORKOUT_REMINDERS group. Those reminders are scheduled on the device by useWorkoutReminders, which reads its on and off state from that query. See Notifications.
Push permission card
Group switches mean nothing if the operating system blocks notifications.usePushPermission() wraps getPushPermissionState() in a query with staleTime: 0 and refetches every time the app returns to the foreground.
When permission is readable and not granted, the screen shows a card above the list with the pushDisabledBanner text and one button:
The card does not hide the group list. The trainee can still set preferences while push is off.
Screen states
Pull to refresh refetches both the preferences and the permission state, and replays the entrance animation through
useReplayAnimation.
Each switch sets accessibilityLabel to the group title and accessibilityHint to its hint.