Skip to content

Commit 3092142

Browse files
Added Notifications Popup
Challenge: 30114259 Submission: 348696
1 parent 6a943bf commit 3092142

File tree

13 files changed

+466
-211
lines changed

13 files changed

+466
-211
lines changed

dist/dev/index.js

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/prod/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/assets/images/icon-bell-grey.svg

Lines changed: 20 additions & 0 deletions
Loading

src/assets/images/icon-checkmark.svg

Lines changed: 12 additions & 0 deletions
Loading

src/components/LoginNav/index.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ const LoginNav = ({
1717
onMenuOpen,
1818
showNotification,
1919
profile,
20-
authURLs
20+
authURLs,
21+
markNotificationAsRead,
22+
markAllNotificationAsRead,
23+
markAllNotificationAsSeen
2124
}) => {
2225
const [openNotifications, setOpenNotifications] = useState()
2326
const [openAccountMenu, setOpenAccountMenu] = useState()
@@ -39,8 +42,7 @@ const LoginNav = ({
3942
if (showNotification) {
4043
return ([
4144
<NotificationButton
42-
className={styles.notificationButton}
43-
state={notificationButtonState}
45+
notifications={notifications || []}
4446
notificationsPopupOpen={openNotifications}
4547
onClick={handleClickNotifications}
4648
key='notification-button'
@@ -83,7 +85,12 @@ const LoginNav = ({
8385
<NotificationsPopup
8486
open={openNotifications}
8587
notifications={notifications}
86-
onClose={() => setOpenNotifications(false)}
88+
onClose={() => {
89+
setOpenNotifications(false)
90+
markAllNotificationAsSeen()
91+
}}
92+
markNotificationAsRead={markNotificationAsRead}
93+
markAllNotificationAsRead={markAllNotificationAsRead}
8794
/>
8895
<AccountMenu
8996
profile={profile}
@@ -112,7 +119,10 @@ LoginNav.propTypes = {
112119
showNotification: PropTypes.bool,
113120
profile: PropTypes.shape(),
114121
switchText: PropTypes.shape(),
115-
authURLs: PropTypes.shape()
122+
authURLs: PropTypes.shape(),
123+
markNotificationAsRead: PropTypes.func.isRequired,
124+
markAllNotificationAsRead: PropTypes.func.isRequired,
125+
markAllNotificationAsSeen: PropTypes.func.isRequired
116126
}
117127

118128
export default LoginNav
Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
33
import cn from 'classnames'
4+
import IconBellEmpty from '../../assets/images/icon-bell-grey.svg'
45
import IconBell from '../../assets/images/icon-bell.svg'
56
import styles from './styles.module.scss'
7+
import _ from 'lodash'
68

7-
const NotificationButton = ({ className, state, onClick, notificationsPopupOpen }) => (
9+
const getNotificationButtonState = (notifications) => {
10+
console.log('got')
11+
console.log(_.countBy(notifications || [], n => !n.seen))
12+
if (notifications && _.countBy(notifications || [], n => !n.isSeen).true > 0) {
13+
console.log('returing : new')
14+
15+
return 'new'
16+
}
17+
if (notifications.length === 0) {
18+
console.log('returing : none')
19+
20+
return 'none'
21+
} else {
22+
console.log('returing : seen')
23+
24+
return 'seen'
25+
}
26+
}
27+
28+
const NotificationButton = ({ onClick, notificationsPopupOpen, notifications }) => (
829
<div
9-
className={cn(styles.notificationButton, styles[state], notificationsPopupOpen && styles.isNotificationsPopupOpen, className)}
30+
className={cn([styles.notificationButton,
31+
notificationsPopupOpen && styles.isNotificationsPopupOpen,
32+
styles[getNotificationButtonState(notifications)]])}
1033
onClick={onClick}
1134
>
12-
<IconBell />
35+
{(!_.isEmpty(notifications || []) ? <IconBell /> : <IconBellEmpty />)}
1336
</div>
1437
)
1538

1639
NotificationButton.propTypes = {
17-
className: PropTypes.string,
18-
state: PropTypes.oneOf(['none', 'new', 'seen']),
1940
onClick: PropTypes.func,
20-
notificationsPopupOpen: PropTypes.bool
41+
notificationsPopupOpen: PropTypes.bool,
42+
notifications: PropTypes.array
2143
}
2244

2345
export default NotificationButton

src/components/NotificationButton/styles.module.scss

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
.notificationButton {
44
position: relative;
5-
padding: 10px;
5+
width: 30px;
6+
height: 30px;
7+
padding-top: 3px;
8+
padding-left: 7px;
69

710
img {
811
display: block;
@@ -13,12 +16,9 @@
1316
}
1417

1518
&.new {
16-
line-height: 36px;
17-
18-
&:hover {
19-
background-color: $gray-hover-profile-icon;
20-
border-radius: 50%;
21-
}
19+
padding: 5px;
20+
width: 36px;
21+
height: 36px;
2222
}
2323

2424
&.new::after {
@@ -33,7 +33,8 @@
3333
display: block;
3434
}
3535

36-
&.new.isNotificationsPopupOpen {
36+
&:hover, &.isNotificationsPopupOpen
37+
{
3738
background-color: $gray-hover-profile-icon;
3839
border-radius: 50%;
3940
}

src/components/NotificationsPopup/EmptyNotifications.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const EmptyNotifications = ({ onClose, emptyTitle, emptyText }) => (
2323
<div className={cn(styles.txt, styles['center-txt'])}>{emptyText}</div>
2424
</div>
2525
<div className={styles['noti-footer']}>
26-
<span className={cn(styles.btn, styles['btn-blue'])} role='button'>
26+
<span className={cn(styles['btn-empty-noti'])} role='button'>
2727
Notification Settings
2828
</span>
2929
</div>

0 commit comments

Comments
 (0)