Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removed extra loader while updating preferences #913

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/notification-preferences/NotificationPreferenceRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
selectPreference,
selectPreferenceNonEditableChannels,
selectSelectedCourseId,
selectNotificationPreferencesStatus,
selectUpdatePreferencesStatus,
} from './data/selectors';
import { updatePreferenceToggle } from './data/thunks';
import { LOADING_STATUS } from '../constants';
Expand All @@ -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 {
Expand Down Expand Up @@ -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}
/>
</div>
))}
Expand Down
5 changes: 4 additions & 1 deletion src/notification-preferences/data/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const defaultState = {
},
preferences: {
status: IDLE_STATUS,
updatePreferenceStatus: IDLE_STATUS,
selectedCourse: null,
preferences: [],
apps: [],
Expand Down Expand Up @@ -70,6 +71,7 @@ const notificationPreferencesReducer = (state = defaultState, action = {}) => {
preferences: {
...state.preferences,
status: SUCCESS_STATUS,
updatePreferenceStatus: SUCCESS_STATUS,
...action.payload,
},
};
Expand All @@ -79,6 +81,7 @@ const notificationPreferencesReducer = (state = defaultState, action = {}) => {
preferences: {
...state.preferences,
status: FAILURE_STATUS,
updatePreferenceStatus: FAILURE_STATUS,
preferences: [],
apps: [],
nonEditable: {},
Expand All @@ -102,7 +105,7 @@ const notificationPreferencesReducer = (state = defaultState, action = {}) => {
? { ...preference, [notificationChannel]: value }
: preference
)),
status: LOADING_STATUS,
updatePreferenceStatus: LOADING_STATUS,
},
};
case Actions.UPDATE_APP_PREFERENCE:
Expand Down
9 changes: 6 additions & 3 deletions src/notification-preferences/data/reducers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
FAILURE_STATUS,
LOADING_STATUS,
SUCCESS_STATUS,
IDLE_STATUS,
} from '../../constants';

describe('notification-preferences reducer', () => {
Expand Down Expand Up @@ -80,15 +81,16 @@ describe('notification-preferences reducer', () => {
);
expect(result.preferences).toEqual({
status: SUCCESS_STATUS,
updatePreferenceStatus: SUCCESS_STATUS,
selectedCourse: null,
...preferenceData,
});
});

test.each([
{ action: Actions.FETCHING_PREFERENCES, status: LOADING_STATUS },
{ action: Actions.FAILED_PREFERENCES, status: FAILURE_STATUS },
])('preferences are empty when api call is %s', ({ action, status }) => {
{ action: Actions.FETCHING_PREFERENCES, status: LOADING_STATUS, updatePreferenceStatus: IDLE_STATUS },
{ action: Actions.FAILED_PREFERENCES, status: FAILURE_STATUS, updatePreferenceStatus: FAILURE_STATUS },
])('preferences are empty when api call is %s', ({ action, status, updatePreferenceStatus }) => {
const result = reducer(
state,
{ type: action },
Expand All @@ -99,6 +101,7 @@ describe('notification-preferences reducer', () => {
preferences: [],
apps: [],
nonEditable: {},
updatePreferenceStatus,
});
});

Expand Down
4 changes: 4 additions & 0 deletions src/notification-preferences/data/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
Loading