-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added notification preference ui
- Loading branch information
adeel.tajamul
committed
May 12, 2023
1 parent
7cf9294
commit 1282815
Showing
17 changed files
with
719 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { Link } from 'react-router-dom'; | ||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
import { Container, Icon, Spinner } from '@edx/paragon'; | ||
import { ArrowForwardIos } from '@edx/paragon/icons'; | ||
import { fetchCourseList } from './data/thunks'; | ||
import { courseListStatus, getCourseList } from './data/selectors'; | ||
import { IDLE_STATUS, LOADING_STATUS } from '../constants'; | ||
import { messages } from './messages'; | ||
|
||
const NotificationCourses = ({ intl }) => { | ||
const dispatch = useDispatch(); | ||
const courseStatus = useSelector(courseListStatus()); | ||
const coursesList = useSelector(getCourseList()); | ||
useEffect(() => { | ||
if (courseStatus === IDLE_STATUS || coursesList.length === 0) { | ||
dispatch(fetchCourseList()); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [courseStatus]); | ||
if (courseStatus === LOADING_STATUS) { | ||
return ( | ||
<div className="d-flex h-100"> | ||
<Spinner | ||
variant="primary" | ||
animation="border" | ||
className="mx-auto my-auto" | ||
style={{ width: '4rem', height: '4rem' }} | ||
/> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<Container size="md"> | ||
<h2 className="notification-heading mt-6 mb-5.5"> | ||
{intl.formatMessage(messages.notificationHeading)} | ||
</h2> | ||
<div> | ||
{ | ||
coursesList.map(course => ( | ||
<Link | ||
to={`/notifications/${course.id}`} | ||
> | ||
<div className="mb-4 d-flex text-gray-700"> | ||
<span className="ml-0 mr-auto"> | ||
{course.name} | ||
</span> | ||
<span className="ml-auto mr-0"> | ||
<Icon src={ArrowForwardIos} /> | ||
</span> | ||
</div> | ||
</Link> | ||
)) | ||
} | ||
</div> | ||
</Container> | ||
); | ||
}; | ||
|
||
NotificationCourses.propTypes = { | ||
intl: intlShape.isRequired, | ||
}; | ||
|
||
export default injectIntl(NotificationCourses); |
71 changes: 71 additions & 0 deletions
71
src/notification-preferences/NotificationPreferenceGroup.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { useCallback, useMemo, useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { Collapsible } from '@edx/paragon'; | ||
import { messages } from './messages'; | ||
import ToggleSwitch from './ToggleSwitch'; | ||
import { | ||
getPreferenceGroup, | ||
getSelectedCourse, | ||
} from './data/selectors'; | ||
import NotificationPreferenceRow from './NotificationPreferenceRow'; | ||
import { updateGroupValue } from './data/actions'; | ||
|
||
const NotificationPreferenceGroup = ({ groupId }) => { | ||
const dispatch = useDispatch(); | ||
const intl = useIntl(); | ||
const courseId = useSelector(getSelectedCourse()); | ||
const preferenceGroup = useSelector(getPreferenceGroup(groupId)); | ||
const preferences = useMemo(() => ( | ||
preferenceGroup.map(preference => ( | ||
<NotificationPreferenceRow | ||
key={preference.id} | ||
groupId={groupId} | ||
preferenceName={preference.id} | ||
/> | ||
))), [groupId, preferenceGroup]); | ||
const [groupToggle, setGroupToggle] = useState(true); | ||
const onChangeGroupSettings = useCallback((checked) => { | ||
setGroupToggle(checked); | ||
dispatch(updateGroupValue(courseId, groupId, checked)); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [groupId]); | ||
if (!courseId) { | ||
return null; | ||
} | ||
return ( | ||
<Collapsible.Advanced open={groupToggle}> | ||
<Collapsible.Trigger> | ||
<div className="d-flex"> | ||
<span className="ml-0 mr-auto"> | ||
{intl.formatMessage(messages.notificationGroupTitle, { key: groupId })} | ||
</span> | ||
<span className="ml-auto mr-0"> | ||
<ToggleSwitch value={groupToggle} onChange={onChangeGroupSettings} /> | ||
</span> | ||
</div> | ||
<hr /> | ||
</Collapsible.Trigger> | ||
<Collapsible.Body> | ||
<div className="d-flex flex-row notification-help-text"> | ||
<span className="col-8 px-0">{intl.formatMessage(messages.notificationHelpType)}</span> | ||
<span className="d-flex col-4 px-0"> | ||
<span className="ml-0 mr-auto">{intl.formatMessage(messages.notificationHelpWeb)}</span> | ||
<span className="mx-auto">{intl.formatMessage(messages.notificationHelpEmail)}</span> | ||
<span className="ml-auto mr-0 pr-2.5">{intl.formatMessage(messages.notificationHelpPush)}</span> | ||
</span> | ||
</div> | ||
<div className="mt-3 pb-5"> | ||
{ preferences } | ||
</div> | ||
</Collapsible.Body> | ||
</Collapsible.Advanced> | ||
); | ||
}; | ||
|
||
NotificationPreferenceGroup.propTypes = { | ||
groupId: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default React.memo(NotificationPreferenceGroup); |
51 changes: 51 additions & 0 deletions
51
src/notification-preferences/NotificationPreferenceRow.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { useCallback } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { messages } from './messages'; | ||
import ToggleSwitch from './ToggleSwitch'; | ||
import { getPreferenceAttribute } from './data/selectors'; | ||
import { updatePreferenceValue } from './data/actions'; | ||
|
||
const NotificationPreferenceRow = ({ groupId, preferenceName }) => { | ||
const dispatch = useDispatch(); | ||
const intl = useIntl(); | ||
const preference = useSelector(getPreferenceAttribute(groupId, preferenceName)); | ||
const onToggle = useCallback((checked, notificationChannel) => { | ||
dispatch(updatePreferenceValue(groupId, preferenceName, notificationChannel, checked)); | ||
}, [dispatch, groupId, preferenceName]); | ||
return ( | ||
<div className="d-flex flex-row mb-3"> | ||
<span className="col-8 px-0"> | ||
{intl.formatMessage(messages.notificationTitle, { text: preferenceName })} | ||
</span> | ||
<span className="d-flex col-4 px-0"> | ||
<span className="ml-0 mr-auto"> | ||
<ToggleSwitch | ||
value={preference.web} | ||
onChange={(checked) => onToggle(checked, 'web')} | ||
/> | ||
</span> | ||
<span className="mx-auto"> | ||
<ToggleSwitch | ||
value={preference.email} | ||
onChange={(checked) => onToggle(checked, 'email')} | ||
/> | ||
</span> | ||
<span className="ml-auto mr-0"> | ||
<ToggleSwitch | ||
value={preference.push} | ||
onChange={(checked) => onToggle(checked, 'push')} | ||
/> | ||
</span> | ||
</span> | ||
</div> | ||
); | ||
}; | ||
|
||
NotificationPreferenceRow.propTypes = { | ||
groupId: PropTypes.string.isRequired, | ||
preferenceName: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default React.memo(NotificationPreferenceRow); |
Oops, something went wrong.