From 8ed18f3d699f48ceb38576d5dd49370439627c57 Mon Sep 17 00:00:00 2001 From: SundasNoreen Date: Thu, 25 May 2023 11:58:38 +0500 Subject: [PATCH] refactor: UI refactor based on figma --- src/Notifications/NotificationRowItem.jsx | 18 +- src/Notifications/NotificationSections.jsx | 6 +- src/Notifications/NotificationTabs.jsx | 18 +- src/Notifications/Notifications.jsx | 25 +- src/Notifications/data/api.js | 306 +++++++++------------ src/Notifications/data/selectors.js | 1 + src/__snapshots__/Header.test.jsx.snap | 2 +- src/index.scss | 77 ++---- 8 files changed, 205 insertions(+), 248 deletions(-) diff --git a/src/Notifications/NotificationRowItem.jsx b/src/Notifications/NotificationRowItem.jsx index c21793a..6541bd8 100644 --- a/src/Notifications/NotificationRowItem.jsx +++ b/src/Notifications/NotificationRowItem.jsx @@ -55,15 +55,15 @@ const NotificationRowItem = ({ notification }) => { const iconComponent = getIconByType(notification.type); return ( -
-
+
+
-
+
{notification?.respondingUser} {' '} @@ -82,13 +82,13 @@ const NotificationRowItem = ({ notification }) => { {' '}{notification?.notificationContent} -
- {notification.status === 'unread' &&
} +
+ {notification.status === 'unread' &&
}
-
- +
+ {notification?.courseName} - + {intl.formatMessage(messages.fullStop)} diff --git a/src/Notifications/NotificationSections.jsx b/src/Notifications/NotificationSections.jsx index d71329c..0a2103b 100644 --- a/src/Notifications/NotificationSections.jsx +++ b/src/Notifications/NotificationSections.jsx @@ -14,8 +14,8 @@ const NotificationSections = ({ handleLoadMoreNotification, loadMoreCount }) => return ( notifications && ( -
-
+
+
{TODAY && TODAY.length > 0 && intl.formatMessage(messages.notificationTodayHeading)} @@ -29,7 +29,7 @@ const NotificationSections = ({ handleLoadMoreNotification, loadMoreCount }) => {TODAY && TODAY.map( (notification) => , )} -
+
{EARLIER && EARLIER.length > 0 && intl.formatMessage(messages.notificationEarlierHeading)} diff --git a/src/Notifications/NotificationTabs.jsx b/src/Notifications/NotificationTabs.jsx index 0828fab..8fd9cea 100644 --- a/src/Notifications/NotificationTabs.jsx +++ b/src/Notifications/NotificationTabs.jsx @@ -4,12 +4,13 @@ import React, { import { Tabs, Tab } from '@edx/paragon'; import { useSelector, useDispatch } from 'react-redux'; import NotificationSections from './NotificationSections'; -import { getNotificationTotalUnseenCounts } from './data/selectors'; +import { getNotificationTotalUnseenCounts, getSelectedNotificationType } from './data/selectors'; import { fetchNotificationList } from './data/thunks'; import { notificationTabsOptions } from './data/constants'; const NotificationTabs = () => { const notificationUnseenCounts = useSelector(getNotificationTotalUnseenCounts()); + const selectedNotificationType = useSelector(getSelectedNotificationType()); const [activeTab, setActiveTab] = useState(notificationTabsOptions[0].key); const [loadMoreCount, setLoadMoreCount] = useState(10); @@ -32,17 +33,24 @@ const NotificationTabs = () => { eventKey={option.key} title={option.title} notification={notificationUnseenCounts[option.title]} - tabClassName="notification-tab d-flex flex-row align-items-center" + tabClassName="d-flex flex-row align-items-center pt-0 pb-2.5 line-height-24 px-0 mr-4" > - + {option.key === selectedNotificationType + && } - )), [notificationUnseenCounts, handleLoadMoreNotification, loadMoreCount]); + )), [notificationUnseenCounts, handleLoadMoreNotification, loadMoreCount, selectedNotificationType]); + + // This code is used to replace More... text to More to match the UI + const buttons = document.getElementsByClassName('dropdown-toggle'); + for (let i = 0; i < buttons.length; i++) { + buttons[i].firstChild.nodeValue = 'More'; + } return ( activeTab && ( {tabArray} diff --git a/src/Notifications/Notifications.jsx b/src/Notifications/Notifications.jsx index 60d0f96..a9f4ddc 100644 --- a/src/Notifications/Notifications.jsx +++ b/src/Notifications/Notifications.jsx @@ -49,7 +49,7 @@ const Notifications = () => { }, []); return ( -
+
{ overlay={(
- -

+ +

{intl.formatMessage(messages.notificationTitle)}

-
- -
+
@@ -80,8 +81,10 @@ const Notifications = () => { > <> {notificationCounts?.Total > 0 && ( - - {notificationCounts?.Total} + + {notificationCounts?.Total} )}
diff --git a/src/Notifications/data/api.js b/src/Notifications/data/api.js index 0de5a60..64b812c 100644 --- a/src/Notifications/data/api.js +++ b/src/Notifications/data/api.js @@ -2,180 +2,148 @@ import { getConfig } from '@edx/frontend-platform'; export const getApiBaseUrl = () => getConfig().LMS_BASE_URL; +const parseNotificationList = (notificationList) => { + const currentTime = Date.now(); + const twentyFourHoursAgo = currentTime - (24 * 60 * 60 * 1000); + const today = []; + const earlier = []; + notificationList.forEach(obj => { + const objectTime = obj.time; + if (objectTime >= twentyFourHoursAgo && objectTime <= currentTime) { today.push(obj); } else { earlier.push(obj); } + }); + return { today, earlier }; +}; export async function getNotifications(notificationType, notificationCount) { + const notificationData = [ + { + type: 'post', + respondingUser: 'SCM_Lead', + notificationContent: 'Hello and welcome to SC0x!', + targetUser: '', + courseName: 'Supply Chain Analytics', + URL: '', + status: 'unread', + time: '1684996319038', + }, + { + type: 'post', + respondingUser: 'SCM_Lead', + notificationContent: 'Hello and welcome to SC0x!', + targetUser: '', + courseName: 'Supply Chain Analytics', + URL: '', + status: 'unread', + time: '1684996319038', + }, + { + type: 'post', + respondingUser: 'SCM_Lead', + notificationContent: 'Hello and welcome to SC0x!', + targetUser: '', + courseName: 'Supply Chain Analytics', + URL: '', + status: 'unread', + time: '1684996319038', + }, + { + type: 'help', + respondingUser: 'MITx_Learner', + notificationContent: 'What grade does a student need to get in order to pass the course and earn a certificate?', + targetUser: '', + courseName: 'Supply Chain Analytics', + URL: '', + status: 'unread', + time: '1684996339844', + }, + { + type: 'post', + respondingUser: 'SCM_Lead', + notificationContent: 'Hello and welcome to SC0x!', + targetUser: '', + courseName: 'Supply Chain Analytics', + URL: '', + status: 'unread', + time: '1684253634808', + author: '', + }, + { + type: 'help', + respondingUser: 'MITx_Learner', + notificationContent: 'What grade does a student need to get in order to pass the course and earn a certificate?', + targetUser: '', + courseName: 'Supply Chain Analytics', + URL: '', + status: 'unread', + time: '1684253736371', + author: '', + }, + { + type: 'respond', + respondingUser: 'MITx_Learner', + notificationContent: 'Can’t find linear regression in section 3 review', + targetUser: '', + courseName: 'Supply Chain Analytics', + URL: '', + status: 'unread', + time: '1684253736371', + author: '', + }, + { + type: 'comment', + respondingUser: 'MITx_Learner', + notificationContent: 'Can’t find linear regression in section 3 review', + targetUser: 'MITx_Expert’s ', + courseName: 'Supply Chain Analytics', + URL: '', + status: 'unread', + time: '1684253736371', + author: '', + }, + { + type: 'question', + respondingUser: 'MITx_Learner', + notificationContent: 'Examples of quadratic equations in supply chains', + targetUser: '', + courseName: 'Supply Chain Analytics', + URL: '', + status: 'unread', + time: '1684253736371', + author: '', + }, + { + type: 'comment', + respondingUser: 'MITx_Learner', + notificationContent: 'What grade does a student need to get in order to pass the course and earn a certificate?', + targetUser: 'MITx_Expert’s ', + courseName: 'Supply Chain Analytics', + URL: '', + status: 'unread', + time: '1684253736371', + author: 'testuser', + }, + { + type: 'comment', + respondingUser: 'MITx_Learner', + notificationContent: 'Convexity of f(x)=1/x , x>1', + targetUser: '', + courseName: 'Supply Chain Analytics', + URL: '', + status: 'unread', + time: '1684253736371', + author: 'testuser', + }, + ]; + + const { today, earlier } = parseNotificationList(notificationData); + const data = { discussions: { - TODAY: [ - { - type: 'post', - respondingUser: 'SCM_Lead', - notificationContent: 'Hello and welcome to SC0x!', - targetUser: '', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '15m', - }, - { - type: 'help', - respondingUser: 'MITx_Learner', - notificationContent: 'What grade does a student need to get in order to pass the course and earn a certificate?', - targetUser: '', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '15m', - }, - ], + TODAY: today, + EARLIER: earlier, }, reminders: { - TODAY: [ - { - type: 'post', - respondingUser: 'SCM_Lead', - notificationContent: 'Hello and welcome to SC0x!', - targetUser: '', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '1684253634808', - author: '', - }, - { - type: 'help', - respondingUser: 'MITx_Learner', - notificationContent: 'What grade does a student need to get in order to pass the course and earn a certificate?', - targetUser: '', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '1684253736371', - author: '', - }, - { - type: 'respond', - respondingUser: 'MITx_Learner', - notificationContent: 'Can’t find linear regression in section 3 review', - targetUser: '', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '1684253736371', - author: '', - }, - { - type: 'comment', - respondingUser: 'MITx_Learner', - notificationContent: 'Can’t find linear regression in section 3 review', - targetUser: 'MITx_Expert’s ', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '1684253736371', - author: '', - }, - { - type: 'question', - respondingUser: 'MITx_Learner', - notificationContent: 'Examples of quadratic equations in supply chains', - targetUser: '', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '1684253736371', - author: '', - }, - { - type: 'comment', - respondingUser: 'MITx_Learner', - notificationContent: 'What grade does a student need to get in order to pass the course and earn a certificate?', - targetUser: 'MITx_Expert’s ', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '1684253736371', - author: 'testuser', - }, - { - type: 'comment', - respondingUser: 'MITx_Learner', - notificationContent: 'Convexity of f(x)=1/x , x>1', - targetUser: '', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '1684253736371', - author: 'testuser', - }, - ], - EARLIER: [ - { - type: 'answer', - respondingUser: 'SCM_Lead', - notificationContent: 'Quiz in section 3 - Please explain the F-Significance value', - targetUser: '', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '15m', - author: 'testuser', - }, - { - type: 'endorsed', - respondingUser: '', - notificationContent: 'Quiz in section 3 - Please explain the F-Significance value', - targetUser: '', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '15m', - author: 'testuser', - }, - { - type: 'reported', - respondingUser: 'MITx Learner’s', - notificationContent: '“Here are the exam answers. Question 1 - CSA stands for Compliance Safety Ac...”', - targetUser: '', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '15m', - author: '', - }, - { - type: 'postLiked', - respondingUser: 'SCM_Lead', - notificationContent: 'Retaking the course', - targetUser: '', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '15m', - author: '', - }, - { - type: 'commentLiked', - respondingUser: 'MITx_Expert ', - notificationContent: 'Final exam answers', - targetUser: '', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '15m', - author: '', - }, - { - type: 'edited', - respondingUser: 'MITx_Expert ', - notificationContent: 'Question 1', - targetUser: '', - courseName: 'Supply Chain Analytics', - URL: '', - status: 'unread', - time: '15m', - author: '', - }, - ], + TODAY: today, + EARLIER: earlier, }, }; const notifications = data[notificationType]; diff --git a/src/Notifications/data/selectors.js b/src/Notifications/data/selectors.js index b0bb9d4..d62a52b 100644 --- a/src/Notifications/data/selectors.js +++ b/src/Notifications/data/selectors.js @@ -1,3 +1,4 @@ export const getNotificationStatus = () => state => state.notifications.notificationStatus; export const getNotificationTotalUnseenCounts = () => state => state.notifications.totalUnseenCounts; export const getNotifications = () => state => state.notifications.notifications; +export const getSelectedNotificationType = () => state => state.notifications.notificationType; diff --git a/src/__snapshots__/Header.test.jsx.snap b/src/__snapshots__/Header.test.jsx.snap index e19fabe..3768354 100644 --- a/src/__snapshots__/Header.test.jsx.snap +++ b/src/__snapshots__/Header.test.jsx.snap @@ -238,7 +238,7 @@ exports[`
renders correctly for authenticated desktop 1`] = ` className="nav secondary-menu-container align-items-center ml-auto" >