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

100 lines
3 KiB
TypeScript

'use client'
import { useEffect, useId, useMemo, useRef, type ReactNode } from 'react'
import { CampaignListResults } from '@/components/campaign/shared/CampaignListPending'
import {
toCampaignWizardChromeState,
useSetCampaignWizardChrome,
} from '@/components/campaign/shell/CampaignWizardChromeContext'
import { CAMPAIGN_HOME } from '@/lib/campaignPaths'
import { WIZARD_STEP_PENDING_MESSAGE, wizardFlowChromeAriaLabel } from '@/lib/campaignWizardCopy'
import { cn } from '@/lib/utils'
export type CampaignWizardShellProps = {
flowTitle: string
stepTitle?: string | null
isEntryStep: boolean
previousHref: string
dismissHref?: string
municipalityLabel?: string
contentAlign?: 'start' | 'end'
/** When `'none'`, the shell does not move focus to the step title — use on form steps that autofocus an input. */
contentFocus?: 'title' | 'none'
children: ReactNode
}
export const CampaignWizardShell = ({
flowTitle,
stepTitle,
isEntryStep,
previousHref,
dismissHref = CAMPAIGN_HOME,
municipalityLabel,
contentAlign = 'start',
contentFocus = 'title',
children,
}: CampaignWizardShellProps) => {
const hasStepTitle = stepTitle != null && stepTitle !== ''
const titleRef = useRef<HTMLHeadingElement>(null)
const titleId = useId()
const chrome = useMemo(
() =>
toCampaignWizardChromeState({
flowTitle,
isEntryStep,
previousHref,
dismissHref,
municipalityLabel,
}),
[dismissHref, flowTitle, isEntryStep, municipalityLabel, previousHref],
)
useSetCampaignWizardChrome(chrome)
useEffect(() => {
if (!hasStepTitle || contentFocus === 'none') return
titleRef.current?.focus()
}, [contentFocus, hasStepTitle, stepTitle])
return (
<div className="flex min-h-full w-full flex-col">
<main
aria-labelledby={hasStepTitle ? titleId : undefined}
aria-label={hasStepTitle ? undefined : wizardFlowChromeAriaLabel(flowTitle)}
className={cn(
'flex flex-1 flex-col pb-6 md:justify-start md:py-6',
hasStepTitle ? 'pt-3' : 'pt-2',
contentAlign === 'end' ? 'justify-end md:justify-start' : 'justify-start',
)}
>
<CampaignListResults
pendingMessage={WIZARD_STEP_PENDING_MESSAGE}
className={cn(
'flex flex-1 flex-col',
hasStepTitle ? 'gap-6' : 'gap-0',
contentAlign === 'end' ? 'justify-end md:justify-start' : 'justify-start',
)}
>
{municipalityLabel ? (
<p className="hidden max-w-prose truncate text-sm text-muted-foreground md:block">
{municipalityLabel}
</p>
) : null}
{hasStepTitle ? (
<h1
ref={titleRef}
id={titleId}
tabIndex={-1}
className="text-xl font-semibold tracking-tight outline-none md:text-2xl"
>
{stepTitle}
</h1>
) : null}
{children}
</CampaignListResults>
</main>
</div>
)
}