import { Add, Close, Edit } from '@mui/icons-material' import clsx from 'clsx' import { ComponentType, useCallback } from 'react' import { FieldErrors, useFieldArray, useFormContext } from 'react-hook-form' import toast from 'react-hot-toast' import { useTranslation } from 'react-i18next' import { AddressInputProps, CreateCw1Whitelist, DurationUnitsValues, ProposalVetoConfig, } from '@dao-dao/types' import { makeValidateAddress, validateNonNegative, validateRequired, } from '@dao-dao/utils' import { useChain } from '../../contexts' import { Button } from '../buttons' import { IconButton } from '../icon_buttons' import { FormSwitchCard, InputErrorMessage, InputLabel, NumericInput, SelectInput, } from '../inputs' export type ProposalVetoConfigProps = { veto: ProposalVetoConfig fieldNamePrefix: string errors?: FieldErrors disabled?: boolean createCw1WhitelistVetoers: CreateCw1Whitelist creatingCw1WhitelistVetoers: boolean AddressInput: ComponentType> className?: string } export const ProposalVetoConfigurer = ({ veto, fieldNamePrefix, errors, disabled, createCw1WhitelistVetoers, creatingCw1WhitelistVetoers, AddressInput, className, }: ProposalVetoConfigProps) => { const { t } = useTranslation() const { bech32Prefix } = useChain() const { control, register, setValue, getValues } = useFormContext() const { fields: vetoerFields, append: appendVetoer, remove: removeVetoer, } = useFieldArray({ control, name: (fieldNamePrefix + 'addresses') as 'addresses', }) const onCreateCw1WhitelistVetoers = useCallback(async () => { const contractAddress = await createCw1WhitelistVetoers( veto.addresses.map(({ address }) => address) ) // Address is valid on success and undefined on error. Errors // are handled automatically, so we can just do nothing here. if (contractAddress) { setValue( (fieldNamePrefix + 'cw1WhitelistAddress') as 'cw1WhitelistAddress', contractAddress ) toast.success(t('success.saved')) } }, [createCw1WhitelistVetoers, fieldNamePrefix, setValue, t, veto.addresses]) return (
{vetoerFields.map(({ id }, index) => (
{!disabled && !veto.cw1WhitelistAddress && index > 0 && ( removeVetoer(index)} size="sm" variant="ghost" /> )}
))}
{!disabled && (
{veto.cw1WhitelistAddress ? ( ) : ( )} {!veto.cw1WhitelistAddress && vetoerFields.length > 1 && ( )}
)}
{DurationUnitsValues.map((type, idx) => ( ))}
) }