1- import { useState , useEffect , useRef } from 'react' ;
1+ import { useState , useRef } from 'react' ;
22import { useDispatch } from 'react-redux' ;
33import { useNavigate } from 'react-router-dom' ;
44import { useUserProfile } from '@/store/queries/user/useUserQueries' ;
@@ -11,6 +11,7 @@ import { useGetProjectList } from '@/store/queries/project/useProjectQueries';
1111import { useDebounce } from '@/hooks/useDebounce' ;
1212import BellBadge from '@/components/ui/BellBadge' ;
1313import { ProjectListData } from '@/types/project.type' ;
14+ import StatusBadge , { StatusType } from '@/pages/project/_components/StatusBadge' ;
1415// import { RootState } from '@/store/redux/store';
1516
1617export default function Header ( { onMenuClick } : { onMenuClick ?: ( ) => void } ) {
@@ -22,6 +23,8 @@ export default function Header({ onMenuClick }: { onMenuClick?: () => void }) {
2223 const [ showNotification , setShowNotification ] = useState ( false ) ;
2324 const notificationRef = useRef < HTMLDivElement > ( null ) ;
2425 const debouncedInputValue = useDebounce ( inputValue , 300 ) ;
26+ const inputRef = useRef < HTMLInputElement > ( null ) ;
27+ // const [dropdownPos, setDropdownPos] = useState({ left: 0, top: 0, width: 0 });
2528 // const projectName = useSelector((state: RootState) => state.searchReducer.projectName);
2629 const { data : suggestedProjects = [ ] } = useGetProjectList ( {
2730 projectName : debouncedInputValue ,
@@ -38,16 +41,21 @@ export default function Header({ onMenuClick }: { onMenuClick?: () => void }) {
3841 // { enabled: !!debouncedInputValue }
3942 // );
4043
41- useEffect ( ( ) => {
42- if ( ! showNotification ) return ;
43- const handleClickOutside = ( e : MouseEvent ) => {
44- if ( notificationRef . current && ! notificationRef . current . contains ( e . target as Node ) ) {
45- setShowNotification ( false ) ;
46- }
47- } ;
48- document . addEventListener ( 'mousedown' , handleClickOutside ) ;
49- return ( ) => document . removeEventListener ( 'mousedown' , handleClickOutside ) ;
50- } , [ showNotification ] ) ;
44+ // function updateDropdownPos() {
45+ // if (inputRef.current) {
46+ // const rect = inputRef.current.getBoundingClientRect();
47+ // setDropdownPos({ left: rect.left, top: rect.bottom, width: rect.width });
48+ // }
49+ // }
50+
51+ // useEffect(() => {
52+ // if (!showRecent) return;
53+ // updateDropdownPos();
54+ // window.addEventListener('resize', updateDropdownPos);
55+ // return () => {
56+ // window.removeEventListener('resize', updateDropdownPos);
57+ // };
58+ // }, [showRecent]);
5159
5260 const handleSearch = ( keyword ?: string ) => {
5361 const searchWord = keyword ?? inputValue ;
@@ -100,6 +108,7 @@ export default function Header({ onMenuClick }: { onMenuClick?: () => void }) {
100108 < img src = { searchIcon } alt = "search button" className = "absolute left-4 top-2 w-6 h-6" />
101109 </ button >
102110 < input
111+ ref = { inputRef }
103112 type = "text"
104113 placeholder = "프로젝트 검색"
105114 className = "w-full rounded-full pl-10 text-base"
@@ -114,7 +123,7 @@ export default function Header({ onMenuClick }: { onMenuClick?: () => void }) {
114123 />
115124 { showRecent && (
116125 < div
117- className = "absolute left-0 top-full mt-2 w-full min-w-[180px] max-w-[360px] md:max-w-none bg-white border border-gray-200 rounded-lg shadow-lg p-4 z-50 max-h-60 overflow-auto sm:w-full sm:left-0 sm:right-0 sm:mx-auto"
126+ className = "absolute left-0 top-full mt-2 w-full min-w-[180px] max-w-[360px] md:max-w-none bg-white border border-gray-200 rounded-lg shadow-lg p-4 max-h-60 overflow-auto sm:w-full sm:left-0 sm:right-0 sm:mx-auto z-[99999] "
118127 style = { { minHeight : 48 } } >
119128 { inputValue . trim ( ) ? (
120129 suggestedProjects . length > 0 ? (
@@ -130,14 +139,7 @@ export default function Header({ onMenuClick }: { onMenuClick?: () => void }) {
130139 setTimeout ( ( ) => handleSearch ( proj . projectName ) , 0 ) ;
131140 } } >
132141 < span > { proj . projectName } </ span >
133- < span
134- className = {
135- proj . projectStatus === 'COMPLETED'
136- ? 'ml-2 px-2 py-0.5 rounded-full text-xs font-semibold bg-green-100 text-green-700'
137- : 'ml-2 px-2 py-0.5 rounded-full text-xs font-semibold bg-yellow-100 text-yellow-700'
138- } >
139- { proj . projectStatus === 'COMPLETED' ? '완료' : '진행중' }
140- </ span >
142+ < StatusBadge status = { proj . projectStatus as StatusType } className = "ml-2" />
141143 </ li >
142144 ) ) }
143145 </ ul >
@@ -161,7 +163,6 @@ export default function Header({ onMenuClick }: { onMenuClick?: () => void }) {
161163 < div className = "text-xs text-gray-400 mb-1" > 최근 검색어</ div >
162164 < ul className = "mb-2" >
163165 { recentSearches . map ( ( item ) => {
164- // 프로젝트명과 완전 일치하는 프로젝트 찾기
165166 const matched = suggestedProjects . find (
166167 ( p : ProjectListData ) => p . projectName . toLowerCase ( ) === item . toLowerCase ( )
167168 ) ;
@@ -177,16 +178,7 @@ export default function Header({ onMenuClick }: { onMenuClick?: () => void }) {
177178 } } >
178179 { item }
179180 </ span >
180- { matched && (
181- < span
182- className = {
183- matched . projectStatus === 'COMPLETED'
184- ? 'ml-2 px-2 py-0.5 rounded-full text-xs font-semibold bg-green-100 text-green-700'
185- : 'ml-2 px-2 py-0.5 rounded-full text-xs font-semibold bg-yellow-100 text-yellow-700'
186- } >
187- { matched . projectStatus === 'COMPLETED' ? '완료' : '진행중' }
188- </ span >
189- ) }
181+ { matched && < StatusBadge status = { matched . projectStatus as StatusType } className = "ml-2" /> }
190182 < button
191183 className = "ml-2 text-gray-400 hover:text-red-400 opacity-70 group-hover:opacity-100 transition"
192184 onMouseDown = { ( e ) => {
0 commit comments