Skip to content

Commit 17bc875

Browse files
authored
feat: add the notifications drop down (#1999)
1 parent bcfa0f8 commit 17bc875

File tree

11 files changed

+166
-17
lines changed

11 files changed

+166
-17
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import '../../../../../packages/core/src/ui/styles/theme.scss';
2+
@import '../../../../../packages/common/src/ui/styles/theme.scss';
3+
4+
.icon {
5+
width: size_unit(14);
6+
height: size_unit(14);
7+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import { useTranslation } from 'react-i18next';
3+
4+
import { Flex, Text } from '@input-output-hk/lace-ui-toolkit';
5+
6+
import styles from './NotificationsAllClear.module.scss';
7+
8+
import HappyFaceIcon from '@lace/core/src/ui/assets/icons/happy-face.component.svg';
9+
10+
export const NotificationsAllClear = (): React.ReactElement => {
11+
const { t } = useTranslation();
12+
13+
return (
14+
<Flex flexDirection="column" alignItems="center" justifyContent="center" gap="$8">
15+
<HappyFaceIcon className={styles.icon} />
16+
<Text.Body.Large>{t('notificationsCenter.allClear.title')}</Text.Body.Large>
17+
<Text.Body.Small>{t('notificationsCenter.allClear.description')}</Text.Body.Small>
18+
</Flex>
19+
);
20+
};
File renamed without changes.
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import React from 'react';
2+
23
import { Button } from '@lace/common';
3-
import styles from './NotificationsCenter.module.scss';
4-
import NotificationBellIcon from '../../assets/icons/notifications-bell.component.svg';
4+
5+
import styles from './NotificationsBell.module.scss';
6+
7+
import NotificationBellIcon from '@lace/core/src/ui/assets/icons/notifications-bell.component.svg';
58

69
// eslint-disable-next-line no-magic-numbers
710
const formatNotificationCount = (count: number) => (count < 10 ? count.toString() : '9+');
811

912
export interface NotificationsBellProps {
10-
notificationsCount: number;
1113
onClick: () => void;
12-
popupView?: boolean;
14+
unreadNotifications: number;
1315
}
1416

15-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
16-
export const NotificationsBell = ({ notificationsCount, onClick }: NotificationsBellProps): React.ReactElement => (
17-
<Button className={styles.btn} block onClick={onClick} color="gradient" data-testid="notifications-bell">
17+
export const NotificationsBell = ({ onClick, unreadNotifications }: NotificationsBellProps): React.ReactElement => (
18+
<Button className={styles.btn} block color="gradient" data-testid="notifications-bell" onClick={onClick}>
1819
<NotificationBellIcon />
19-
{notificationsCount > 0 && <span className={styles.badge}>{formatNotificationCount(notificationsCount)}</span>}
20+
{unreadNotifications > 0 && <span className={styles.badge}>{formatNotificationCount(unreadNotifications)}</span>}
2021
</Button>
2122
);
Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,63 @@
11
import React, { useState } from 'react';
2-
import { NotificationsBell } from './NotificationsBell';
2+
import { Dropdown } from 'antd';
3+
34
import { usePostHogClientContext } from '@providers/PostHogClientProvider';
45
import { ExperimentName } from '@lib/scripts/types/feature-flags';
6+
7+
import { NotificationsBell } from './NotificationsBell';
8+
import { NotificationsDropDown } from './NotificationsDropDown';
9+
510
export interface NotificationsCenterContainerProps {
611
popupView?: boolean;
712
}
813

9-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1014
export const NotificationsBellContainer = ({ popupView }: NotificationsCenterContainerProps): React.ReactElement => {
1115
const posthog = usePostHogClientContext();
1216

13-
// TODO Connect with notifications center
14-
const [notificationsCount, setNotificationsCount] = useState(0);
17+
const [isOpen, setIsOpen] = useState(false);
1518

1619
// TODO Connect with notifications center
17-
const handleClick = () => {
18-
// eslint-disable-next-line no-magic-numbers
19-
setNotificationsCount(notificationsCount === 11 ? 0 : notificationsCount + 1);
20+
const [notifications, setNotifications] = useState<string[]>([]);
21+
22+
const handleOpenChange = (open: boolean) => {
23+
setIsOpen(open);
24+
25+
// TODO remove this placeholder logic
26+
if (!open) {
27+
setNotifications(
28+
// eslint-disable-next-line no-magic-numbers
29+
notifications.length === 11 ? [] : [...notifications, `Notification ${notifications.length + 1}`]
30+
);
31+
}
32+
};
33+
34+
const handleMarkAllAsRead = () => {
35+
// TODO remove this placeholder logic
36+
setNotifications([]);
37+
};
38+
39+
const handleViewAll = () => {
40+
setIsOpen(false);
2041
};
2142

2243
return (
2344
posthog?.isFeatureFlagEnabled(ExperimentName.NOTIFICATIONS_CENTER) && (
24-
<NotificationsBell notificationsCount={notificationsCount} onClick={handleClick} popupView={popupView} />
45+
<Dropdown
46+
onOpenChange={handleOpenChange}
47+
open={isOpen}
48+
dropdownRender={() => (
49+
<NotificationsDropDown
50+
notifications={notifications}
51+
onMarkAllAsRead={handleMarkAllAsRead}
52+
onViewAll={handleViewAll}
53+
popupView={popupView}
54+
/>
55+
)}
56+
placement="bottomRight"
57+
trigger={['click']}
58+
>
59+
<NotificationsBell onClick={() => setIsOpen(!isOpen)} unreadNotifications={notifications.length} />
60+
</Dropdown>
2561
)
2662
);
2763
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@import '../../../../../packages/core/src/ui/styles/theme.scss';
2+
@import '../../../../../packages/common/src/ui/styles/theme.scss';
3+
@import '../../../../../packages/common/src/ui/styles/abstracts/mixins';
4+
5+
.container {
6+
background-color: var(--bg-color-container, #ffffff) !important;
7+
border: 1px var(--light-mode-light-grey) solid !important;
8+
border-radius: size_unit(2) !important;
9+
box-shadow: 0 0 16px 0 rgba(167, 143, 160, 0.2);
10+
margin-top: size_unit(0.5) !important;
11+
max-height: 475px;
12+
padding: size_unit(1) !important;
13+
width: 310px;
14+
15+
&.popupView {
16+
left: size_unit(-4);
17+
}
18+
}
19+
20+
.content {
21+
min-height: 200px;
22+
max-height: 350px;
23+
overflow-y: scroll;
24+
@include scroll-bar-style;
25+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react';
2+
import classnames from 'classnames';
3+
import { useTranslation } from 'react-i18next';
4+
import { Menu } from 'antd';
5+
6+
import { Divider, Flex, Text } from '@input-output-hk/lace-ui-toolkit';
7+
8+
import { NotificationsAllClear } from './NotificationsAllClear';
9+
10+
import styles from './NotificationsDropDown.module.scss';
11+
12+
export interface NotificationsDropDownProps {
13+
notifications: string[];
14+
onMarkAllAsRead: () => void;
15+
onViewAll: () => void;
16+
popupView?: boolean;
17+
}
18+
19+
export const NotificationsDropDown = ({
20+
notifications,
21+
onMarkAllAsRead,
22+
onViewAll,
23+
popupView
24+
}: NotificationsDropDownProps): React.ReactElement => {
25+
const { t } = useTranslation();
26+
27+
return (
28+
<Menu className={classnames(styles.container, { [styles.popupView]: popupView })}>
29+
<div className={styles.content}>
30+
{notifications.length > 0 ? <div>Placeholder content</div> : <NotificationsAllClear />}
31+
</div>
32+
<Divider my="$4" />
33+
<Flex justifyContent="space-between">
34+
<Text.Body.Normal>
35+
<a onClick={onViewAll}>
36+
{t(`notificationsCenter.${notifications.length > 0 ? 'viewAll' : 'manageSubscriptions'}`)}
37+
</a>
38+
</Text.Body.Normal>
39+
{notifications.length > 0 && (
40+
<Text.Body.Normal>
41+
<a onClick={onMarkAllAsRead}>{t('notificationsCenter.markAllAsRead')}</a>
42+
</Text.Body.Normal>
43+
)}
44+
</Flex>
45+
</Menu>
46+
);
47+
};
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
export * from './NotificationsBell';
21
export * from './NotificationsBellContainer';
Lines changed: 9 additions & 0 deletions
Loading
File renamed without changes.

0 commit comments

Comments
 (0)