Skip to content

Commit

Permalink
fix: fixed issue to update email cadence for account notification type
Browse files Browse the repository at this point in the history
  • Loading branch information
sundasnoreen12 committed Nov 22, 2024
1 parent 5a5de29 commit 42342c2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/notification-preferences/NotificationPreferenceColumn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ 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,
appId,
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') && (
Expand Down
2 changes: 2 additions & 0 deletions src/notification-preferences/data/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ export const postPreferenceToggle = async (
notificationType,
notificationChannel,
value,
emailCadence,
) => {
const patchData = snakeCaseObject({

Check warning on line 43 in src/notification-preferences/data/service.js

View check run for this annotation

Codecov / codecov/patch

src/notification-preferences/data/service.js#L42-L43

Added lines #L42 - L43 were not covered by tests
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);
Expand Down
4 changes: 3 additions & 1 deletion src/notification-preferences/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const normalizeAccountPreferences = (originalData, updateInfo) => {
);

if (preferenceToUpdate) {
preferenceToUpdate[channel] = updatedValue;
preferenceToUpdate[camelCase(channel)] = updatedValue;

Check warning on line 51 in src/notification-preferences/data/thunks.js

View check run for this annotation

Codecov / codecov/patch

src/notification-preferences/data/thunks.js#L51

Added line #L51 was not covered by tests
}

return originalData;

Check warning on line 54 in src/notification-preferences/data/thunks.js

View check run for this annotation

Codecov / codecov/patch

src/notification-preferences/data/thunks.js#L54

Added line #L54 was not covered by tests
Expand Down Expand Up @@ -135,6 +135,7 @@ export const updatePreferenceToggle = (
notificationType,
notificationChannel,
value,
emailCadence,
) => (
async (dispatch) => {
try {
Expand All @@ -161,6 +162,7 @@ export const updatePreferenceToggle = (
notificationType,
notificationChannel,
value,
emailCadence,
);
dispatch(fetchNotificationPreferenceSuccess(courseId, camelCaseObject(data), true));

Check warning on line 167 in src/notification-preferences/data/thunks.js

View check run for this annotation

Codecov / codecov/patch

src/notification-preferences/data/thunks.js#L167

Added line #L167 was not covered by tests
}
Expand Down

0 comments on commit 42342c2

Please sign in to comment.