@@ -6,12 +6,13 @@ import SidebarSubmenu from './sidebar-submenu';
66import routes from '@/helper/sidebar-routes' ;
77import { usePathname } from 'next/navigation'
88import { useEffect } from 'react' ;
9- import { useAppDispatch } from '@/lib/hooks' ;
9+ import { useAppDispatch , useAppSelector } from '@/lib/hooks' ;
1010import { setPageTitle } from '@/features/common/headerSlice' ;
1111import { UserProfile } from '@/helper/types' ;
1212import BookmarkSquareIcon from '@heroicons/react/24/outline/BookmarkSquareIcon'
1313import ChevronUpIcon from '@heroicons/react/24/outline/ChevronUpIcon'
1414import ArrowUpOnSquareIcon from '@heroicons/react/24/outline/ArrowUpOnSquareIcon'
15+ import { getUserInfo } from '@/features/common/userSlice' ;
1516
1617interface LeftSidebarProps { }
1718
@@ -25,27 +26,42 @@ function LeftSidebar(props: LeftSidebarProps) {
2526 const leftSidebarDrawer = document . getElementById ( 'left-sidebar-drawer' ) ;
2627 if ( leftSidebarDrawer ) leftSidebarDrawer . click ( ) ;
2728 } ;
29+ const user = useAppSelector ( ( state ) => state . user ) ;
2830
29- const user : UserProfile = {
30- name : "Alex" ,
31- avatar : "https://reqres.in/img/faces/7-image.jpg" ,
32- emailId : ""
33- }
3431
3532 useEffect ( ( ) => {
3633 console . log ( pathname )
3734 let routeObj = routes . filter ( ( r ) => { return r . path == pathname } ) [ 0 ]
3835 if ( routeObj ) {
3936 dispatch ( setPageTitle ( { title : routeObj . pageTitle } ) )
37+ } else {
38+ const secondSlashIndex = pathname . indexOf ( '/' , pathname . indexOf ( '/' ) + 1 )
39+ if ( secondSlashIndex !== - 1 ) {
40+ const substringBeforeSecondSlash = pathname . substring ( 0 , secondSlashIndex ) ;
41+ let submenuRouteObj = routes . filter ( ( r ) => { return r . path == substringBeforeSecondSlash } ) [ 0 ]
42+ if ( submenuRouteObj . submenu ) {
43+ let submenuObj = submenuRouteObj . submenu . filter ( ( r ) => { return r . path == pathname } ) [ 0 ]
44+ console . log ( "herere" , submenuObj )
45+ dispatch ( setPageTitle ( { title : submenuObj . pageTitle } ) )
46+
47+ }
48+ }
4049 }
4150 } , [ pathname ] )
4251
52+
53+ useEffect ( ( ) => {
54+ dispatch ( getUserInfo ( ) )
55+ } , [ ] )
56+
4357 const logoutUser = async ( ) => {
4458 console . log ( "here" )
4559 localStorage . clear ( ) ;
4660 window . location . href = '/'
4761 }
4862
63+
64+
4965
5066 return (
5167 < div className = "drawer-side z-30 overflow-hidden" >
0 commit comments