-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Web-App] Add novu notifications to navbar (#1015)
* connect novu notifications to UI * fix comments * fix naming * remove redundant props * add user interactions logic to novu notification and overlay * fix build issues
- Loading branch information
Showing
15 changed files
with
495 additions
and
38 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
38 changes: 38 additions & 0 deletions
38
packages/web-app/src/modules/home-views/components/NavigationBarWithNotifications.tsx
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,38 @@ | ||
import { useNotifications } from '@novu/notification-center' | ||
import { NavigationBar, type NavigationBarProps } from '@saladtechnologies/garden-components' | ||
import type { FunctionComponent } from 'react' | ||
import { getConfiguredNovuBannerNotifications } from '../../notifications/utils' | ||
|
||
export const NavigationBarWithNotifications: FunctionComponent<NavigationBarProps> = (props) => { | ||
const { | ||
notifications: novuNotifications, | ||
unseenCount, | ||
markNotificationAsRead, | ||
markAllNotificationsAsSeen, | ||
} = useNotifications() | ||
|
||
const unreadNovuNotifications = novuNotifications?.filter((notification) => !notification.read) | ||
const bannerNotifications = getConfiguredNovuBannerNotifications(unreadNovuNotifications, (notificationId: string) => | ||
markNotificationAsRead(notificationId), | ||
) | ||
const newsNotifications = bannerNotifications.filter((notification) => notification?.variant === 'news') | ||
const warningsNotifications = bannerNotifications.filter((notification) => notification?.variant === 'error') | ||
const hasUnseenNotifications = unseenCount > 0 | ||
const handleOpenNotificationsDrawer = () => { | ||
props.notifications.onOpenNotificationsDrawer() | ||
|
||
if (hasUnseenNotifications) { | ||
markAllNotificationsAsSeen() | ||
} | ||
} | ||
|
||
const notifications = { | ||
...props.notifications, | ||
news: newsNotifications, | ||
warnings: warningsNotifications, | ||
hasUnseenNotifications, | ||
onOpenNotificationsDrawer: handleOpenNotificationsDrawer, | ||
} | ||
|
||
return <NavigationBar {...props} notifications={notifications} /> | ||
} |
2 changes: 1 addition & 1 deletion
2
.../components/NotificationToast.stories.tsx → ...cationToast/NotificationToast.stories.tsx
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
1 change: 1 addition & 0 deletions
1
packages/web-app/src/modules/notifications-views/components/NotificationToast/index.tsx
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 @@ | ||
export * from './NotificationToast' |
53 changes: 53 additions & 0 deletions
53
.../modules/notifications-views/components/NovuNotificationBanner/NovuNotificationBanner.tsx
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,53 @@ | ||
import { useNotifications } from '@novu/notification-center' | ||
import { NotificationBanner } from '@saladtechnologies/garden-components' | ||
import type { FC } from 'react' | ||
import { useEffect, useState } from 'react' | ||
import type { WithStyles } from 'react-jss' | ||
import withStyles from 'react-jss' | ||
import { getConfiguredNovuBannerNotifications } from '../../../notifications/utils' | ||
|
||
const styles = () => ({ | ||
container: { | ||
width: 560, | ||
position: 'fixed', | ||
zIndex: 99, | ||
top: 85, | ||
left: 0, | ||
right: 0, | ||
margin: 'auto', | ||
}, | ||
}) | ||
|
||
interface NovuNotificationBannerRawProps extends WithStyles<typeof styles> {} | ||
|
||
export const NovuNotificationBannerRaw: FC<NovuNotificationBannerRawProps> = ({ classes }) => { | ||
const { notifications, markNotificationAsRead } = useNotifications() | ||
const [isHidden, setisHidden] = useState(false) | ||
|
||
const unreadNovuNotifications = notifications?.filter((notification) => !notification.read) | ||
const bannerNotifications = getConfiguredNovuBannerNotifications( | ||
unreadNovuNotifications, | ||
(notificationId: string) => { | ||
markNotificationAsRead(notificationId) | ||
setisHidden(true) | ||
}, | ||
) | ||
const overlayNovuNotifications = bannerNotifications?.filter((notification) => notification.overlay) | ||
const lastOverlayNovuNotification = overlayNovuNotifications[0] | ||
|
||
useEffect(() => { | ||
setisHidden(false) | ||
}, [notifications, setisHidden]) | ||
|
||
if (!lastOverlayNovuNotification || isHidden) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div className={classes.container}> | ||
<NotificationBanner {...lastOverlayNovuNotification} /> | ||
</div> | ||
) | ||
} | ||
|
||
export const NovuNotificationBanner = withStyles(styles)(NovuNotificationBannerRaw) |
1 change: 1 addition & 0 deletions
1
packages/web-app/src/modules/notifications-views/components/NovuNotificationBanner/index.tsx
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 @@ | ||
export * from './NovuNotificationBanner' |
2 changes: 2 additions & 0 deletions
2
packages/web-app/src/modules/notifications-views/components/index.tsx
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,2 @@ | ||
export * from './NotificationToast' | ||
export * from './NovuNotificationBanner' |
16 changes: 15 additions & 1 deletion
16
packages/web-app/src/modules/notifications/NotificationStore.tsx
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
Oops, something went wrong.