260821_01_FST: First Commit
This commit is contained in:
78
src/components/app-shell/ActivePopupGate.tsx
Normal file
78
src/components/app-shell/ActivePopupGate.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { KriDialog } from "@/components/common/KriDialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useActivePopupsQuery } from "@/query/popup";
|
||||
import { CookieKeys } from "@/store/cookie/cookie-keys";
|
||||
import { cookieStore } from "@/store/cookie/client-cookie";
|
||||
import { isCenterRole } from "@/types/auth";
|
||||
|
||||
const readHiddenPopupIds = () => {
|
||||
const raw = cookieStore.get(CookieKeys.PopupHideToday);
|
||||
if (!raw) return [];
|
||||
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(raw);
|
||||
return Array.isArray(parsed) ? parsed.filter((value): value is number => typeof value === "number") : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const getEndOfToday = () => {
|
||||
const end = new Date();
|
||||
end.setHours(24, 0, 0, 0);
|
||||
return end;
|
||||
};
|
||||
|
||||
export function ActivePopupGate() {
|
||||
const { auth } = useAuth();
|
||||
// 활성 팝업 조회 API는 백엔드에서 Center 역할 전용이며, 관리자로 호출하면 403이 발생해
|
||||
// 공용 HTTP 클라이언트의 기본 403 처리(로그아웃)가 실행되어 로그인 화면으로 튕겨나간다.
|
||||
const activePopupsQuery = useActivePopupsQuery(isCenterRole(auth.user?.userRole));
|
||||
const [dismissedIds, setDismissedIds] = useState<number[]>([]);
|
||||
const [hiddenIds] = useState<number[]>(() => readHiddenPopupIds());
|
||||
const [hideTodayChecked, setHideTodayChecked] = useState(false);
|
||||
|
||||
const popups = activePopupsQuery.data ?? [];
|
||||
const current = popups.find((popup) => !dismissedIds.includes(popup.popupId) && !hiddenIds.includes(popup.popupId));
|
||||
|
||||
useEffect(() => {
|
||||
setHideTodayChecked(false);
|
||||
}, [current?.popupId]);
|
||||
|
||||
if (!current) return null;
|
||||
|
||||
const dismiss = () => setDismissedIds((ids) => [...ids, current.popupId]);
|
||||
|
||||
const hideToday = () => {
|
||||
const nextHiddenIds = [...new Set([...readHiddenPopupIds(), current.popupId])];
|
||||
cookieStore.set(CookieKeys.PopupHideToday, JSON.stringify(nextHiddenIds), { expires: getEndOfToday() });
|
||||
setHideTodayChecked(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<KriDialog
|
||||
open
|
||||
onOpenChange={(next) => !next && dismiss()}
|
||||
onInteractOutside={(event) => event.preventDefault()}
|
||||
title={current.title}
|
||||
contentClassName="max-w-lg"
|
||||
footerClassName="sm:justify-between"
|
||||
footer={
|
||||
<>
|
||||
<label className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<Checkbox checked={hideTodayChecked} onCheckedChange={(checked) => checked === true && hideToday()} />
|
||||
오늘 하루 보지 않기
|
||||
</label>
|
||||
<Button type="button" onClick={dismiss}>닫기</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div dangerouslySetInnerHTML={{ __html: current.contentHtml }} />
|
||||
</KriDialog>
|
||||
);
|
||||
}
|
||||
51
src/components/app-shell/AppHeader.tsx
Normal file
51
src/components/app-shell/AppHeader.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
"use client";
|
||||
|
||||
import Image from "next/image";
|
||||
import { LogOut } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { KriHeader } from "@/components/layout/KriHeader";
|
||||
import type { TopMenuItem } from "@/config/menu.type";
|
||||
import type { AuthUser } from "@/types/auth";
|
||||
|
||||
interface AppHeaderProps {
|
||||
menus: TopMenuItem[];
|
||||
menuOpen: boolean;
|
||||
showMenuButton: boolean;
|
||||
activeMenuId?: string;
|
||||
user?: AuthUser | null;
|
||||
onToggleMenu: () => void;
|
||||
onNavigate: (path: string) => void;
|
||||
}
|
||||
|
||||
export function AppHeader({ menus, menuOpen, showMenuButton, activeMenuId, user, onToggleMenu, onNavigate }: AppHeaderProps) {
|
||||
return (
|
||||
<KriHeader
|
||||
logo={<Image src="/logo.png" alt="로고" width={120} height={40} className="h-10 w-auto object-contain" priority />}
|
||||
menus={menus}
|
||||
activeMenuId={activeMenuId}
|
||||
menuOpen={menuOpen}
|
||||
showMenuButton={showMenuButton}
|
||||
onToggleMenu={onToggleMenu}
|
||||
onNavigate={onNavigate}
|
||||
/*
|
||||
center={
|
||||
<p
|
||||
className="absolute left-1/2 top-1/2 max-w-[32rem] -translate-x-1/2 -translate-y-1/2 truncate text-lg font-semibold text-primary md:text-lg"
|
||||
title="세종학당재단 2026년 한국어교육 수요 및 만족도 조사"
|
||||
>
|
||||
세종학당재단 2026년 한국어교육 수요 및 만족도 조사
|
||||
</p>
|
||||
}
|
||||
*/
|
||||
right={
|
||||
<>
|
||||
<span className="hidden text-sm text-muted-foreground sm:inline">{user?.userName ?? ""}</span>
|
||||
<Button variant="ghost" size="sm" className="gap-2" onClick={() => onNavigate("/logout")}>
|
||||
<LogOut className="size-4" />
|
||||
<span className="hidden sm:inline">로그아웃</span>
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
49
src/components/app-shell/AppMainLayout.tsx
Normal file
49
src/components/app-shell/AppMainLayout.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import { KriMainLayout } from "@/components/layout/KriMainLayout";
|
||||
import { ActivePopupGate } from "./ActivePopupGate";
|
||||
import { AppHeader } from "./AppHeader";
|
||||
import { AppSidebar } from "./AppSidebar";
|
||||
import { sideMenus } from "@/config/menu.data";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useVisibleTopMenus } from "@/hooks/useVisibleTopMenus";
|
||||
|
||||
export function AppMainLayout({ children }: { children: React.ReactNode }) {
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
const { auth } = useAuth();
|
||||
const topMenus = useVisibleTopMenus();
|
||||
const [menuOpen, setMenuOpen] = useState(true);
|
||||
|
||||
const activeMenuId = useMemo(
|
||||
() => topMenus.find((item) => item.path && (pathname === item.path || pathname.startsWith(`${item.path}/`)))?.id,
|
||||
[pathname, topMenus],
|
||||
);
|
||||
|
||||
const navigate = (path: string) => router.push(path);
|
||||
const hasSidebar = sideMenus.length > 0;
|
||||
|
||||
return (
|
||||
<KriMainLayout
|
||||
sidebarOpen={hasSidebar && menuOpen}
|
||||
onSidebarOpenChange={setMenuOpen}
|
||||
header={
|
||||
<AppHeader
|
||||
menus={topMenus}
|
||||
menuOpen={menuOpen}
|
||||
showMenuButton={hasSidebar}
|
||||
activeMenuId={activeMenuId}
|
||||
user={auth.user}
|
||||
onToggleMenu={() => setMenuOpen((current) => !current)}
|
||||
onNavigate={navigate}
|
||||
/>
|
||||
}
|
||||
sidebar={hasSidebar ? <AppSidebar items={sideMenus} isOpen={menuOpen} pathname={pathname} onNavigate={navigate} /> : undefined}
|
||||
>
|
||||
{children}
|
||||
<ActivePopupGate />
|
||||
</KriMainLayout>
|
||||
);
|
||||
}
|
||||
10
src/components/app-shell/AppPageTitle.tsx
Normal file
10
src/components/app-shell/AppPageTitle.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { KriPageTitle } from "@/components/layout/KriPageTitle";
|
||||
|
||||
export interface AppPageTitleProps {
|
||||
title: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export function AppPageTitle({ title, description }: AppPageTitleProps) {
|
||||
return <KriPageTitle title={title} description={description} />;
|
||||
}
|
||||
15
src/components/app-shell/AppSidebar.tsx
Normal file
15
src/components/app-shell/AppSidebar.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
"use client";
|
||||
|
||||
import { KriSidebar } from "@/components/layout/KriSidebar";
|
||||
import type { SideMenuItem } from "@/config/menu.type";
|
||||
|
||||
interface AppSidebarProps {
|
||||
items: SideMenuItem[];
|
||||
isOpen: boolean;
|
||||
pathname: string;
|
||||
onNavigate: (path: string) => void;
|
||||
}
|
||||
|
||||
export function AppSidebar({ items, isOpen, pathname, onNavigate }: AppSidebarProps) {
|
||||
return <KriSidebar items={items} isOpen={isOpen} pathname={pathname} onNavigate={onNavigate} />;
|
||||
}
|
||||
12
src/components/app-shell/LoadingOverlayAdapter.tsx
Normal file
12
src/components/app-shell/LoadingOverlayAdapter.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import { useAtomValue } from "jotai";
|
||||
import { KriLoadingOverlay, type KriLoadingOverlayProps } from "@/components/common/KriLoadingOverlay";
|
||||
import { loadingAtom } from "@/store/jotai/loading";
|
||||
|
||||
export type LoadingOverlayAdapterProps = Omit<KriLoadingOverlayProps, "open"> & { force?: boolean };
|
||||
|
||||
export function LoadingOverlayAdapter({ force = false, ...props }: LoadingOverlayAdapterProps) {
|
||||
const open = useAtomValue(loadingAtom);
|
||||
return <KriLoadingOverlay open={force || open} {...props} />;
|
||||
}
|
||||
5
src/components/app-shell/index.ts
Normal file
5
src/components/app-shell/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export { AppHeader } from "./AppHeader";
|
||||
export { AppMainLayout } from "./AppMainLayout";
|
||||
export { AppPageTitle } from "./AppPageTitle";
|
||||
export { AppSidebar } from "./AppSidebar";
|
||||
export { LoadingOverlayAdapter } from "./LoadingOverlayAdapter";
|
||||
Reference in New Issue
Block a user