chore: refactoring the code for readability according to ESLint
This commit is contained in:
@@ -7,7 +7,8 @@ import classNames from 'classnames';
|
||||
import messages from './messages';
|
||||
import ToggleSwitch from './ToggleSwitch';
|
||||
import {
|
||||
selectPreferenceAppToggleValue, selectPreferenceNonEditable,
|
||||
selectPreferenceAppToggleValue,
|
||||
selectNonEditablePreferences,
|
||||
selectPreferencesOfApp,
|
||||
selectSelectedCourseId,
|
||||
selectUpdatePreferencesStatus,
|
||||
@@ -24,32 +25,19 @@ const NotificationPreferenceApp = ({ appId }) => {
|
||||
const appPreferences = useSelector(selectPreferencesOfApp(appId));
|
||||
const appToggle = useSelector(selectPreferenceAppToggleValue(appId));
|
||||
const updatePreferencesStatus = useSelector(selectUpdatePreferencesStatus());
|
||||
const nonEditable = useSelector(selectPreferenceNonEditable(appId));
|
||||
const nonEditable = useSelector(selectNonEditablePreferences(appId));
|
||||
|
||||
const onColumnToggle = useCallback(
|
||||
const onChannelToggle = useCallback(
|
||||
(event) => {
|
||||
const {
|
||||
id: notificationChannel,
|
||||
} = event.target;
|
||||
const truePreferences = appPreferences.filter((preference) => {
|
||||
const isPreferenceNonEditable = nonEditable?.[preference.id]?.includes(notificationChannel) || false;
|
||||
return preference[notificationChannel] === true && !isPreferenceNonEditable;
|
||||
});
|
||||
if (truePreferences.length > 0) {
|
||||
dispatch(updateChannelPreferenceToggle(
|
||||
courseId,
|
||||
appId,
|
||||
notificationChannel,
|
||||
false,
|
||||
));
|
||||
} else {
|
||||
dispatch(updateChannelPreferenceToggle(
|
||||
courseId,
|
||||
appId,
|
||||
notificationChannel,
|
||||
true,
|
||||
));
|
||||
}
|
||||
const { id: notificationChannel } = event.target;
|
||||
const activePreferences = appPreferences.filter((preference) => preference[notificationChannel] === true
|
||||
&& !nonEditable?.[preference.id]?.includes(notificationChannel));
|
||||
dispatch(updateChannelPreferenceToggle(
|
||||
courseId,
|
||||
appId,
|
||||
notificationChannel,
|
||||
!(activePreferences.length > 0),
|
||||
));
|
||||
},
|
||||
[appId, appPreferences, courseId, dispatch, nonEditable],
|
||||
);
|
||||
@@ -70,6 +58,7 @@ const NotificationPreferenceApp = ({ appId }) => {
|
||||
if (!courseId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Collapsible.Advanced open={appToggle} data-testid="notification-app" className="mb-5">
|
||||
<Collapsible.Trigger>
|
||||
@@ -95,6 +84,7 @@ const NotificationPreferenceApp = ({ appId }) => {
|
||||
{NOTIFICATION_CHANNELS.map((channel) => (
|
||||
<NavItem
|
||||
id={channel}
|
||||
key={channel}
|
||||
className={classNames(
|
||||
'd-flex',
|
||||
{ 'ml-auto': channel === 'web' },
|
||||
@@ -102,15 +92,9 @@ const NotificationPreferenceApp = ({ appId }) => {
|
||||
{ 'ml-auto mr-0': channel === 'push' },
|
||||
)}
|
||||
role="button"
|
||||
onClick={onColumnToggle}
|
||||
onClick={onChannelToggle}
|
||||
>
|
||||
{
|
||||
// eslint-disable-next-line no-nested-ternary
|
||||
channel === 'web' ? intl.formatMessage(messages.webLabel)
|
||||
// eslint-disable-next-line no-nested-ternary
|
||||
: channel === 'email' ? intl.formatMessage(messages.notificationHelpEmail)
|
||||
: channel === 'push' ? intl.formatMessage(messages.notificationHelpPush) : null
|
||||
}
|
||||
{intl.formatMessage(messages.notificationChannel, { text: channel })}
|
||||
</NavItem>
|
||||
))}
|
||||
</span>
|
||||
|
||||
@@ -54,7 +54,7 @@ export const selectPreferenceNonEditableChannels = (appId, name) => state => (
|
||||
state?.notificationPreferences.preferences.nonEditable[appId]?.[name] || []
|
||||
);
|
||||
|
||||
export const selectPreferenceNonEditable = (appId) => state => (
|
||||
export const selectNonEditablePreferences = appId => state => (
|
||||
state?.notificationPreferences.preferences.nonEditable[appId] || []
|
||||
);
|
||||
|
||||
|
||||
@@ -43,17 +43,8 @@ export const patchPreferenceToggle = async (
|
||||
return data;
|
||||
};
|
||||
|
||||
export const patchChannelPreferenceToggle = async (
|
||||
courseId,
|
||||
notificationApp,
|
||||
notificationChannel,
|
||||
value,
|
||||
) => {
|
||||
const patchData = snakeCaseObject({
|
||||
notificationApp,
|
||||
notificationChannel,
|
||||
value,
|
||||
});
|
||||
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,7 +13,8 @@ import {
|
||||
import {
|
||||
getCourseList,
|
||||
getCourseNotificationPreferences,
|
||||
patchAppPreferenceToggle, patchChannelPreferenceToggle,
|
||||
patchAppPreferenceToggle,
|
||||
patchChannelPreferenceToggle,
|
||||
patchPreferenceToggle,
|
||||
} from './service';
|
||||
|
||||
@@ -149,20 +150,10 @@ export const updatePreferenceToggle = (
|
||||
}
|
||||
);
|
||||
|
||||
export const updateChannelPreferenceToggle = (
|
||||
courseId,
|
||||
notificationApp,
|
||||
notificationChannel,
|
||||
value,
|
||||
) => (
|
||||
export const updateChannelPreferenceToggle = (courseId, notificationApp, notificationChannel, value) => (
|
||||
async (dispatch) => {
|
||||
try {
|
||||
const data = await patchChannelPreferenceToggle(
|
||||
courseId,
|
||||
notificationApp,
|
||||
notificationChannel,
|
||||
value,
|
||||
);
|
||||
const data = await patchChannelPreferenceToggle(courseId, notificationApp, notificationChannel, value);
|
||||
const normalizedData = normalizePreferences(camelCaseObject(data));
|
||||
dispatch(fetchNotificationPreferenceSuccess(courseId, normalizedData));
|
||||
} catch (errors) {
|
||||
|
||||
@@ -27,6 +27,17 @@ const messages = defineMessages({
|
||||
}`,
|
||||
description: 'Display text for Notification Types',
|
||||
},
|
||||
notificationChannel: {
|
||||
id: 'notification.preference.channel',
|
||||
defaultMessage: `{
|
||||
text, select,
|
||||
web {Web}
|
||||
email {Email}
|
||||
push {Push}
|
||||
other {{text}}
|
||||
}`,
|
||||
description: 'Display text for Notification Channel',
|
||||
},
|
||||
typeLabel: {
|
||||
id: 'notification.preference.type.label',
|
||||
defaultMessage: 'Type',
|
||||
|
||||
Reference in New Issue
Block a user