Skip to content

Commit

Permalink
Merge pull request #901 from openedx/sundas/INF-1086
Browse files Browse the repository at this point in the history
fix: fixed preferences toggle unpredictable behavior
  • Loading branch information
sundasnoreen12 authored Oct 10, 2023
2 parents b08890b + 7f1c7b8 commit 1257e81
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/notification-preferences/NotificationPreferenceRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ 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();
const intl = useIntl();
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 {
Expand Down Expand Up @@ -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}
/>
</div>
))}
Expand Down
1 change: 1 addition & 0 deletions src/notification-preferences/data/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const notificationPreferencesReducer = (state = defaultState, action = {}) => {
? { ...preference, [notificationChannel]: value }
: preference
)),
status: LOADING_STATUS,
},
};
case Actions.UPDATE_APP_PREFERENCE:
Expand Down
2 changes: 1 addition & 1 deletion src/notification-preferences/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const updatePreferenceToggle = (
notificationApp,
notificationType,
notificationChannel,
value,
!value,
));
const data = await patchPreferenceToggle(
courseId,
Expand Down

0 comments on commit 1257e81

Please sign in to comment.