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 onToggle = useCallback((event, notificationType) => {
const { name: notificationChannel } = event.target; 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( dispatch(updatePreferenceToggle(
courseId, courseId,
@@ -36,9 +38,10 @@ const NotificationPreferenceColumn = ({ appId, channel, appPreference }) => {
notificationType, notificationType,
notificationChannel, notificationChannel,
value, value,
emailCadence,
)); ));
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [appId]); }, [appId, appPreferences]);
const renderPreference = (preference) => ( const renderPreference = (preference) => (
(preference?.coreNotificationTypes?.length > 0 || preference.id !== 'core') && ( (preference?.coreNotificationTypes?.length > 0 || preference.id !== 'core') && (

View File

@@ -38,12 +38,14 @@ export const postPreferenceToggle = async (
notificationType, notificationType,
notificationChannel, notificationChannel,
value, value,
emailCadence,
) => { ) => {
const patchData = snakeCaseObject({ const patchData = snakeCaseObject({
notificationApp, notificationApp,
notificationType: snakeCase(notificationType), notificationType: snakeCase(notificationType),
notificationChannel, notificationChannel,
value, value,
emailCadence,
}); });
const url = `${getConfig().LMS_BASE_URL}/api/notifications/preferences/update-all/`; const url = `${getConfig().LMS_BASE_URL}/api/notifications/preferences/update-all/`;
const { data } = await getAuthenticatedHttpClient().post(url, patchData); const { data } = await getAuthenticatedHttpClient().post(url, patchData);

View File

@@ -48,7 +48,7 @@ export const normalizeAccountPreferences = (originalData, updateInfo) => {
); );
if (preferenceToUpdate) { if (preferenceToUpdate) {
preferenceToUpdate[channel] = updatedValue; preferenceToUpdate[camelCase(channel)] = updatedValue;
} }
return originalData; return originalData;
@@ -135,6 +135,7 @@ export const updatePreferenceToggle = (
notificationType, notificationType,
notificationChannel, notificationChannel,
value, value,
emailCadence,
) => ( ) => (
async (dispatch) => { async (dispatch) => {
try { try {
@@ -161,6 +162,7 @@ export const updatePreferenceToggle = (
notificationType, notificationType,
notificationChannel, notificationChannel,
value, value,
emailCadence,
); );
dispatch(fetchNotificationPreferenceSuccess(courseId, camelCaseObject(data), true)); dispatch(fetchNotificationPreferenceSuccess(courseId, camelCaseObject(data), true));
} }