import { useFetcher } from 'react-router-dom' import { CheckboxFieldUncontrolled } from 'components/Inputs' import { useEffect } from 'react' import { ReportReason } from 'types/report' import { LoadingSpinner } from './LoadingSpinner' import { PopupProps } from 'types' type ReportPopupProps = { openedAt: number reasons: ReportReason[] } & PopupProps export const ReportPopup = ({ openedAt, reasons, handleClose }: ReportPopupProps) => { // Use openedAt to allow for multiple reports // by default, fetcher will remember the data const fetcher = useFetcher({ key: openedAt.toString() }) // Close automatically if action succeeds useEffect(() => { if (fetcher.data) { const { isSent } = fetcher.data if (isSent) { handleClose() } } }, [fetcher, handleClose]) return ( <> {fetcher.state !== 'idle' && }

Report Post

{reasons.map((r) => ( ))}
) }