teqo/src/components/campaign/tour/TourRegionPicker.tsx
Francisco Ignácio Fontoura Solla d5b4af2d98 E13: visit eligibility checklist and the tour composer.
Five conditions per município (volume, headroom, rede, janela, encaixe) with
their reason always visible, plus a staff-only composer at
/campanha/atividades/giros that turns an âncora + satélites + semente into draft
activities in one transaction. No `visita` kind and no `tour` entity:
`deputyPresent` already marks the candidate's own agenda.
2026-07-27 21:04:04 -03:00

72 lines
2.4 KiB
TypeScript

'use client'
import { useRouter } from 'next/navigation'
import { useTransition } from 'react'
import { Field, FieldDescription, FieldLabel } from '@/components/ui/field'
import { NativeSelect, NativeSelectOption } from '@/components/ui/native-select'
import { Spinner } from '@/components/ui/Spinner'
/**
* Each option arrives with its href already serialized by the RSC: the canonical
* serializer imports the identity-territory tables, and pulling those into the
* client bundle for one query param is exactly what B14 measured and rejected.
*/
type TourRegionOption = {
region: string
municipalityCount: number
href: string
}
/**
* Interaction 1 of 3: which identity territory the giro travels in. The list is
* the actor's own scope, so an advisor is never offered a território where they
* have nothing to open — and the count says why each option is there.
*/
export const TourRegionPicker = ({
regions,
selectedRegion,
clearHref,
}: {
regions: TourRegionOption[]
selectedRegion: string | null
clearHref: string
}) => {
const router = useRouter()
const [isPending, startTransition] = useTransition()
return (
<Field className="max-w-md">
<FieldLabel htmlFor="tour-region">Território de Identidade</FieldLabel>
<NativeSelect
id="tour-region"
value={selectedRegion ?? ''}
disabled={isPending}
onChange={(event) => {
const { value } = event.target
const href = regions.find((option) => option.region === value)?.href ?? clearHref
// The result renders below the picker, so the viewport stays put.
startTransition(() => router.push(href, { scroll: false }))
}}
className="min-h-11 w-full"
>
<NativeSelectOption value="">Selecione um território</NativeSelectOption>
{regions.map((option) => (
<NativeSelectOption key={option.region} value={option.region}>
{option.region} ({option.municipalityCount})
</NativeSelectOption>
))}
</NativeSelect>
<FieldDescription>
{isPending ? (
<span className="flex items-center gap-2">
<Spinner aria-hidden="true" />
Montando a proposta de giro…
</span>
) : (
'Um giro acontece dentro de um território. O número é quantos municípios dele você acompanha.'
)}
</FieldDescription>
</Field>
)
}