From bc8197a9afc5278f79b1b90696a2ef6bdfbfbe2a Mon Sep 17 00:00:00 2001 From: sundasnoreen12 Date: Tue, 17 Oct 2023 12:56:31 +0500 Subject: [PATCH] fix: removed extra loader while updating preferences --- src/notification-preferences/NotificationPreferenceRow.jsx | 6 +++--- src/notification-preferences/data/reducers.js | 5 ++++- src/notification-preferences/data/selectors.js | 4 ++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/notification-preferences/NotificationPreferenceRow.jsx b/src/notification-preferences/NotificationPreferenceRow.jsx index 0e9b971fe..6890de3b6 100644 --- a/src/notification-preferences/NotificationPreferenceRow.jsx +++ b/src/notification-preferences/NotificationPreferenceRow.jsx @@ -11,7 +11,7 @@ import { selectPreference, selectPreferenceNonEditableChannels, selectSelectedCourseId, - selectNotificationPreferencesStatus, + selectUpdatePreferencesStatus, } from './data/selectors'; import { updatePreferenceToggle } from './data/thunks'; import { LOADING_STATUS } from '../constants'; @@ -22,7 +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 updatePreferencesStatus = useSelector(selectUpdatePreferencesStatus()); const onToggle = useCallback((event) => { const { @@ -76,7 +76,7 @@ const NotificationPreferenceRow = ({ appId, preferenceName }) => { name={channel} value={preference[channel]} onChange={onToggle} - disabled={nonEditable.includes(channel) || preferencesStatus === LOADING_STATUS} + disabled={nonEditable.includes(channel) || updatePreferencesStatus === LOADING_STATUS} /> ))} diff --git a/src/notification-preferences/data/reducers.js b/src/notification-preferences/data/reducers.js index e27935f92..cb61a7991 100644 --- a/src/notification-preferences/data/reducers.js +++ b/src/notification-preferences/data/reducers.js @@ -15,6 +15,7 @@ export const defaultState = { }, preferences: { status: IDLE_STATUS, + updatePreferenceStatus: IDLE_STATUS, selectedCourse: null, preferences: [], apps: [], @@ -70,6 +71,7 @@ const notificationPreferencesReducer = (state = defaultState, action = {}) => { preferences: { ...state.preferences, status: SUCCESS_STATUS, + updatePreferenceStatus: SUCCESS_STATUS, ...action.payload, }, }; @@ -79,6 +81,7 @@ const notificationPreferencesReducer = (state = defaultState, action = {}) => { preferences: { ...state.preferences, status: FAILURE_STATUS, + updatePreferenceStatus: FAILURE_STATUS, preferences: [], apps: [], nonEditable: {}, @@ -102,7 +105,7 @@ const notificationPreferencesReducer = (state = defaultState, action = {}) => { ? { ...preference, [notificationChannel]: value } : preference )), - status: LOADING_STATUS, + updatePreferenceStatus: LOADING_STATUS, }, }; case Actions.UPDATE_APP_PREFERENCE: diff --git a/src/notification-preferences/data/selectors.js b/src/notification-preferences/data/selectors.js index a7f06230f..d918705c5 100644 --- a/src/notification-preferences/data/selectors.js +++ b/src/notification-preferences/data/selectors.js @@ -2,6 +2,10 @@ export const selectNotificationPreferencesStatus = () => state => ( state.notificationPreferences.preferences.status ); +export const selectUpdatePreferencesStatus = () => state => ( + state.notificationPreferences.preferences.updatePreferenceStatus +); + export const selectPreferences = () => state => ( state.notificationPreferences.preferences?.preferences );