teqo-backup/src/components/campaign/PledgeEstimateForm.tsx
Francisco Ignácio Fontoura Solla cf13c441aa Remodel /campanha around predefined Praças replacing electoral nuclei.
436 seeded Praças (municipality-based; per-TSE-zone in Salvador/Camaçari) become
the operational unit; roles renamed to coordinator/advisor/leader with advisors
scoped to administered Praças. Leadership is one record per person across many
Praças/organizations; vote pledges split leader-declared vs staff-estimated
(estimates never serialized to leaders). Adds organizations, demand workflow
with staff-only cost/receipts, action-plan results with deputy presence, manual
political trend, multi-candidate comparison and the diverging red/white/blue
map mode. Migration 20260721_020109_remodel_plazas deliberately resets the
campaign vertical in production (public site untouched); test suite ported to
the new model (unit 187 / int 306 / e2e 9 green).
2026-07-21 02:28:00 -03:00

78 lines
2.6 KiB
TypeScript

'use client'
import { useActionState } from 'react'
import { Alert, AlertDescription } from '@/components/ui/Alert'
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 PledgeEstimateFormProps = {
pledgeID: number
currentEstimatedVotes: number | null
currentEstimateNote: string | null
formAction: (
state: CampaignFormActionState,
formData: FormData,
) => Promise<CampaignFormActionState>
}
/** Staff-only inline estimate. The leader never sees these fields. */
export const PledgeEstimateForm = ({
pledgeID,
currentEstimatedVotes,
currentEstimateNote,
formAction,
}: PledgeEstimateFormProps) => {
const [state, submitAction, isPending] = useActionState(formAction, {})
return (
<form action={submitAction} className="flex flex-col gap-2">
<input type="hidden" name="pledgeId" value={pledgeID} />
<div className="flex flex-wrap items-end gap-2">
<Field>
<FieldLabel htmlFor={`pledge-estimate-${pledgeID}`} className="text-xs">
Estimativa do assessor
</FieldLabel>
<Input
id={`pledge-estimate-${pledgeID}`}
name="estimatedVotes"
type="number"
min={0}
max={1000000}
inputMode="numeric"
defaultValue={currentEstimatedVotes ?? undefined}
className="min-h-11 w-32"
/>
</Field>
<Field className="min-w-40 flex-1">
<FieldLabel htmlFor={`pledge-note-${pledgeID}`} className="text-xs">
Justificativa
</FieldLabel>
<Input
id={`pledge-note-${pledgeID}`}
name="estimateNote"
maxLength={1000}
defaultValue={currentEstimateNote ?? undefined}
className="min-h-11"
/>
</Field>
<Button type="submit" variant="secondary" disabled={isPending} className="min-h-11">
{isPending ? <Spinner data-icon="inline-start" aria-hidden="true" /> : null}
Salvar
</Button>
</div>
{fieldError(state.fieldErrors, 'estimatedVotes') ? (
<FieldError>{fieldError(state.fieldErrors, 'estimatedVotes')}</FieldError>
) : null}
{state.message && state.status !== 'success' ? (
<Alert variant="destructive">
<AlertDescription>{state.message}</AlertDescription>
</Alert>
) : null}
</form>
)
}