import { Contract } from 'common/contract' import { useState } from 'react' import { Button } from './button' import { ContractSearch } from './contract-search' import { Col } from './layout/col' import { Modal } from './layout/modal' import { Row } from './layout/row' import { LoadingIndicator } from './loading-indicator' export function SelectMarketsModal(props: { title: string description?: React.ReactNode open: boolean setOpen: (open: boolean) => void submitLabel: (length: number) => string onSubmit: (contracts: Contract[]) => void | Promise contractSearchOptions?: Partial[0]> }) { const { title, description, open, setOpen, submitLabel, onSubmit, contractSearchOptions, } = props const [contracts, setContracts] = useState([]) const [loading, setLoading] = useState(false) async function addContract(contract: Contract) { if (contracts.map((c) => c.id).includes(contract.id)) { setContracts(contracts.filter((c) => c.id !== contract.id)) } else setContracts([...contracts, contract]) } async function onFinish() { setLoading(true) await onSubmit(contracts) setLoading(false) setOpen(false) setContracts([]) } return (
{title}
{!loading && ( {contracts.length > 0 && ( )} )}
{description}
{loading && (
)}
c.id), highlightClassName: '!bg-indigo-100 outline outline-2 outline-indigo-300', }} additionalFilter={{}} /* hide pills */ headerClassName="bg-white sticky" {...contractSearchOptions} />
) }