'use client' import { useActionState } from 'react' import { CampaignFormActionMessage } from '@/components/campaign/shared/CampaignFormActionMessage' import { Button } from '@/components/ui/button' import { Field, FieldError, FieldLabel } from '@/components/ui/field' import { Input } from '@/components/ui/input' import { Spinner } from '@/components/ui/Spinner' import type { CampaignFormActionState } from '@/utilities/campaignFormActionError' import { fieldError } from '@/utilities/campaignFormFields' type DeclareVotesFormProps = { municipalityID: number /** Present when staff declare on behalf of a leadership. */ leadershipID?: number currentDeclaredVotes: number | null formAction: ( state: CampaignFormActionState, formData: FormData, ) => Promise } export const DeclareVotesForm = ({ municipalityID, leadershipID, currentDeclaredVotes, formAction, }: DeclareVotesFormProps) => { const [state, submitAction, isPending] = useActionState(formAction, {}) return (
{leadershipID !== undefined ? ( ) : null} {leadershipID !== undefined ? 'Quantos votos a liderança traz neste município?' : 'Quantos votos você está trazendo neste município?'}
{fieldError(state.fieldErrors, 'declaredVotes') ? ( {fieldError(state.fieldErrors, 'declaredVotes')} ) : null}
) }