import React, { useState, useEffect } from 'react' import { router, usePage } from '@inertiajs/react' import { Spinner } from 'flowbite-react' import { usePrevious } from 'react-use' import Modal from '@/Components/Modal' import SearchInput from '@/Components/SearchInput' import Pagination from '@/Components/Pagination' export default function CustomerSelectionModal(props) { const { modalState, onItemSelected } = props const [loading, setLoading] = useState(false) const { props: { customers: { data, links }, }, } = usePage() const [search, setSearch] = useState('') const preValue = usePrevious(search) const params = { customer_q: search } const handleItemSelected = (item) => { onItemSelected(item) modalState.toggle() } useEffect(() => { if (preValue) { router.get(route(route().current()), params, { replace: true, preserveState: true, }) } }, [search]) useEffect(() => { router.on('start', () => setLoading(true)) router.on('finish', () => setLoading(false)) }, []) return ( setSearch(e.target.value)} value={search} /> {loading ? (
) : (
{data.map((customer) => ( handleItemSelected(customer) } > ))}
Name
{customer.name}
)}
) }