import { useEffect, useState } from 'react' import { router, useForm, usePage } from '@inertiajs/react' import { HiArrowLeft, HiOutlineStar } from 'react-icons/hi2' import { useAutoFocus } from '@/hooks' import { isFavorite } from '../utils' import FormLocation from '../../Components/FormLocation' import Modal from '../../Components/Modal' export default function LocationModal(props) { const { props: { auth: { user }, }, } = usePage() const { state, locations, onItemSelected } = props const { post, processing } = useForm({}) const [search, setSearch] = useState('') const locationFocus = useAutoFocus() const [filter_locations, setFilterLocations] = useState(locations) const handleOnFilter = (e) => { setSearch(e.target.value) if (e.target.value === '') { setFilterLocations(locations) return } setFilterLocations( filter_locations.filter((location) => { let name = location.name.toLowerCase() let search = e.target.value.toLowerCase() return name.includes(search) }) ) } const handleItemSelected = (location) => { onItemSelected(location) state.toggle() } const handleFavorite = (location) => { if (processing) { return } post(route('customer.location.favorite', location)) } useEffect(() => { if (state.isOpen === true) { locationFocus.current.focus() } }, [state]) return (
{filter_locations.map((location) => (
handleItemSelected(location)} className="flex-1 px-3 py-3" > {location.name}
handleFavorite(location)} >
))}
) }