11import { XMarkIcon } from '@heroicons/react/24/outline' ;
2- import { MODAL_MESSAGE_CUSTOMER_SERVICE } from '../../../../constants/user/customerService' ;
32import * as S from './SearchBar.styled' ;
43import { useState } from 'react' ;
5- import { useLocation , useSearchParams } from 'react-router-dom' ;
4+ import { useSearchParams } from 'react-router-dom' ;
65import { useModal } from '../../../../hooks/useModal' ;
6+ import { MODAL_MESSAGE_CUSTOMER_SERVICE } from '../../../../constants/user/customerService' ;
77import Modal from '../../modal/Modal' ;
88import { ADMIN_ROUTE } from '../../../../constants/routes' ;
99
1010interface SearchBarProps {
11- onGetKeyword : ( keyword : string ) => void ;
11+ onGetKeyword : ( value : string ) => void ;
1212 value : string ;
13+ isNotice ?: boolean ;
1314}
1415
15- export default function SearchBar ( { onGetKeyword, value } : SearchBarProps ) {
16- const [ inputValue , setInputValue ] = useState < string > ( '' ) ;
16+ export default function SearchBar ( {
17+ onGetKeyword,
18+ value,
19+ isNotice,
20+ } : SearchBarProps ) {
21+ const [ keyword , setKeyword ] = useState < string > ( value ) ;
1722 const { isOpen, message, handleModalOpen, handleModalClose } = useModal ( ) ;
1823 const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
19- const location = useLocation ( ) ;
20- const keyword = inputValue ? inputValue : value ;
2124
2225 const handleKeyword = ( inputValue : string ) => {
2326 const newSearchParams = new URLSearchParams ( searchParams ) ;
@@ -32,22 +35,21 @@ export default function SearchBar({ onGetKeyword, value }: SearchBarProps) {
3235 const handleSubmit = ( e : React . FormEvent < HTMLFormElement > ) => {
3336 e . preventDefault ( ) ;
3437
35- if ( inputValue . trim ( ) === '' ) {
38+ if ( keyword . trim ( ) === '' ) {
3639 return handleModalOpen ( MODAL_MESSAGE_CUSTOMER_SERVICE . noKeyword ) ;
3740 } else {
38- onGetKeyword ( inputValue ) ;
39- handleKeyword ( inputValue ) ;
41+ onGetKeyword ( keyword ) ;
42+ handleKeyword ( keyword ) ;
4043 return ;
4144 }
4245 } ;
4346
4447 const handleChangeKeyword = ( e : React . ChangeEvent < HTMLInputElement > ) => {
45- const value = e . target . value ;
46- setInputValue ( value ) ;
48+ setKeyword ( e . target . value ) ;
4749 } ;
4850
4951 const handleClickSearchDefault = ( ) => {
50- setInputValue ( '' ) ;
52+ setKeyword ( '' ) ;
5153 onGetKeyword ( '' ) ;
5254 handleKeyword ( '' ) ;
5355 } ;
@@ -73,9 +75,11 @@ export default function SearchBar({ onGetKeyword, value }: SearchBarProps) {
7375 </ S . AdminSearchBarInputWrapper >
7476 < S . AdminSearchBarButton > 검색</ S . AdminSearchBarButton >
7577 </ S . AdminSearchBarWrapper >
76- < S . WriteLink to = { ADMIN_ROUTE . write } state = { { form : location . pathname } } >
77- 작성하기
78- </ S . WriteLink >
78+ { isNotice && (
79+ < S . WriteLink to = { ADMIN_ROUTE . write } state = { { form : location . pathname } } >
80+ 작성하기
81+ </ S . WriteLink >
82+ ) }
7983 < Modal isOpen = { isOpen } onClose = { handleModalClose } >
8084 { message }
8185 </ Modal >
0 commit comments