Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 29x 88x 88x 88x 231x 237x 88x 88x 29x 29x 29x 29x 2x 88x 2x 86x 86x | 'use client'
import { notFound, usePathname, useSearchParams } from 'next/navigation'
import { useEffect } from 'react'
import isAuth from '../../../../components/Auth/isAuth'
import { ServerError } from '../../../../components/Errors/ServerError/ServerError'
import { Loading } from '../../../../components/Loading/Loading'
import { GlobalFooter } from '../../../../components/Navbar/GlobalFooter/GlobalFooter'
import { Navbar } from '../../../../components/Navbar/Navbar/Navbar'
import { NavbarLogo } from '../../../../components/Navbar/NavbarLogo/NavbarLogo'
import { MobileSidebar } from '../../../../components/Navbar/Sidebar/MobileSidebar/MobileSidebar'
import { Sidebar } from '../../../../components/Navbar/Sidebar/Sidebar'
import { useAppDispatch, useAppSelector } from '../../../../store/hooks'
import { fetchLastWillState, resetLastWill } from '../../../../store/lastwill/lastwill'
const Rootlayout = ({ children }: { children: React.ReactNode }) => {
const path = usePathname()
const searchParams = useSearchParams()
const id = searchParams.get('id')
const isInitialized = useAppSelector((state) => state.lastWill.isInitialized)
const error = useAppSelector((state) => state.lastWill.error)
const dispatch = useAppDispatch()
useEffect(() => {
const getLastWillState = async () => {
await dispatch(
fetchLastWillState({
lastWillId: id ? id : undefined,
}),
)
}
getLastWillState()
return () => {
dispatch(resetLastWill())
}
// This has to be empty to work because it will retrigger when dispatch is defined new
}, []) // eslint-disable-line
if (error === 'NOT_FOUND') {
return notFound()
}
Iif (error === 'ERROR') {
return <ServerError />
}
return (
<>
{!isInitialized ? (
<div className="container mt-5">
<Loading />
</div>
) : (
<div className={`flex h-screen min-h-screen w-full overflow-y-scroll sm:flex-col lg:flex-row`}>
<Sidebar path={path} />
<div className="flex h-fit min-h-screen flex-grow flex-col">
<Navbar background={false}>
<div className="mr-5 lg:hidden">
<NavbarLogo />
</div>
</Navbar>
<MobileSidebar path={path} />
{children}
<GlobalFooter />
</div>
</div>
)}
</>
)
}
export default isAuth(Rootlayout, 'protected')
|