/** * 장소 검색 다이얼로그 컴포넌트 * - 카카오 장소 검색 API를 사용 */ import { useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { X, Search, MapPin } from 'lucide-react'; import useAuthStore from '@/stores/useAuthStore'; /** * @param {Object} props * @param {boolean} props.isOpen - 다이얼로그 열림 여부 * @param {Function} props.onClose - 닫기 핸들러 * @param {Function} props.onSelect - 장소 선택 핸들러 (place 객체 전달) */ function LocationSearchDialog({ isOpen, onClose, onSelect }) { const [searchQuery, setSearchQuery] = useState(''); const [results, setResults] = useState([]); const [searching, setSearching] = useState(false); // 다이얼로그 닫기 시 상태 초기화 const handleClose = () => { setSearchQuery(''); setResults([]); onClose(); }; // 카카오 장소 검색 API 호출 const handleSearch = async () => { if (!searchQuery.trim()) { setResults([]); return; } setSearching(true); try { const token = useAuthStore.getState().token; const response = await fetch(`/api/admin/kakao/places?query=${encodeURIComponent(searchQuery)}`, { headers: { Authorization: `Bearer ${token}`, }, }); if (response.ok) { const data = await response.json(); setResults(data.documents || []); } } catch (error) { console.error('장소 검색 오류:', error); } finally { setSearching(false); } }; // 장소 선택 const handleSelectPlace = (place) => { onSelect({ name: place.place_name, address: place.road_address_name || place.address_name, lat: parseFloat(place.y), lng: parseFloat(place.x), }); handleClose(); }; return ( {isOpen && ( e.stopPropagation()} >

장소 검색

{/* 검색 입력 */}
setSearchQuery(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); handleSearch(); } }} placeholder="장소명을 입력하세요" className="w-full pl-12 pr-4 py-3 border border-gray-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent" autoFocus />
{/* 검색 결과 */}
{results.length > 0 ? (
{results.map((place, index) => ( ))}
) : searchQuery && !searching ? (

검색어를 입력하고 검색 버튼을 눌러주세요

) : (

장소명을 입력하고 검색해주세요

)}
)}
); } export default LocationSearchDialog;