teqo-backup/src/components/campaign/municipality/WizardTrendChoiceStep.tsx
fsolla 7faf3ed27f feat(campanha): B168 — desfazer encadeamento automático das ações rápidas do wizard
Ações de ajuste (votos, tendência, atualização, liderança) agora retornam à
origem ao salvar (toast + from allowlist B110 / Início), sem avançar sozinhas
para outro wizard. Removidos fila de encadeamento (wizardActionChain.ts),
param entry, skip/Pular (chrome mobile sempre X) e prefill de nota sem
produtor. Liderança: botão pós-save 'Continuar' → 'Concluir' (origem).
Sem migration.
2026-08-08 14:10:47 -03:00

126 lines
4.4 KiB
TypeScript

'use client'
import { Info } from 'lucide-react'
import { useState } from 'react'
import { CampaignWizardNavLink } from '@/components/campaign/shared/CampaignWizardNavLink'
import { CampaignWizardShell } from '@/components/campaign/shared/CampaignWizardShell'
import { Button } from '@/components/ui/button'
import {
Drawer,
DrawerCloseButton,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
} from '@/components/ui/Drawer'
import { wizardPreviousHref, wizardReturnHref, wizardTrendHref } from '@/lib/campaignActionRoutes'
import { wizardFlowTitleForSlug } from '@/lib/campaignWizardCopy'
import {
politicalTrendWizardMetaByStatus,
type PoliticalTrendWizardMetaEntry,
} from '@/lib/politicalTrendWizardMeta'
import {
selectablePoliticalTrendStatuses,
wizardTrendChoiceStepTitle,
} from '@/lib/politicalTrendWizardUi'
import type { PoliticalTrendStatusValue } from '@/lib/schemas/municipality'
import { cn } from '@/lib/utils'
type WizardTrendChoiceStepProps = {
actionSlug: string
municipalityName: string
municipalitySlug: string
currentStatus: PoliticalTrendStatusValue | null
returnPath?: string
}
export const WizardTrendChoiceStep = ({
actionSlug,
municipalityName,
municipalitySlug,
currentStatus,
returnPath,
}: WizardTrendChoiceStepProps) => {
const [infoEntry, setInfoEntry] = useState<PoliticalTrendWizardMetaEntry | null>(null)
const options = selectablePoliticalTrendStatuses(currentStatus)
return (
<>
<CampaignWizardShell
flowTitle={wizardFlowTitleForSlug(actionSlug)}
isEntryStep={false}
stepTitle={wizardTrendChoiceStepTitle(currentStatus)}
previousHref={wizardPreviousHref({
actionSlug,
stepKind: 'trend-choice',
municipalitySlug,
returnPath,
})}
dismissHref={wizardReturnHref(returnPath)}
municipalityLabel={municipalityName}
>
<ul className="grid list-none grid-cols-2 gap-3 md:grid-cols-3">
{options.map((status) => {
const entry = politicalTrendWizardMetaByStatus[status]
const Icon = entry.icon
return (
<li key={status} className="relative">
<CampaignWizardNavLink
href={wizardTrendHref(actionSlug, municipalitySlug, status, returnPath)}
className={cn(
'flex aspect-square w-full flex-col justify-between rounded-lg border bg-background p-3 pr-10 text-left',
entry.tileClassName,
'transition-colors hover:bg-muted/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
)}
>
<Icon className="size-5 shrink-0" aria-hidden />
<div className="flex flex-col gap-0.5">
<span className="text-sm font-medium">{entry.label}</span>
<span className="line-clamp-2 text-xs opacity-80">
{entry.changeDescription}
</span>
</div>
</CampaignWizardNavLink>
<Button
type="button"
variant="ghost"
size="icon"
className="absolute right-1 top-1 size-8"
aria-label={`Informações sobre ${entry.label}`}
onClick={(event) => {
event.preventDefault()
event.stopPropagation()
setInfoEntry(entry)
}}
>
<Info className="size-4" aria-hidden />
</Button>
</li>
)
})}
</ul>
</CampaignWizardShell>
<Drawer open={infoEntry != null} onOpenChange={(open) => !open && setInfoEntry(null)}>
<DrawerContent>
{infoEntry ? (
<>
<DrawerHeader>
<DrawerTitle>{infoEntry.label}</DrawerTitle>
<DrawerDescription>{infoEntry.changeDescription}</DrawerDescription>
</DrawerHeader>
<div className="px-4 pb-2">
<p className="text-sm text-muted-foreground">{infoEntry.infoContent}</p>
</div>
<DrawerFooter>
<DrawerCloseButton>Fechar</DrawerCloseButton>
</DrawerFooter>
</>
) : null}
</DrawerContent>
</Drawer>
</>
)
}