import React, { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { UserMeResponse } from '../types/api'; import { logout } from '../utils/api'; import LanguageSwitch from './LanguageSwitch'; interface SidebarItemProps { icon: React.ReactNode; label: string; isActive?: boolean; isCollapsed: boolean; isDisabled?: boolean; onClick?: () => void; } const SidebarItem: React.FC = ({ icon, label, isActive, isCollapsed, isDisabled, onClick }) => { return (
{icon}
{!isCollapsed && {label}}
); }; interface SidebarProps { activeItem: string; onNavigate: (id: string) => void; onHome?: () => void; userInfo?: UserMeResponse | null; onLogout?: () => void; } const Sidebar: React.FC = ({ activeItem, onNavigate, onHome, userInfo, onLogout }) => { const { t } = useTranslation(); const [isCollapsed, setIsCollapsed] = useState(false); const [isMobileOpen, setIsMobileOpen] = useState(false); const [isLoggingOut, setIsLoggingOut] = useState(false); // 로그아웃 처리 const handleLogout = async () => { if (isLoggingOut) return; setIsLoggingOut(true); try { await logout(); onLogout?.(); } catch (error) { console.error('Logout failed:', error); // 에러가 나도 로컬 토큰은 이미 삭제됨, 홈으로 이동 onLogout?.(); } finally { setIsLoggingOut(false); } }; useEffect(() => { const handleResize = () => { if (window.innerWidth < 768) { setIsMobileOpen(false); } }; handleResize(); window.addEventListener('resize', handleResize); return () => window.removeEventListener('resize', handleResize); }, []); const handleNavigate = (id: string) => { onNavigate(id); if (window.innerWidth < 768) { setIsMobileOpen(false); } }; const menuItems = [ { id: '대시보드', label: t('sidebar.dashboard'), disabled: false, icon: }, { id: '새 프로젝트 만들기', label: t('sidebar.newProject'), disabled: false, icon: }, { id: 'ADO2 콘텐츠', label: t('sidebar.ado2Contents'), disabled: false, icon: }, { id: '내 콘텐츠', label: t('sidebar.myContents'), disabled: true, icon: }, { id: '내 정보', label: t('sidebar.myInfo'), disabled: false, icon: }, ]; return ( <> {/* Mobile Menu Button */} {/* Mobile Overlay */} {isMobileOpen && (
setIsMobileOpen(false)} /> )} {/* Sidebar */}
{!isCollapsed && ( ADO2 )}
{menuItems.map(item => ( handleNavigate(item.id)} /> ))}
{userInfo?.profile_image_url || userInfo?.thumbnail_image_url ? ( Profile ) : (
)} {!isCollapsed && (

{userInfo?.nickname || t('sidebar.defaultUser')}

)}
); }; export default Sidebar;