Skip to content

Commit

Permalink
Merge pull request #1049 from openedx/sundas/INF-1360
Browse files Browse the repository at this point in the history
fix: fixed environment variable issue for email cadence
  • Loading branch information
sundasnoreen12 authored May 16, 2024
2 parents 16fb3a1 + 82c9e07 commit 90da117
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/notification-preferences/EmailCadences.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@openedx/paragon';

import messages from './messages';
import { EMAIL_CADENCE } from './data/constants';
import EMAIL_CADENCE from './data/constants';

const EmailCadences = ({
email, onToggle, emailCadence, notificationType,
Expand Down
3 changes: 2 additions & 1 deletion src/notification-preferences/NotificationPreferenceApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useIsOnMobile } from '../hooks';
import ToggleSwitch from './ToggleSwitch';
import { LOADING_STATUS } from '../constants';
import NotificationTypes from './NotificationTypes';
import { NOTIFICATION_CHANNELS } from './data/constants';
import { notificationChannels } from './data/utils';
import { updateAppPreferenceToggle } from './data/thunks';
import NotificationPreferenceColumn from './NotificationPreferenceColumn';
import { selectPreferenceAppToggleValue, selectSelectedCourseId, selectUpdatePreferencesStatus } from './data/selectors';
Expand All @@ -24,6 +24,7 @@ const NotificationPreferenceApp = ({ appId }) => {
const appToggle = useSelector(selectPreferenceAppToggleValue(appId));
const updatePreferencesStatus = useSelector(selectUpdatePreferencesStatus());
const mobileView = useIsOnMobile();
const NOTIFICATION_CHANNELS = notificationChannels();

const onChangeAppSettings = useCallback((event) => {
dispatch(updateAppPreferenceToggle(courseId, appId, event.target.checked));
Expand Down
9 changes: 7 additions & 2 deletions src/notification-preferences/NotificationPreferenceColumn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { updateChannelPreferenceToggle, updatePreferenceToggle } from './data/th
import {
selectNonEditablePreferences, selectPreferencesOfApp, selectSelectedCourseId, selectUpdatePreferencesStatus,
} from './data/selectors';
import { notificationChannels, shouldHideAppPreferences } from './data/utils';

const NotificationPreferenceColumn = ({ appId, channel, appPreference }) => {
const dispatch = useDispatch();
Expand All @@ -25,6 +26,8 @@ const NotificationPreferenceColumn = ({ appId, channel, appPreference }) => {
const nonEditable = useSelector(selectNonEditablePreferences(appId));
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;
Expand Down Expand Up @@ -59,7 +62,7 @@ const NotificationPreferenceColumn = ({ appId, channel, appPreference }) => {
className={classNames(
'd-flex align-items-center justify-content-center mb-2 h-4.5 column-padding',
{
'pr-0': channel === 'email',
'pr-0': channel === NOTIFICATION_CHANNELS[NOTIFICATION_CHANNELS.length - 1],
'pl-0': channel === 'web' && mobileView,
},
)}
Expand All @@ -86,18 +89,20 @@ const NotificationPreferenceColumn = ({ appId, channel, appPreference }) => {

return (
<div className={classNames('d-flex flex-column border-right channel-column')}>
{!hideAppPreferences && (
<NavItem
id={channel}
key={channel}
role="button"
onClick={onChannelToggle}
className={classNames('mb-3 header-label column-padding', {
'pr-0': channel === 'email',
'pr-0': channel === NOTIFICATION_CHANNELS[NOTIFICATION_CHANNELS.length - 1],
'pl-0': channel === 'web' && mobileView,
})}
>
{intl.formatMessage(messages.notificationChannel, { text: channel })}
</NavItem>
)}
{appPreference
? renderPreference(appPreference)
: appPreferences.map((preference) => (renderPreference(preference)))}
Expand Down
7 changes: 5 additions & 2 deletions src/notification-preferences/NotificationTypes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ import { Icon, OverlayTrigger, Tooltip } from '@openedx/paragon';

import messages from './messages';
import { useIsOnMobile } from '../hooks';
import { NOTIFICATION_CHANNELS } from './data/constants';
import { notificationChannels, shouldHideAppPreferences } from './data/utils';

import { selectPreferencesOfApp } from './data/selectors';
import NotificationPreferenceColumn from './NotificationPreferenceColumn';

const NotificationTypes = ({ appId }) => {
const intl = useIntl();
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') && (
<>
Expand Down
8 changes: 3 additions & 5 deletions src/notification-preferences/data/constants.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import showEmailChannel from './utils';

export const NOTIFICATION_CHANNELS = showEmailChannel();

export const EMAIL_CADENCE = {
const EMAIL_CADENCE = {
DAILY: 'Daily',
WEEKLY: 'Weekly',
IMMEDIATELY: 'Immediately',
NEVER: 'Never',
};

export default EMAIL_CADENCE;
2 changes: 1 addition & 1 deletion src/notification-preferences/data/thunks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { camelCaseObject } from '@edx/frontend-platform';
import { EMAIL_CADENCE } from './constants';
import EMAIL_CADENCE from './constants';
import {
fetchCourseListSuccess,
fetchCourseListFetching,
Expand Down
14 changes: 12 additions & 2 deletions src/notification-preferences/data/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { getConfig } from '@edx/frontend-platform';

const showEmailChannel = () => ({ WEB: 'web', ...(getConfig().SHOW_EMAIL_CHANNEL === 'true' && { EMAIL: 'email' }) });
export const notificationChannels = () => ({ WEB: 'web', ...(getConfig().SHOW_EMAIL_CHANNEL === 'true' && { EMAIL: 'email' }) });

export default showEmailChannel;
export const shouldHideAppPreferences = (preferences, appId) => {
const appPreferences = preferences.filter(pref => pref.appId === appId);

if (appPreferences.length !== 1) {
return false;
}

const firstPreference = appPreferences[0];

return firstPreference?.id === 'core' && (!firstPreference.coreNotificationTypes?.length);
};

0 comments on commit 90da117

Please sign in to comment.