130 lines
4.1 KiB
TypeScript
130 lines
4.1 KiB
TypeScript
"use client";
|
|
|
|
import { useRouter } from "next/navigation";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Menu, X, ZoomIn, ZoomOut, LogOut } from "lucide-react";
|
|
import Image from "next/image";
|
|
import { topMenus } from "@/config/menu.data";
|
|
import {useAuth} from "@/hooks/useAuth";
|
|
import type {LoginUser} from "@/types/auth";
|
|
import {useEffect, useState} from "react";
|
|
|
|
interface HeaderProps {
|
|
isMain: boolean;
|
|
menuOpen: boolean;
|
|
activeTopId: string;
|
|
fontSize: number;
|
|
onToggleMenu: () => void;
|
|
onNavigate: (path: string) => void;
|
|
decreaseFontSize: () => void;
|
|
increaseFontSize: () => void;
|
|
}
|
|
|
|
export const Header = ({
|
|
isMain,
|
|
menuOpen,
|
|
activeTopId,
|
|
fontSize,
|
|
onToggleMenu,
|
|
onNavigate,
|
|
decreaseFontSize,
|
|
increaseFontSize,
|
|
}: HeaderProps) => {
|
|
const router = useRouter();
|
|
const { auth } = useAuth();
|
|
const [userInfo, setUserInfo] = useState<LoginUser|undefined>(undefined);
|
|
|
|
useEffect(() => {
|
|
if(auth.user){
|
|
setUserInfo(auth.user);
|
|
}
|
|
else{
|
|
router.replace("/logout");
|
|
}
|
|
}, [auth.user])
|
|
|
|
return (
|
|
<header className="bg-white border-b border-gray-200 sticky top-0 z-40">
|
|
<div className="flex items-center justify-between px-4 h-16">
|
|
<div className="flex items-center gap-4">
|
|
{/* 햄버거 메뉴 */}
|
|
<div className="w-5">
|
|
{isMain? null :
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
onClick={() => onToggleMenu()}
|
|
>
|
|
{menuOpen ? <X className="w-5 h-5" /> : <Menu className="w-5 h-5" />}
|
|
</Button>
|
|
}
|
|
</div>
|
|
{/* 로고 */}
|
|
<div
|
|
className="flex items-center gap-2 cursor-pointer"
|
|
onClick={() => onNavigate("/")}
|
|
>
|
|
<div className="w-20 h-10 flex items-center justify-center">
|
|
<Image
|
|
src="/kri_logo.png"
|
|
alt="KRI 로고"
|
|
width={120}
|
|
height={40}
|
|
className="object-contain"
|
|
priority
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{/* 상단 메뉴 */}
|
|
<nav className="flex items-center gap-1 ml-25">
|
|
{topMenus.map((m) => (
|
|
<Button
|
|
key={m.id}
|
|
variant={activeTopId === m.id ? "default" : "ghost"}
|
|
onClick={() => onNavigate(m.path)}
|
|
>
|
|
{m.label}
|
|
</Button>
|
|
))}
|
|
</nav>
|
|
</div>
|
|
|
|
{/* 우측 컨트롤 */}
|
|
<div className="flex items-center gap-4">
|
|
<div className="flex items-center gap-1 border-r pr-4">
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
onClick={() => decreaseFontSize()}
|
|
title="폰트 작게"
|
|
>
|
|
<ZoomOut className="w-4 h-4" />
|
|
</Button>
|
|
<span className="text-xs text-gray-500 min-w-[3rem] text-center">
|
|
{fontSize}px
|
|
</span>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
onClick={() => increaseFontSize()}
|
|
title="폰트 크게"
|
|
>
|
|
<ZoomIn className="w-4 h-4" />
|
|
</Button>
|
|
</div>
|
|
<span className="text-sm text-gray-600 hidden sm:inline">{userInfo?.userName || ""}</span>
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
className="gap-2"
|
|
onClick={() => onNavigate("/logout")}
|
|
>
|
|
<LogOut className="w-4 h-4" />
|
|
<span className="hidden sm:inline">로그아웃</span>
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
);
|
|
}; |