"use client"; import Image from "next/image"; import Link from "next/link"; import { useState } from "react"; import { usePathname } from "next/navigation"; import type { LoginUser } from "@kri/common"; import { cn } from "@/lib/utils"; import { kartMenus } from "@/config/menu.data"; import type { KartMenuItem } from "@/config/menu.type"; import { ProjectSelector } from "@/components/project/ProjectSelector"; import { useProjectTitle } from "@/query/project"; import { useSelectedProject } from "@/hooks/useSelectedProject"; import { projectPagePath } from "@/lib/report-navigation"; import { useAuth } from "@/hooks/useAuth"; import { useMutation } from "@tanstack/react-query"; import { nextApi } from "@/lib/http-client"; import { apiError } from "@kri/common/http"; import { isExternalUser, isShareLink, REPORT_MEMBER_ROLE } from "@/types/share"; interface AppHeaderProps { user: LoginUser; } /** Legacy KART Header.js: fixed GNB (64px) + title bar (80px). */ export function AppHeader({ user }: AppHeaderProps) { const pathname = usePathname(); const { auth } = useAuth(); const external = isExternalUser(user); const { project } = useSelectedProject(); const title = useProjectTitle(project); const [mobileOpen, setMobileOpen] = useState(false); const menus = project && !(external && auth.external?.pageOnly) ? kartMenus.filter((menu) => !menu.visible || menu.visible(user)) : []; // "(code) name" like the project selector; the code alone until the project list provides the // name (useProjectTitle falls back to pkey). External links keep their link title. const projectTitle = !project ? "Project Overview TOP 6" : external || title === project.pkey ? title : "(" + project.pkey + ") " + title; const canCopyUrl = !!project && user.userRole < REPORT_MEMBER_ROLE; const copy = useMutation({ mutationFn: async (mode: "P" | "U") => { if (!project) return; const url = new URL(window.location.href); url.searchParams.delete("projectType"); url.searchParams.delete("pkey"); const link = await nextApi.post(`/share/${project.projectType}/${encodeURIComponent(project.pkey)}`, { realUrl: pathname + url.search + url.hash, mode, }); if (!isShareLink(link)) throw new Error("공유 링크 응답을 확인해 주세요."); await navigator.clipboard.writeText(link.url); }, onSuccess: () => window.alert("주소가 복사되었습니다."), onError: (error) => window.alert(apiError(error, { fallbackMessage: "주소를 복사하지 못했습니다." }).message), }); return (
{mobileOpen ? ( <>
); } function KartLogo() { return KART; } function GnbLink({ menu, active }: { menu: KartMenuItem; active: boolean }) { const content = ( <>