From 7f1c7b86ef6080b8d04a1df20bdf24c511e668f4 Mon Sep 17 00:00:00 2001 From: sundasnoreen12 Date: Mon, 9 Oct 2023 11:52:58 +0500 Subject: [PATCH] fix: fixed preferences toggle unpredictable behaviour --- src/notification-preferences/NotificationPreferenceRow.jsx | 5 ++++- src/notification-preferences/data/reducers.js | 1 + src/notification-preferences/data/thunks.js | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/notification-preferences/NotificationPreferenceRow.jsx b/src/notification-preferences/NotificationPreferenceRow.jsx index 72b2299d6..0e9b971fe 100644 --- a/src/notification-preferences/NotificationPreferenceRow.jsx +++ b/src/notification-preferences/NotificationPreferenceRow.jsx @@ -11,8 +11,10 @@ import { selectPreference, selectPreferenceNonEditableChannels, selectSelectedCourseId, + selectNotificationPreferencesStatus, } from './data/selectors'; import { updatePreferenceToggle } from './data/thunks'; +import { LOADING_STATUS } from '../constants'; const NotificationPreferenceRow = ({ appId, preferenceName }) => { const dispatch = useDispatch(); @@ -20,6 +22,7 @@ const NotificationPreferenceRow = ({ appId, preferenceName }) => { const courseId = useSelector(selectSelectedCourseId()); const preference = useSelector(selectPreference(appId, preferenceName)); const nonEditable = useSelector(selectPreferenceNonEditableChannels(appId, preferenceName)); + const preferencesStatus = useSelector(selectNotificationPreferencesStatus()); const onToggle = useCallback((event) => { const { @@ -73,7 +76,7 @@ const NotificationPreferenceRow = ({ appId, preferenceName }) => { name={channel} value={preference[channel]} onChange={onToggle} - disabled={nonEditable.includes(channel)} + disabled={nonEditable.includes(channel) || preferencesStatus === LOADING_STATUS} /> ))} diff --git a/src/notification-preferences/data/reducers.js b/src/notification-preferences/data/reducers.js index cbdc83a56..e27935f92 100644 --- a/src/notification-preferences/data/reducers.js +++ b/src/notification-preferences/data/reducers.js @@ -102,6 +102,7 @@ const notificationPreferencesReducer = (state = defaultState, action = {}) => { ? { ...preference, [notificationChannel]: value } : preference )), + status: LOADING_STATUS, }, }; case Actions.UPDATE_APP_PREFERENCE: diff --git a/src/notification-preferences/data/thunks.js b/src/notification-preferences/data/thunks.js index dcc865f5f..86ff5c0f8 100644 --- a/src/notification-preferences/data/thunks.js +++ b/src/notification-preferences/data/thunks.js @@ -126,7 +126,7 @@ export const updatePreferenceToggle = ( notificationApp, notificationType, notificationChannel, - value, + !value, )); const data = await patchPreferenceToggle( courseId,