@@ -5,6 +5,8 @@ import makeStyles from '@material-ui/core/styles/makeStyles';
55import Drawer from '@material-ui/core/Drawer' ;
66import Toolbar from '@material-ui/core/Toolbar' ;
77import Divider from '@material-ui/core/Divider' ;
8+ import Badge from '@material-ui/core/Badge' ;
9+ import NotificationsIcon from '@material-ui/icons/Notifications' ;
810import IconButton from '@material-ui/core/IconButton' ;
911import MenuIcon from '@material-ui/icons/Menu' ;
1012import SvgIcon from '@material-ui/core/SvgIcon' ;
@@ -19,6 +21,7 @@ import ConnectedLinks from './common/connected-links';
1921import Footer from './footer' ;
2022
2123import dynamic from 'next/dynamic' ;
24+ import NotificationPanel , { lastMessageId } from './notification-panel' ;
2225const DocSearch = dynamic ( import ( './docsearch' ) , {
2326 ssr : false
2427} ) ;
@@ -121,11 +124,18 @@ const Layout = ({ children }) => {
121124 const [ open , setOpen ] = useState ( router . pathname !== '/' ) ;
122125 const [ links , setLinks ] = useState ( { } ) ;
123126 const searchRef = useRef ( null ) ;
127+ const anchorRef = useRef ( null ) ;
128+ const [ openNotification , setOpenNotifiation ] = useState ( false ) ;
129+ const [ lastCheck , setLastCheck ] = useState ( '' ) ;
124130
125131 useEffect ( ( ) => {
126132 setLinks ( findConnectedLinks ( router . asPath , flatSchema ) || { } ) ;
127133 } , [ router . asPath ] ) ;
128134
135+ useEffect ( ( ) => {
136+ setLastCheck ( localStorage . getItem ( 'data-driven-forms-last-checked' ) || '' ) ;
137+ } , [ ] ) ;
138+
129139 const handleDrawerOpen = ( ) => {
130140 setOpen ( true ) ;
131141 setTimeout ( ( ) => searchRef . current . focus ( ) , 500 ) ;
@@ -135,6 +145,12 @@ const Layout = ({ children }) => {
135145 setOpen ( false ) ;
136146 }
137147
148+ const handleToggle = ( ) => {
149+ localStorage . setItem ( 'data-driven-forms-last-checked' , lastMessageId ) ;
150+ setLastCheck ( lastMessageId ) ;
151+ setOpenNotifiation ( ! openNotification ) ;
152+ } ;
153+
138154 return (
139155 < MenuContext . Provider value = { links } >
140156 < div className = { classes . root } >
@@ -172,6 +188,12 @@ const Layout = ({ children }) => {
172188 } ) }
173189 >
174190 < DocSearch />
191+ < IconButton aria-label = "show new notifications" onClick = { handleToggle } color = "inherit" ref = { anchorRef } className = { clsx ( classes . menuButton ) } >
192+ < Badge badgeContent = { lastMessageId - lastCheck } color = "secondary" >
193+ < NotificationsIcon className = { classes . menuIcons } />
194+ </ Badge >
195+ </ IconButton >
196+ < NotificationPanel isOpen = { openNotification } anchorRef = { anchorRef } onClose = { ( ) => setOpenNotifiation ( false ) } />
175197 < a href = "https://github.com/data-driven-forms/react-forms" rel = "noopener noreferrer" target = "_blank" >
176198 < IconButton color = "inherit" aria-label = "gh repository" edge = "start" className = { clsx ( classes . menuButton ) } >
177199 < SvgIcon >
@@ -180,7 +202,6 @@ const Layout = ({ children }) => {
180202 </ IconButton >
181203 </ a >
182204 </ div >
183-
184205 < main
185206 className = { clsx ( classes . content , {
186207 [ classes . contentShift ] : open ,
0 commit comments