mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-15 02:23:07 +00:00
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.
77 lines
2.7 KiB
TypeScript
77 lines
2.7 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 DeclareVotesFormProps = {
|
|
municipalityID: number
|
|
/** Present when staff declare on behalf of a leadership. */
|
|
leadershipID?: number
|
|
currentDeclaredVotes: number | null
|
|
formAction: (
|
|
state: CampaignFormActionState,
|
|
formData: FormData,
|
|
) => Promise<CampaignFormActionState>
|
|
}
|
|
|
|
export const DeclareVotesForm = ({
|
|
municipalityID,
|
|
leadershipID,
|
|
currentDeclaredVotes,
|
|
formAction,
|
|
}: DeclareVotesFormProps) => {
|
|
const [state, submitAction, isPending] = useActionState(formAction, {})
|
|
|
|
return (
|
|
<form action={submitAction} className="flex flex-col gap-3">
|
|
<input type="hidden" name="municipalityId" value={municipalityID} />
|
|
{leadershipID !== undefined ? (
|
|
<input type="hidden" name="leadershipId" value={leadershipID} />
|
|
) : null}
|
|
<Field>
|
|
<FieldLabel htmlFor={`declare-votes-${municipalityID}-${leadershipID ?? 'own'}`}>
|
|
{leadershipID !== undefined
|
|
? 'Quantos votos a liderança traz neste município?'
|
|
: 'Quantos votos você está trazendo neste município?'}
|
|
</FieldLabel>
|
|
<div className="flex gap-2">
|
|
<Input
|
|
id={`declare-votes-${municipalityID}-${leadershipID ?? 'own'}`}
|
|
name="declaredVotes"
|
|
type="number"
|
|
min={0}
|
|
max={1000000}
|
|
required
|
|
inputMode="numeric"
|
|
defaultValue={currentDeclaredVotes ?? undefined}
|
|
className="min-h-11 w-36"
|
|
/>
|
|
<Button type="submit" disabled={isPending} className="min-h-11">
|
|
{isPending ? <Spinner data-icon="inline-start" aria-hidden="true" /> : null}
|
|
{currentDeclaredVotes == null ? 'Declarar' : 'Atualizar'}
|
|
</Button>
|
|
</div>
|
|
{fieldError(state.fieldErrors, 'declaredVotes') ? (
|
|
<FieldError>{fieldError(state.fieldErrors, 'declaredVotes')}</FieldError>
|
|
) : null}
|
|
</Field>
|
|
{state.message && state.status !== 'success' ? (
|
|
<Alert variant="destructive">
|
|
<AlertDescription>{state.message}</AlertDescription>
|
|
</Alert>
|
|
) : null}
|
|
{state.status === 'success' ? (
|
|
<Alert>
|
|
<AlertDescription>{state.message ?? 'Declaração registrada.'}</AlertDescription>
|
|
</Alert>
|
|
) : null}
|
|
</form>
|
|
)
|
|
}
|