fix: fixed issue to update email cadence for account notification type

This commit is contained in:
sundasnoreen12
2024-11-22 13:26:04 +05:00
parent 5a5de29dea
commit 42342c2b18
3 changed files with 10 additions and 3 deletions

View File

@@ -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') && (

View File

@@ -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);

View File

@@ -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));
}