All files / app/(dynamic)/last-will/editor layout.tsx

88.23% Statements 15/17
83.33% Branches 5/6
100% Functions 4/4
86.66% Lines 13/15

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                        78x 85x 85x 85x 244x   85x   85x 27x         27x           27x 1x         85x   83x                                                  
'use client'
import { notFound, usePathname, useSearchParams } from 'next/navigation'
import { useEffect } from 'react'
import isAuth from '../../../../components/Auth/isAuth'
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 dispatch = useAppDispatch()
 
	useEffect(() => {
		Iif (!id) {
			console.warn("Can't fetch last will state because id is not defined")
			return
		}
 
		dispatch(
			fetchLastWillState({
				lastWillId: id,
			})
		)
 
		return () => {
			dispatch(resetLastWill())
		}
		// This has to be empty to work because it will retrigger when dispatch is defined new
	}, []) // eslint-disable-line
 
	if (!id) return notFound()
 
	return (
		<>
			{!isInitialized ? (
				// TODO: Add loading screen
				<p>Laden...</p>
			) : (
				<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')