|
| 1 | +'use client'; |
| 2 | +import React, { ReactNode } from 'react'; |
| 3 | +import type { AppProps } from 'next/app'; |
| 4 | +import { ChakraProvider, Box, Portal, useDisclosure } from '@chakra-ui/react'; |
| 5 | +import theme from '@/theme/theme'; |
| 6 | +import routes from '@/routes'; |
| 7 | +import Sidebar from '@/components/sidebar/Sidebar'; |
| 8 | +import Footer from '@/components/footer/FooterAdmin'; |
| 9 | +import Navbar from '@/components/navbar/NavbarAdmin'; |
| 10 | +import { getActiveRoute, getActiveNavbar } from '@/utils/navigation'; |
| 11 | +import { usePathname } from 'next/navigation'; |
| 12 | +import { useEffect, useState } from 'react'; |
| 13 | +import '@/styles/App.css'; |
| 14 | +import '@/styles/Contact.css'; |
| 15 | +import '@/styles/Plugins.css'; |
| 16 | +import '@/styles/MiniCalendar.css'; |
| 17 | +import AppWrappers from './AppWrappers'; |
| 18 | + |
| 19 | +export default function RootLayout({ children }: { children: ReactNode }) { |
| 20 | + const pathname = usePathname(); |
| 21 | + const [apiKey, setApiKey] = useState(''); |
| 22 | + const { isOpen, onOpen, onClose } = useDisclosure(); |
| 23 | + useEffect(() => { |
| 24 | + const initialKey = localStorage.getItem('apiKey'); |
| 25 | + console.log(initialKey); |
| 26 | + if (initialKey?.includes('sk-') && apiKey !== initialKey) { |
| 27 | + setApiKey(initialKey); |
| 28 | + } |
| 29 | + }, [apiKey]); |
| 30 | + |
| 31 | + return ( |
| 32 | + <html lang="en"> |
| 33 | + <body id={'root'}> |
| 34 | + <AppWrappers> |
| 35 | + {/* <ChakraProvider theme={theme}> */} |
| 36 | + {pathname?.includes('register') || pathname?.includes('sign-in') ? ( |
| 37 | + children |
| 38 | + ) : ( |
| 39 | + <Box> |
| 40 | + <Sidebar setApiKey={setApiKey} routes={routes} /> |
| 41 | + <Box |
| 42 | + pt={{ base: '60px', md: '100px' }} |
| 43 | + float="right" |
| 44 | + minHeight="100vh" |
| 45 | + height="100%" |
| 46 | + overflow="auto" |
| 47 | + position="relative" |
| 48 | + maxHeight="100%" |
| 49 | + w={{ base: '100%', xl: 'calc( 100% - 290px )' }} |
| 50 | + maxWidth={{ base: '100%', xl: 'calc( 100% - 290px )' }} |
| 51 | + transition="all 0.33s cubic-bezier(0.685, 0.0473, 0.346, 1)" |
| 52 | + transitionDuration=".2s, .2s, .35s" |
| 53 | + transitionProperty="top, bottom, width" |
| 54 | + transitionTimingFunction="linear, linear, ease" |
| 55 | + > |
| 56 | + <Portal> |
| 57 | + <Box> |
| 58 | + <Navbar |
| 59 | + setApiKey={setApiKey} |
| 60 | + onOpen={onOpen} |
| 61 | + logoText={'Horizon UI Dashboard PRO'} |
| 62 | + brandText={getActiveRoute(routes, pathname)} |
| 63 | + secondary={getActiveNavbar(routes, pathname)} |
| 64 | + /> |
| 65 | + </Box> |
| 66 | + </Portal> |
| 67 | + <Box |
| 68 | + mx="auto" |
| 69 | + p={{ base: '20px', md: '30px' }} |
| 70 | + pe="20px" |
| 71 | + minH="100vh" |
| 72 | + pt="50px" |
| 73 | + > |
| 74 | + {children} |
| 75 | + {/* <Component apiKeyApp={apiKey} {...pageProps} /> */} |
| 76 | + </Box> |
| 77 | + <Box> |
| 78 | + <Footer /> |
| 79 | + </Box> |
| 80 | + </Box> |
| 81 | + </Box> |
| 82 | + )} |
| 83 | + {/* </ChakraProvider> */} |
| 84 | + </AppWrappers> |
| 85 | + </body> |
| 86 | + </html> |
| 87 | + ); |
| 88 | +} |
0 commit comments