Skip to content

Commit

Permalink
feat: implement showPreferences flag in notification preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
awais-ansari committed Jul 13, 2023
1 parent e720787 commit a499aa4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/account-settings/AccountSettingsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
import { fetchSiteLanguages } from './site-language';
import CoachingToggle from './coaching/CoachingToggle';
import DemographicsSection from './demographics/DemographicsSection';
import { fetchCourseList } from '../notification-preferences/data/thunks';

class AccountSettingsPage extends React.Component {
constructor(props, context) {
Expand Down Expand Up @@ -79,6 +80,7 @@ class AccountSettingsPage extends React.Component {
}

componentDidMount() {
this.props.fetchCourseList();
this.props.fetchSettings();
this.props.fetchSiteLanguages();
sendTrackingLogEvent('edx.user.settings.viewed', {
Expand Down Expand Up @@ -908,6 +910,7 @@ AccountSettingsPage.propTypes = {
saveSettings: PropTypes.func.isRequired,
fetchSettings: PropTypes.func.isRequired,
beginNameChange: PropTypes.func.isRequired,
fetchCourseList: PropTypes.func.isRequired,
tpaProviders: PropTypes.arrayOf(PropTypes.shape({
connected: PropTypes.bool,
})),
Expand Down Expand Up @@ -959,6 +962,7 @@ AccountSettingsPage.defaultProps = {
};

export default connect(accountSettingsPageSelector, {
fetchCourseList,
fetchSettings,
saveSettings,
saveMultipleSettings,
Expand Down
10 changes: 6 additions & 4 deletions src/account-settings/JumpNav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ import { OpenInNew } from '@edx/paragon/icons';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import { useSelector } from 'react-redux';
import { NavHashLink } from 'react-router-hash-link';
import Scrollspy from 'react-scrollspy';
import { Link } from 'react-router-dom';
import messages from './AccountSettingsPage.messages';
import { selectShowPreferences } from '../notification-preferences/data/selectors';

const JumpNav = ({
intl,
displayDemographicsLink,
}) => {
const stickToTop = useWindowSize().width > breakpoints.small.minWidth;
const showNotificationMenu = false;
const showPreferences = useSelector(selectShowPreferences());

return (
<div className={classNames('jump-nav px-2.25', { 'jump-nav-sm position-sticky pt-3': stickToTop })}>
<Scrollspy
Expand Down Expand Up @@ -70,8 +73,7 @@ const JumpNav = ({
</NavHashLink>
</li>
</Scrollspy>
{showNotificationMenu
&& (
{showPreferences && (
<>
<hr />
<Scrollspy
Expand All @@ -85,7 +87,7 @@ const JumpNav = ({
</li>
</Scrollspy>
</>
)}
)}
</div>
);
};
Expand Down
5 changes: 2 additions & 3 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import NotificationCourses from './notification-preferences/NotificationCourses'
import NotificationPreferences from './notification-preferences/NotificationPreferences';

subscribe(APP_READY, () => {
const allowNotificationRoutes = false;
ReactDOM.render(
<AppProvider store={configureStore()}>
<Head />
Expand All @@ -35,8 +34,8 @@ subscribe(APP_READY, () => {
<Header />
<main className="flex-grow-1">
<Switch>
{allowNotificationRoutes && (<Route path="/notifications/:courseId" component={NotificationPreferences} />)}
{allowNotificationRoutes && (<Route path="/notifications" component={NotificationCourses} />)}
<Route path="/notifications/:courseId" component={NotificationPreferences} />
<Route path="/notifications" component={NotificationCourses} />
<Route path="/id-verification" component={IdVerificationPage} />
<Route exact path="/" component={AccountSettingsPage} />
<Route path="/notfound" component={NotFoundPage} />
Expand Down
2 changes: 2 additions & 0 deletions src/notification-preferences/data/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../../constants';

export const defaultState = {
showPreferences: false,
courses: {
status: IDLE_STATUS,
courses: [],
Expand Down Expand Up @@ -42,6 +43,7 @@ const notificationPreferencesReducer = (state = defaultState, action = {}) => {
courses: [...state.courses.courses, ...action.payload.courseList],
pagination: action.payload.pagination,
},
showPreferences: action.payload.showPreferences,
};
case Actions.FAILED_COURSE_LIST:
return {
Expand Down
4 changes: 4 additions & 0 deletions src/notification-preferences/data/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ export const selectSelectedCourseId = () => state => (
export const selectPagination = () => state => (
state.notificationPreferences.courses.pagination
);

export const selectShowPreferences = () => state => (
state.notificationPreferences.showPreferences
);
1 change: 1 addition & 0 deletions src/notification-preferences/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const normalizeCourses = (responseData) => {
return {
courseList,
pagination,
showPreferences: responseData.showPreferences,
};
};

Expand Down

0 comments on commit a499aa4

Please sign in to comment.