import {Outlet, useNavigate, useLocation} from 'react-router'; import Layout from './Layout'; import {PageType} from '@/types'; import {useAuth} from '@/features/auth/useAuth'; import {showToast} from '@/lib/notify'; const PAGE_TO_PATH: Record = { DASHBOARD: '/dashboard', STATISTICS: '/statistics', LEARNING: '/learning', PRODUCTS: '/products', PARTNERS: '/partners', QUOTATION: '/quotation', CARDS: '/cards', RENEGOTIATION: '/renegotiation', MEMBERS: '/members', DEV_SETTINGS: '/dev/settings', // /settings 보다 먼저 — startsWith 매칭이라 순서가 곧 우선순위 SETTINGS: '/settings', DESIGN: '/dev/design', NOTIFICATIONS: '/notifications', }; export default function AuthenticatedLayout() { const {user, logout} = useAuth(); const navigate = useNavigate(); const {pathname} = useLocation(); const currentPage = (Object.keys(PAGE_TO_PATH) as PageType[]).find((page) => pathname.startsWith(PAGE_TO_PATH[page]), ) ?? 'PRODUCTS'; const setPage = (page: PageType) => { navigate(PAGE_TO_PATH[page]); }; const handleLogout = async () => { // logout()이 상태를 비우므로 메시지에 쓸 유저 정보를 미리 잡아둔다. const who = `${user?.company ? user.company + ' ' : ''}${user?.name ?? ''}`.trim(); // 로그아웃 완료(상태 초기화) 후 이동 — 안 그러면 /login 가드가 다시 튕겨낼 수 있다. await logout(); showToast(who ? `${who}님, 로그아웃되었습니다.` : '로그아웃되었습니다.', 'info'); navigate('/login'); }; return ( ); }