11'use client' ;
22
33import Link from 'next/link' ;
4- import Image from 'next/image' ;
54import IconLogo from '@assets/svg/logo' ;
65import IconBell from '@assets/svg/bell' ;
76import useUserStore from '@/stores/authStore' ;
8- import { useEffect , useRef , useState } from 'react' ;
97import { useRouter } from 'next/navigation' ;
10- import ProfileDefaultIcon from '@assets/svg/profile-default ' ;
8+ import ProfileDropdown from '@/components/ProfileDropdown ' ;
119
1210export default function Header ( ) {
1311 const router = useRouter ( ) ;
1412 const user = useUserStore ( ( state ) => state . user ) ;
1513 const setUser = useUserStore ( ( state ) => state . setUser ) ;
1614 const isLoggedIn = ! ! user ;
1715
18- const [ isOpen , setIsOpen ] = useState ( false ) ;
19- const dropdownRef = useRef < HTMLDivElement > ( null ) ;
20-
21- // 바깥 클릭 시 드롭다운 닫기
22- useEffect ( ( ) => {
23- const handleClickOutside = ( e : MouseEvent ) => {
24- if (
25- dropdownRef . current &&
26- ! dropdownRef . current . contains ( e . target as Node )
27- ) {
28- setIsOpen ( false ) ;
29- }
30- } ;
31- document . addEventListener ( 'mousedown' , handleClickOutside ) ;
32- return ( ) => document . removeEventListener ( 'mousedown' , handleClickOutside ) ;
33- } , [ ] ) ;
34-
35- // 로그아웃 처리 후 홈 이동
16+ // 로그아웃 처리
3617 const handleLogout = ( ) => {
3718 setUser ( null ) ;
3819 router . push ( '/' ) ;
@@ -53,51 +34,20 @@ export default function Header() {
5334 < div className = 'text-md relative flex items-center gap-24 text-black' >
5435 { isLoggedIn ? (
5536 < >
37+ { /* 알림 아이콘 */ }
5638 < button aria-label = '알림' className = 'hover:text-primary' >
5739 < IconBell />
5840 </ button >
5941
42+ { /* 구분선 */ }
6043 < div className = 'mx-12 h-22 w-px bg-gray-300' />
6144
62- { /* 프로필 + 드롭다운 */ }
63- < div
64- className = 'flex items-center gap-8 cursor-pointer'
65- onClick = { ( ) => setIsOpen ( ( prev ) => ! prev ) }
66- ref = { dropdownRef }
67- >
68- { user . profileImageUrl ? (
69- < Image
70- src = { user . profileImageUrl }
71- alt = '프로필 이미지'
72- width = { 32 }
73- height = { 32 }
74- className = 'rounded-full border border-gray-300'
75- />
76- ) : (
77- < div className = 'size-32 rounded-full border border-gray-300 overflow-hidden' >
78- < ProfileDefaultIcon size = { 32 } />
79- </ div >
80- ) }
81- < span > { user . nickname || '사용자' } </ span >
82-
83- { /* 드롭다운 메뉴 */ }
84- { isOpen && (
85- < div className = 'absolute top-50 right-0 z-50 mt-20 w-120 rounded-md border border-gray-200 bg-white shadow-md' >
86- < Link
87- href = '/mypage'
88- className = 'block w-full px-16 py-12 text-left hover:bg-gray-50 cursor-pointer'
89- >
90- 마이페이지
91- </ Link >
92- < button
93- onClick = { handleLogout }
94- className = 'w-full px-16 py-12 text-left hover:bg-gray-50 cursor-pointer'
95- >
96- 로그아웃
97- </ button >
98- </ div >
99- ) }
100- </ div >
45+ { /* 프로필 드롭다운 */ }
46+ < ProfileDropdown
47+ nickname = { user . nickname }
48+ profileImageUrl = { user . profileImageUrl }
49+ onLogout = { handleLogout }
50+ />
10151 </ >
10252 ) : (
10353 < >
0 commit comments