fix: hide type and web option from the header when there is no preference under app
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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 (
|
||||
<div className={classNames('d-flex flex-column border-right channel-column')}>
|
||||
{!hideAppPreferences && (
|
||||
<NavItem
|
||||
id={channel}
|
||||
key={channel}
|
||||
@@ -100,6 +102,7 @@ const NotificationPreferenceColumn = ({ appId, channel, appPreference }) => {
|
||||
>
|
||||
{intl.formatMessage(messages.notificationChannel, { text: channel })}
|
||||
</NavItem>
|
||||
)}
|
||||
{appPreference
|
||||
? renderPreference(appPreference)
|
||||
: appPreferences.map((preference) => (renderPreference(preference)))}
|
||||
|
||||
@@ -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 (
|
||||
<div className="d-flex flex-column mr-auto px-0">
|
||||
{!mobileView && <span className="mb-3 header-label">{intl.formatMessage(messages.typeLabel)}</span>}
|
||||
{!mobileView && !hideAppPreferences && <span className="mb-3 header-label">{intl.formatMessage(messages.typeLabel)}</span>}
|
||||
{preferences.map(preference => (
|
||||
(preference?.coreNotificationTypes?.length > 0 || preference.id !== 'core') && (
|
||||
<>
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user