'use client' import { SEARCH_OPTIONS, SEARCH_OPTIONS_ENUM, SEARCH_OPTIONS_PARTNERS, useSurveyFilterStore } from '@/store/surveyFilterStore' import { useRouter } from 'next/navigation' import { useState } from 'react' export default function SearchForm({ memberRole, userId }: { memberRole: string; userId: string }) { const router = useRouter() const { setSearchOption, setSort, setIsMySurvey, setKeyword, reset, isMySurvey, keyword, searchOption, sort, setOffset } = useSurveyFilterStore() const [searchKeyword, setSearchKeyword] = useState(keyword) const [option, setOption] = useState(searchOption) const handleSearch = () => { if (option !== 'id' && searchKeyword.trim().length < 2) { alert('2文字以上入力してください') return } reset() setKeyword(searchKeyword) setSearchOption(option) } const searchOptions = memberRole === 'Partner' ? SEARCH_OPTIONS_PARTNERS : SEARCH_OPTIONS return (
{ if (e.target.value.length > 30) { alert('30文字以内で入力してください') return } setSearchKeyword(e.target.value) }} onKeyDown={(e) => { if (e.key === 'Enter') { handleSearch() } }} />
{ setOffset(0) setIsMySurvey(isMySurvey === userId ? null : userId) }} />
) }