'use client' import { useSurvey } from '@/hooks/useSurvey' import { useAddressStore } from '@/store/addressStore' import { usePopupController } from '@/store/popupController' import { useState } from 'react' type Address = { address1: string address2: string address3: string kana1: string kana2: string kana3: string prefcode: string zipcode: string } export default function ZipCodePopup() { const [searchValue, setSearchValue] = useState('') //search 데이터 유무 const { setAddressData } = useAddressStore() const { getZipCode } = useSurvey() const [addressInfo, setAddressInfo] = useState([]) const popupController = usePopupController() const handleApply = (item: Address) => { setAddressData({ post_code: item.zipcode || '', address: item.address1 || '', address_detail: item.address2 + ' ' + item.address3 || '', }) popupController.setZipCodePopup(false) } const handleChange = (e: React.ChangeEvent) => { setSearchValue(e.target.value) } const handleSearch = () => { const addressData = getZipCode(searchValue) addressData.then((address) => { if (address) { setAddressInfo(address) } else { setAddressInfo([]) } }) } return ( <>
住所検索
{ if (e.key === 'Enter') { handleSearch() } }} /> {/*input에 데이터 있으면 삭제버튼 보임 */} {searchValue && }
名前
{addressInfo?.map((item, index) => ( { handleApply(item) }} > ))}
都道府県 市区町村 市区町村以下
{item.address1} {item.address2} {item.address3}
) }