Skip to content

Commit

Permalink
Merge pull request #1089 from openedx/INF-1300
Browse files Browse the repository at this point in the history
refactor: removed the channel wide toggle feature
  • Loading branch information
eemaanamir authored Jul 24, 2024
2 parents cc50ad9 + 5903ad2 commit 4390ca5
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 41 deletions.
19 changes: 2 additions & 17 deletions src/notification-preferences/NotificationPreferenceColumn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,20 @@ import { useIsOnMobile } from '../hooks';
import ToggleSwitch from './ToggleSwitch';
import EmailCadences from './EmailCadences';
import { LOADING_STATUS } from '../constants';
import { updateChannelPreferenceToggle, updatePreferenceToggle } from './data/thunks';
import {
selectNonEditablePreferences, selectAppPreferences, selectSelectedCourseId, selectUpdatePreferencesStatus,
} from './data/selectors';
import { updatePreferenceToggle } from './data/thunks';
import { selectAppPreferences, selectSelectedCourseId, selectUpdatePreferencesStatus } from './data/selectors';
import { notificationChannels, shouldHideAppPreferences } from './data/utils';

const NotificationPreferenceColumn = ({ appId, channel, appPreference }) => {
const dispatch = useDispatch();
const intl = useIntl();
const courseId = useSelector(selectSelectedCourseId());
const appPreferences = useSelector(selectAppPreferences(appId));
const nonEditable = useSelector(selectNonEditablePreferences(appId));
const updatePreferencesStatus = useSelector(selectUpdatePreferencesStatus());
const mobileView = useIsOnMobile();
const NOTIFICATION_CHANNELS = Object.values(notificationChannels());
const hideAppPreferences = shouldHideAppPreferences(appPreferences, appId) || false;

const onChannelToggle = useCallback((event) => {
const { id: notificationChannel } = event.target;
const isPreferenceNonEditable = (preference) => nonEditable?.[preference.id]?.includes(notificationChannel);

const hasActivePreferences = appPreferences.some(
(preference) => preference[notificationChannel] && !isPreferenceNonEditable(preference),
);

dispatch(updateChannelPreferenceToggle(courseId, appId, notificationChannel, !hasActivePreferences));
}, [appId, appPreferences, courseId, dispatch, nonEditable]);

const onToggle = useCallback((event, notificationType) => {
const { name: notificationChannel } = event.target;
const value = notificationChannel === 'email_cadence' ? event.target.innerText : event.target.checked;
Expand Down Expand Up @@ -93,7 +79,6 @@ const NotificationPreferenceColumn = ({ appId, channel, appPreference }) => {
id={channel}
key={channel}
role="button"
onClick={onChannelToggle}
className={classNames('mb-3 header-label column-padding', {
'pr-0': channel === NOTIFICATION_CHANNELS[NOTIFICATION_CHANNELS.length - 1],
'pl-0': channel === 'web',
Expand Down
4 changes: 0 additions & 4 deletions src/notification-preferences/data/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ export const selectPreferenceNonEditableChannels = (appId, name) => state => (
state?.notificationPreferences.preferences.nonEditable[appId]?.[name] || []
);

export const selectNonEditablePreferences = appId => state => (
state?.notificationPreferences.preferences.nonEditable[appId] || []
);

export const selectSelectedCourseId = () => state => (
state.notificationPreferences.preferences.selectedCourse
);
Expand Down
7 changes: 0 additions & 7 deletions src/notification-preferences/data/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,3 @@ export const patchPreferenceToggle = async (
const { data } = await getAuthenticatedHttpClient().patch(url, patchData);
return data;
};

export const patchChannelPreferenceToggle = async (courseId, notificationApp, notificationChannel, value) => {
const patchData = snakeCaseObject({ notificationApp, notificationChannel, value });
const url = `${getConfig().LMS_BASE_URL}/api/notifications/channel/configurations/${courseId}`;
const { data } = await getAuthenticatedHttpClient().patch(url, patchData);
return data;
};
13 changes: 0 additions & 13 deletions src/notification-preferences/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import {
getCourseList,
getCourseNotificationPreferences,
patchChannelPreferenceToggle,
patchPreferenceToggle,
} from './service';

Expand Down Expand Up @@ -136,15 +135,3 @@ export const updatePreferenceToggle = (
}
}
);

export const updateChannelPreferenceToggle = (courseId, notificationApp, notificationChannel, value) => (
async (dispatch) => {
try {
const data = await patchChannelPreferenceToggle(courseId, notificationApp, notificationChannel, value);
const normalizedData = normalizePreferences(camelCaseObject(data));
dispatch(fetchNotificationPreferenceSuccess(courseId, normalizedData));
} catch (errors) {
dispatch(fetchNotificationPreferenceFailed());
}
}
);

0 comments on commit 4390ca5

Please sign in to comment.