From e623f03c4bcf5ccacbe807ebdb8b2beced5bcd40 Mon Sep 17 00:00:00 2001 From: sundasnoreen12 Date: Wed, 15 May 2024 17:57:54 +0500 Subject: [PATCH] fix: hide type and web option from the header when there is no preference under app --- .../NotificationPreferenceApp.jsx | 2 +- .../NotificationPreferenceColumn.jsx | 5 ++++- src/notification-preferences/NotificationTypes.jsx | 5 +++-- src/notification-preferences/data/utils.js | 8 ++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/notification-preferences/NotificationPreferenceApp.jsx b/src/notification-preferences/NotificationPreferenceApp.jsx index 6f80cb7..94d0f43 100644 --- a/src/notification-preferences/NotificationPreferenceApp.jsx +++ b/src/notification-preferences/NotificationPreferenceApp.jsx @@ -12,7 +12,7 @@ import { useIsOnMobile } from '../hooks'; import ToggleSwitch from './ToggleSwitch'; import { LOADING_STATUS } from '../constants'; import NotificationTypes from './NotificationTypes'; -import notificationChannels from './data/utils'; +import { notificationChannels } from './data/utils'; import { updateAppPreferenceToggle } from './data/thunks'; import NotificationPreferenceColumn from './NotificationPreferenceColumn'; import { selectPreferenceAppToggleValue, selectSelectedCourseId, selectUpdatePreferencesStatus } from './data/selectors'; diff --git a/src/notification-preferences/NotificationPreferenceColumn.jsx b/src/notification-preferences/NotificationPreferenceColumn.jsx index 7405664..e5a7038 100644 --- a/src/notification-preferences/NotificationPreferenceColumn.jsx +++ b/src/notification-preferences/NotificationPreferenceColumn.jsx @@ -16,7 +16,7 @@ import { updateChannelPreferenceToggle, updatePreferenceToggle } from './data/th import { selectNonEditablePreferences, selectPreferencesOfApp, selectSelectedCourseId, selectUpdatePreferencesStatus, } from './data/selectors'; -import notificationChannels from './data/utils'; +import { notificationChannels, shouldHideAppPreferences } from './data/utils'; const NotificationPreferenceColumn = ({ appId, channel, appPreference }) => { const dispatch = useDispatch(); @@ -27,6 +27,7 @@ const NotificationPreferenceColumn = ({ appId, channel, appPreference }) => { const updatePreferencesStatus = useSelector(selectUpdatePreferencesStatus()); const mobileView = useIsOnMobile(); const NOTIFICATION_CHANNELS = Object.values(notificationChannels()); + const hideAppPreferences = shouldHideAppPreferences(appPreferences, appId) || false; const onChannelToggle = useCallback((event) => { const { id: notificationChannel } = event.target; @@ -88,6 +89,7 @@ const NotificationPreferenceColumn = ({ appId, channel, appPreference }) => { return (
+ {!hideAppPreferences && ( { > {intl.formatMessage(messages.notificationChannel, { text: channel })} + )} {appPreference ? renderPreference(appPreference) : appPreferences.map((preference) => (renderPreference(preference)))} diff --git a/src/notification-preferences/NotificationTypes.jsx b/src/notification-preferences/NotificationTypes.jsx index a389625..628538d 100644 --- a/src/notification-preferences/NotificationTypes.jsx +++ b/src/notification-preferences/NotificationTypes.jsx @@ -9,7 +9,7 @@ import { Icon, OverlayTrigger, Tooltip } from '@openedx/paragon'; import messages from './messages'; import { useIsOnMobile } from '../hooks'; -import notificationChannels from './data/utils'; +import { notificationChannels, shouldHideAppPreferences } from './data/utils'; import { selectPreferencesOfApp } from './data/selectors'; import NotificationPreferenceColumn from './NotificationPreferenceColumn'; @@ -19,10 +19,11 @@ const NotificationTypes = ({ appId }) => { const preferences = useSelector(selectPreferencesOfApp(appId)); const mobileView = useIsOnMobile(); const NOTIFICATION_CHANNELS = notificationChannels(); + const hideAppPreferences = shouldHideAppPreferences(preferences, appId) || false; return (
- {!mobileView && {intl.formatMessage(messages.typeLabel)}} + {!mobileView && !hideAppPreferences && {intl.formatMessage(messages.typeLabel)}} {preferences.map(preference => ( (preference?.coreNotificationTypes?.length > 0 || preference.id !== 'core') && ( <> diff --git a/src/notification-preferences/data/utils.js b/src/notification-preferences/data/utils.js index e2fb5d6..795aee9 100644 --- a/src/notification-preferences/data/utils.js +++ b/src/notification-preferences/data/utils.js @@ -1,5 +1,9 @@ import { getConfig } from '@edx/frontend-platform'; -const notificationChannels = () => ({ WEB: 'web', ...(getConfig().SHOW_EMAIL_CHANNEL === 'true' && { EMAIL: 'email' }) }); +export const notificationChannels = () => ({ WEB: 'web', ...(getConfig().SHOW_EMAIL_CHANNEL === 'true' && { EMAIL: 'email' }) }); -export default notificationChannels; +export const shouldHideAppPreferences = (preferences, appId) => { + const appPreferences = preferences.filter(pref => pref.appId === appId); + + return appPreferences.length === 1 && appPreferences[0].id === 'core' && !appPreferences[0].coreNotificationTypes.length; +};