|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import Link from 'next/link'; |
| 4 | +import { usePathname, useRouter } from 'next/navigation'; |
| 5 | +import { |
| 6 | + Home, |
| 7 | + ClipboardList, |
| 8 | + CalendarPlus, |
| 9 | + CopyPlus, |
| 10 | + LogOut, |
| 11 | +} from 'lucide-react'; |
| 12 | +import { signOut } from 'firebase/auth'; |
| 13 | +import { auth } from '@/lib/firebase'; |
| 14 | + |
| 15 | +const navItems = [ |
| 16 | + { label: '홈', href: '/', icon: Home }, |
| 17 | + { label: '개발 일지', href: '/logs', icon: ClipboardList }, |
| 18 | + { label: '새 계획 만들기', href: '/plans/new', icon: CalendarPlus }, |
| 19 | + { label: '새 페이지 만들기', href: '/pages/new', icon: CopyPlus }, |
| 20 | +]; |
| 21 | + |
1 | 22 | const Sidebar = () => { |
2 | | - return <div className="w-48 bg-white"></div>; |
| 23 | + const pathname = usePathname(); |
| 24 | + const router = useRouter(); |
| 25 | + |
| 26 | + const handleLogout = async (): Promise<void> => { |
| 27 | + try { |
| 28 | + await signOut(auth); |
| 29 | + router.replace('/landing'); |
| 30 | + router.refresh(); // 서버 컴포넌트/세션 UI 갱신 |
| 31 | + } catch (err) { |
| 32 | + console.error('로그아웃 실패:', err); |
| 33 | + alert('로그아웃에 실패했습니다.'); |
| 34 | + } |
| 35 | + }; |
| 36 | + |
| 37 | + return ( |
| 38 | + <div className="fixed flex h-screen w-48 flex-col bg-white"> |
| 39 | + <div className="flex items-center gap-2 px-6 py-5"> |
| 40 | + <span className="text-primary text-lg font-bold"></></span> |
| 41 | + <span>DevFlow</span> |
| 42 | + </div> |
| 43 | + <hr className="border-slate-300" /> |
| 44 | + <nav className="mt-4 px-4"> |
| 45 | + <ul className="space-y-2"> |
| 46 | + {navItems.map(({ label, href, icon: Icon }) => { |
| 47 | + const isActive = pathname === href; |
| 48 | + |
| 49 | + return ( |
| 50 | + <li key={href}> |
| 51 | + <Link |
| 52 | + href={href} |
| 53 | + className={[ |
| 54 | + 'flex items-center gap-3 rounded-lg px-4 py-3 text-sm font-medium transition', |
| 55 | + isActive |
| 56 | + ? 'bg-slate-200 text-slate-900' |
| 57 | + : 'text-slate-700 hover:bg-slate-100', |
| 58 | + ].join(' ')} |
| 59 | + > |
| 60 | + <Icon |
| 61 | + className={[ |
| 62 | + 'h-5 w-5', |
| 63 | + isActive ? 'text-slate-900' : 'text-slate-600', |
| 64 | + ].join(' ')} |
| 65 | + /> |
| 66 | + {label} |
| 67 | + </Link> |
| 68 | + </li> |
| 69 | + ); |
| 70 | + })} |
| 71 | + </ul> |
| 72 | + </nav> |
| 73 | + <div className="absolute bottom-0 w-full border-t border-slate-200 p-4"> |
| 74 | + <button |
| 75 | + className="flex items-center gap-3 rounded-lg px-4 py-3 text-sm font-medium text-slate-700 hover:bg-slate-100" |
| 76 | + onClick={handleLogout} |
| 77 | + > |
| 78 | + <LogOut className="h-5 w-5 text-slate-600" /> |
| 79 | + 로그아웃 |
| 80 | + </button> |
| 81 | + </div> |
| 82 | + </div> |
| 83 | + ); |
3 | 84 | }; |
4 | 85 |
|
5 | 86 | export default Sidebar; |
0 commit comments