260506_01_fst: First Commit

This commit is contained in:
2026-05-06 17:00:45 +09:00
parent dd5cac3d78
commit 934a71e47a
76 changed files with 9488 additions and 222 deletions

View File

@@ -0,0 +1,86 @@
"use client"
import {ReactNode, useEffect, useState} from "react";
import {useRouter} from "next/navigation";
import {DivKey} from "@/types/kfpa";
import {useAuth} from "@/hooks/useAuth";
import {LayoutCategoryProvider} from "./LayoutCategoryContext";
import Header from "@/components/layout/Header";
import {useMounted} from "@/hooks/useMounted";
import {Sidebar} from "@/components/layout/Sidebar";
import {TOP_MENUS, SIDE_MENUS} from "@/config/menu.data";
import {useLogoutMutation} from "@/query/auth";
import {useDialog} from "@/hooks/useDialog";
import LoginDialog from "@/components/dialog/loginDialog";
type MainLayoutProps = {
children: ReactNode;
};
const getDivKey = () => {
return "-1";
}
const MainLayout = ({ children }: MainLayoutProps) => {
const { auth, logout } = useAuth();
const { showDialog } = useDialog();
const logoutMutation = useLogoutMutation();
const router = useRouter();
const isMounted = useMounted();
const [menuOpen, setMenuOpen] = useState(true);
const [selectedDiv, setSelectedDiv] = useState<DivKey>(getDivKey());
const movePage = (path: string) => {
router.push(path);
};
const openLoginDialog = () => {
showDialog("loginDialog");
};
const handleLogout = () => {
logoutMutation.mutate();
};
useEffect(() => {
const handleAuthExpired = () => {
logout();
};
window.addEventListener("auth:expired", handleAuthExpired);
return () => window.removeEventListener("auth:expired", handleAuthExpired);
}, [logout]);
if(!isMounted) return null;
return (
<div className="h-screen flex flex-col bg-transparent overflow-hidden">
<LayoutCategoryProvider selectedDiv={selectedDiv}>
<Header
topMenus={TOP_MENUS}
userName={auth.user?.userName || ""}
isAuthenticated={auth.user != null}
onNavigate={movePage}
onLogin={openLoginDialog}
onLogout={handleLogout}
/>
<div className="flex flex-1">
<Sidebar
sideMenus={SIDE_MENUS}
isOpen={menuOpen}
selectedDiv={selectedDiv}
onChangeDiv={setSelectedDiv}
/>
<main className="flex-1 p-4">
{children}
</main>
</div>
<LoginDialog />
</LayoutCategoryProvider>
</div>
);
}
export default MainLayout;