teqo/src/components/campaign/StateDeputyForm.tsx
Francisco Ignácio Fontoura Solla e2724c10da Remodel the campaign vertical from Praça to Município
Rename the operational unit "Praça"/"Núcleo" to "Município" (code identifier
`municipality`) and land the 2026-07-23 course changes:

- New `candidate` role with unrestricted visibility (`isCampaignStaff` now
  includes it) alongside coordinator/advisor; leader is locked down to the
  supporter contact tool only.
- Demandas become staff-only; dobradinhas modeled via a `stateDeputy` entity.
- Camaçari consolidated to a single município (ZE 170/171 aggregated);
  Salvador keeps its 19 zone municípios.
- Map moves to the staff dashboard; `/campanha/municipios` is list/overview.
- Vote pledges keep the declared vs estimated (scenario) asymmetry; leaders
  never see estimates.

Destructive migration for the campaign vertical (drops nucleus/plaza-era
tables, wipes campaign rows, seeds 435 municípios). Public-site data untouched.

Includes the post-delivery /simplify cleanups: shared reloadStaffActor /
reloadCoordinatorActor helpers, req.context cache for getFreshCampaignUser,
parallelized dashboard loads, candidate dashboard-copy fix, and dead
leader-dashboard / roleKind code removal.
2026-07-23 21:36:20 -03:00

93 lines
3 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 { Textarea } from '@/components/ui/textarea'
import type { CampaignFormActionState } from '@/utilities/campaignFormActionError'
import { fieldError } from '@/utilities/campaignFormFields'
type StateDeputyFormProps = {
formAction: (
state: CampaignFormActionState,
formData: FormData,
) => Promise<CampaignFormActionState>
initial?: {
id: number
party: string | null
notes: string | null
}
initialName?: string
}
export const StateDeputyForm = ({ formAction, initial, initialName }: StateDeputyFormProps) => {
const [state, submitAction, isPending] = useActionState(formAction, {})
const isEdit = Boolean(initial)
return (
<form action={submitAction} className="flex max-w-2xl flex-col gap-4">
{initial ? <input type="hidden" name="stateDeputyId" value={initial.id} /> : null}
{isEdit ? (
<p className="text-sm text-muted-foreground">
O nome da dobradinha não pode ser alterado após a criação.
</p>
) : (
<Field>
<FieldLabel htmlFor="state-deputy-name">Nome</FieldLabel>
<Input
id="state-deputy-name"
name="name"
required
minLength={2}
maxLength={160}
defaultValue={initialName}
className="min-h-11"
/>
{fieldError(state.fieldErrors, 'name') ? (
<FieldError>{fieldError(state.fieldErrors, 'name')}</FieldError>
) : null}
</Field>
)}
<Field>
<FieldLabel htmlFor="state-deputy-party">Partido</FieldLabel>
<Input
id="state-deputy-party"
name="party"
maxLength={32}
defaultValue={initial?.party ?? undefined}
className="min-h-11"
placeholder="Ex.: PT"
/>
</Field>
<Field>
<FieldLabel htmlFor="state-deputy-notes">Observações</FieldLabel>
<Textarea
id="state-deputy-notes"
name="notes"
rows={4}
maxLength={4000}
defaultValue={initial?.notes ?? undefined}
/>
</Field>
{state.message && state.status !== 'success' ? (
<Alert variant="destructive">
<AlertDescription>{state.message}</AlertDescription>
</Alert>
) : null}
{state.status === 'success' ? (
<Alert>
<AlertDescription>{state.message}</AlertDescription>
</Alert>
) : null}
<Button type="submit" disabled={isPending} className="min-h-11 self-start">
{isPending ? <Spinner data-icon="inline-start" aria-hidden="true" /> : null}
{isEdit ? 'Salvar dobradinha' : 'Cadastrar dobradinha'}
</Button>
</form>
)
}