import { Check, Clear, CopyAll } from '@mui/icons-material' import { ReactNode, useEffect, useState } from 'react' import toast from 'react-hot-toast' import { useTranslation } from 'react-i18next' import { processError } from '@dao-dao/utils' import { IconButton, SmallLoader, Tooltip } from '../components' export type CreateProposalProps = { /** * The rendered new proposal form. */ newProposal: ReactNode /** * Optionally show a button that copies a link to the current draft. */ copyDraftLink?: () => Promise /** * Optionally show a button that clears the form. */ clear?: () => void } export const CreateProposal = ({ newProposal, copyDraftLink: _copyDraftLink, clear, }: CreateProposalProps) => { const { t } = useTranslation() const [copied, setCopied] = useState(false) // Clear copied after 2 seconds. useEffect(() => { const timeout = setTimeout(() => setCopied(false), 2000) return () => clearTimeout(timeout) }, [copied]) const [copying, setCopying] = useState(false) const copyDraftLink = _copyDraftLink && (async () => { setCopying(true) try { await _copyDraftLink() setCopied(true) } catch (error) { console.error(error) toast.error(processError(error)) } finally { setCopying(false) } }) return (

{t('title.newProposal')}

{copyDraftLink && ( )} {clear && ( )}
{newProposal}
) }