teqo-backup/src/components/campaign/DemandForm.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

102 lines
3.7 KiB
TypeScript

'use client'
import { useActionState } from 'react'
import type { RelationOption } from '@/components/campaign/RelationMultiSelect'
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 { NativeSelect, NativeSelectOption } from '@/components/ui/native-select'
import { Spinner } from '@/components/ui/Spinner'
import { Textarea } from '@/components/ui/textarea'
import { campaignDemandKindLabels, campaignDemandKinds } from '@/lib/schemas/campaignDemand'
import type { CampaignFormActionState } from '@/utilities/campaignFormActionError'
import { fieldError } from '@/utilities/campaignFormFields'
type DemandFormProps = {
municipalityOptions: RelationOption[]
formAction: (
state: CampaignFormActionState,
formData: FormData,
) => Promise<CampaignFormActionState>
}
export const DemandForm = ({ municipalityOptions, formAction }: DemandFormProps) => {
const [state, submitAction, isPending] = useActionState(formAction, {})
return (
<form action={submitAction} className="flex max-w-2xl flex-col gap-4">
<Field>
<FieldLabel htmlFor="demand-title">O que você precisa?</FieldLabel>
<Input
id="demand-title"
name="title"
required
minLength={2}
maxLength={160}
className="min-h-11"
/>
{fieldError(state.fieldErrors, 'title') ? (
<FieldError>{fieldError(state.fieldErrors, 'title')}</FieldError>
) : null}
</Field>
<div className="grid gap-4 sm:grid-cols-2">
<Field>
<FieldLabel htmlFor="demand-kind">Tipo</FieldLabel>
<NativeSelect
id="demand-kind"
name="kind"
defaultValue="material"
className="min-h-11 w-full"
>
{campaignDemandKinds.map((kind) => (
<NativeSelectOption key={kind} value={kind}>
{campaignDemandKindLabels[kind]}
</NativeSelectOption>
))}
</NativeSelect>
</Field>
<Field>
<FieldLabel htmlFor="demand-municipality">Município</FieldLabel>
<NativeSelect
id="demand-municipality"
name="municipalityId"
required
defaultValue=""
className="min-h-11 w-full"
>
<NativeSelectOption value="" disabled>
Selecione o município…
</NativeSelectOption>
{municipalityOptions.map((option) => (
<NativeSelectOption key={option.id} value={String(option.id)}>
{option.name}
</NativeSelectOption>
))}
</NativeSelect>
{fieldError(state.fieldErrors, 'municipality') ? (
<FieldError>{fieldError(state.fieldErrors, 'municipality')}</FieldError>
) : null}
</Field>
</div>
<Field>
<FieldLabel htmlFor="demand-description">Detalhe a necessidade</FieldLabel>
<Textarea id="demand-description" name="description" rows={4} maxLength={4000} />
{fieldError(state.fieldErrors, 'description') ? (
<FieldError>{fieldError(state.fieldErrors, 'description')}</FieldError>
) : null}
</Field>
{state.message && state.status !== 'success' ? (
<Alert variant="destructive">
<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}
Abrir demanda
</Button>
</form>
)
}