import { Contract } from 'common/contract' import { Group } from 'common/group' import { Post } from 'common/post' import { useState } from 'react' import { PostCardList } from 'web/pages/group/[...slugs]' import { Button } from './button' import { PillButton } from './buttons/pill-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 PinnedSelectModal(props: { title: string description?: React.ReactNode open: boolean setOpen: (open: boolean) => void onSubmit: ( selectedItems: { itemId: string; type: string }[] ) => void | Promise contractSearchOptions?: Partial[0]> group: Group posts: Post[] }) { const { title, description, open, setOpen, onSubmit, contractSearchOptions, posts, group, } = props const [selectedItem, setSelectedItem] = useState<{ itemId: string type: string } | null>(null) const [loading, setLoading] = useState(false) const [selectedTab, setSelectedTab] = useState<'contracts' | 'posts'>('posts') async function selectContract(contract: Contract) { selectItem(contract.id, 'contract') } async function selectPost(post: Post) { selectItem(post.id, 'post') } async function selectItem(itemId: string, type: string) { setSelectedItem({ itemId: itemId, type: type }) } async function onFinish() { setLoading(true) if (selectedItem) { await onSubmit([ { itemId: selectedItem.itemId, type: selectedItem.type, }, ]) setLoading(false) setOpen(false) setSelectedItem(null) } } return (
{title}
{!loading && ( {selectedItem && ( )} )}
{description}
{loading && (
)}
setSelectedTab('contracts')} selected={selectedTab === 'contracts'} > Contracts setSelectedTab('posts')} selected={selectedTab === 'posts'} > Posts
{selectedTab === 'contracts' ? (
) : ( <>
{posts.length === 0 && (
No posts yet
)}
)}
) }