63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
"use client";
|
|
|
|
import {ReactNode, useEffect, useState} from "react";
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import { Header } from "@/components/layout/Header";
|
|
import {TOP_MENUS} from "@/config/menu.data";
|
|
import {useAuth} from "@/hooks/useAuth";
|
|
import type {LoginUser} from "@/types/auth";
|
|
import {useMounted} from "@/hooks/useMounted";
|
|
type MainLayoutProps = {
|
|
children: ReactNode;
|
|
};
|
|
|
|
const MainLayout = ({ children }: MainLayoutProps) => {
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
const activeTop = TOP_MENUS.find((m) => m.match?.(pathname)) ?? TOP_MENUS[0];
|
|
const { auth, isMonitoring } = useAuth();
|
|
const mounted = useMounted();
|
|
|
|
const [userInfo, setUserInfo] = useState<LoginUser|undefined>(undefined);
|
|
|
|
useEffect(() => {
|
|
if (!mounted) return;
|
|
|
|
if(auth.user){
|
|
setUserInfo(auth.user);
|
|
}
|
|
else{
|
|
router.replace("/logout");
|
|
}
|
|
}, [auth.user, mounted, router])
|
|
|
|
const movePage = (path: string) => {
|
|
router.push(path);
|
|
};
|
|
|
|
return (
|
|
<div
|
|
className="bg-gray-50 flex flex-col min-h-screen"
|
|
>
|
|
{/* 헤더 - 고정 높이 */}
|
|
<Header
|
|
isMonitoring={mounted ? isMonitoring : false}
|
|
userInfo={userInfo}
|
|
activeTopId={activeTop.id}
|
|
onNavigate={movePage}
|
|
/>
|
|
|
|
{/* 본문 */}
|
|
<div className="flex flex-1 min-h-0">
|
|
{/* 메인 콘텐츠만 가변 높이 적용 */}
|
|
<main className="flex-1 p-4">
|
|
{children}
|
|
</main>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default MainLayout;
|
|
|