diff --git a/src/notification-preferences/NotificationPreferenceColumn.jsx b/src/notification-preferences/NotificationPreferenceColumn.jsx index 32a3d7fd7..c92e4789b 100644 --- a/src/notification-preferences/NotificationPreferenceColumn.jsx +++ b/src/notification-preferences/NotificationPreferenceColumn.jsx @@ -28,7 +28,9 @@ const NotificationPreferenceColumn = ({ appId, channel, appPreference }) => { const onToggle = useCallback((event, notificationType) => { const { name: notificationChannel } = event.target; - const value = notificationChannel === 'email_cadence' ? event.target.innerText : event.target.checked; + const appNotificationPreference = appPreferences.find(x => x.id === notificationType); + const value = notificationChannel === 'email_cadence' && courseId ? event.target.innerText : event.target.checked; + const emailCadence = notificationChannel === 'email_cadence' ? event.target.innerText : appNotificationPreference.emailCadence; dispatch(updatePreferenceToggle( courseId, @@ -36,9 +38,10 @@ const NotificationPreferenceColumn = ({ appId, channel, appPreference }) => { notificationType, notificationChannel, value, + emailCadence, )); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [appId]); + }, [appId, appPreferences]); const renderPreference = (preference) => ( (preference?.coreNotificationTypes?.length > 0 || preference.id !== 'core') && ( diff --git a/src/notification-preferences/data/service.js b/src/notification-preferences/data/service.js index 67380c3d9..98b18fe98 100644 --- a/src/notification-preferences/data/service.js +++ b/src/notification-preferences/data/service.js @@ -38,12 +38,14 @@ export const postPreferenceToggle = async ( notificationType, notificationChannel, value, + emailCadence, ) => { const patchData = snakeCaseObject({ notificationApp, notificationType: snakeCase(notificationType), notificationChannel, value, + emailCadence, }); const url = `${getConfig().LMS_BASE_URL}/api/notifications/preferences/update-all/`; const { data } = await getAuthenticatedHttpClient().post(url, patchData); diff --git a/src/notification-preferences/data/thunks.js b/src/notification-preferences/data/thunks.js index 62a802cac..1b21a6d1a 100644 --- a/src/notification-preferences/data/thunks.js +++ b/src/notification-preferences/data/thunks.js @@ -48,7 +48,7 @@ export const normalizeAccountPreferences = (originalData, updateInfo) => { ); if (preferenceToUpdate) { - preferenceToUpdate[channel] = updatedValue; + preferenceToUpdate[camelCase(channel)] = updatedValue; } return originalData; @@ -135,6 +135,7 @@ export const updatePreferenceToggle = ( notificationType, notificationChannel, value, + emailCadence, ) => ( async (dispatch) => { try { @@ -161,6 +162,7 @@ export const updatePreferenceToggle = ( notificationType, notificationChannel, value, + emailCadence, ); dispatch(fetchNotificationPreferenceSuccess(courseId, camelCaseObject(data), true)); }