B114: simplify wizardBack — drop dead wrappers and back-close path

Remove single-use signal-body helper; drop unused programmatic URL-back
flag; keep history marks and layer pop path.

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-08-01 23:59:01 +00:00
parent 962d704a54
commit e880299170
No known key found for this signature in database
6 changed files with 17 additions and 44 deletions

View file

@ -143,7 +143,7 @@ export const WizardLeadershipStep = ({
skip={skipConfig} skip={skipConfig}
trailingAction={trailingAction} trailingAction={trailingAction}
contentFocus={mode.kind === 'form' ? 'none' : 'title'} contentFocus={mode.kind === 'form' ? 'none' : 'title'}
clientLayer={mode.kind === 'form' ? WIZARD_LEADERSHIP_FORM_LAYER : null} clientLayer={mode.kind === 'form' ? WIZARD_LEADERSHIP_FORM_LAYER : undefined}
onPopClientLayer={handlePopFormLayer} onPopClientLayer={handlePopFormLayer}
> >
{mode.kind === 'form' ? ( {mode.kind === 'form' ? (

View file

@ -21,7 +21,7 @@ import {
wizardChainContinueHref, wizardChainContinueHref,
wizardChainEndHref, wizardChainEndHref,
} from '@/lib/wizardActionChain' } from '@/lib/wizardActionChain'
import { wizardSignalBodyPreviousHref } from '@/lib/wizardBack' import { wizardStepPreviousHref } from '@/lib/wizardBack'
import { import {
resolveWizardSignalSkip, resolveWizardSignalSkip,
WIZARD_SIGNAL_BODY_STEP_TITLE_PREFIX, WIZARD_SIGNAL_BODY_STEP_TITLE_PREFIX,
@ -68,13 +68,13 @@ export const WizardSignalBodyStep = ({
flowTitle={wizardFlowTitleForSlug(actionSlug)} flowTitle={wizardFlowTitleForSlug(actionSlug)}
isEntryStep={false} isEntryStep={false}
stepTitle={stepTitle} stepTitle={stepTitle}
previousHref={wizardSignalBodyPreviousHref( previousHref={wizardStepPreviousHref({
step: 'signal-body',
actionSlug, actionSlug,
municipalitySlug, municipalitySlug,
signalType,
entryAction, entryAction,
returnPath, returnPath,
)} })}
dismissHref={wizardChainEndHref(returnPath)} dismissHref={wizardChainEndHref(returnPath)}
municipalityLabel={municipalityName} municipalityLabel={municipalityName}
skip={skip} skip={skip}

View file

@ -28,7 +28,7 @@ export type CampaignWizardShellProps = {
/** When `'none'`, the shell does not move focus to the step title — use on form steps that autofocus an input. */ /** When `'none'`, the shell does not move focus to the step title — use on form steps that autofocus an input. */
contentFocus?: 'title' | 'none' contentFocus?: 'title' | 'none'
/** Client-only layer (e.g. leadership form) — Voltar / Android pop this before leaving the URL step. */ /** Client-only layer (e.g. leadership form) — Voltar / Android pop this before leaving the URL step. */
clientLayer?: WizardClientLayer | null clientLayer?: WizardClientLayer
onPopClientLayer?: () => void onPopClientLayer?: () => void
children: ReactNode children: ReactNode
} }
@ -44,7 +44,7 @@ export const CampaignWizardShell = ({
trailingAction, trailingAction,
contentAlign = 'start', contentAlign = 'start',
contentFocus = 'title', contentFocus = 'title',
clientLayer = null, clientLayer,
onPopClientLayer, onPopClientLayer,
children, children,
}: CampaignWizardShellProps) => { }: CampaignWizardShellProps) => {
@ -56,7 +56,7 @@ export const CampaignWizardShell = ({
stepKind: isEntryStep ? 'entry' : 'continue', stepKind: isEntryStep ? 'entry' : 'continue',
previousHref: isEntryStep ? undefined : previousHref, previousHref: isEntryStep ? undefined : previousHref,
dismissHref, dismissHref,
clientLayer, clientLayer: clientLayer ?? null,
onPopClientLayer, onPopClientLayer,
}) })

View file

@ -35,7 +35,6 @@ export const useWizardBackHistory = (
const backPushedRef = useRef(false) const backPushedRef = useRef(false)
const layerPushedRef = useRef(false) const layerPushedRef = useRef(false)
const closingBackProgrammaticallyRef = useRef(false)
const closingLayerProgrammaticallyRef = useRef(false) const closingLayerProgrammaticallyRef = useRef(false)
const onPopClientLayerRef = useRef(onPopClientLayer) const onPopClientLayerRef = useRef(onPopClientLayer)
const navigateHrefRef = useRef(dismissHref) const navigateHrefRef = useRef(dismissHref)
@ -133,12 +132,6 @@ export const useWizardBackHistory = (
return return
} }
if (closingBackProgrammaticallyRef.current) {
closingBackProgrammaticallyRef.current = false
backPushedRef.current = false
return
}
if ( if (
!shouldHandleWizardBackPopstate({ !shouldHandleWizardBackPopstate({
wasHistoryPushed: backPushedRef.current, wasHistoryPushed: backPushedRef.current,

View file

@ -9,7 +9,6 @@ import {
wizardTrendHref, wizardTrendHref,
type CampaignWizardActionId, type CampaignWizardActionId,
} from '@/lib/campaignActionRoutes' } from '@/lib/campaignActionRoutes'
import type { MunicipalitySignalType } from '@/lib/schemas/municipalityUpdate'
/** Synthetic history mark for URL-step / entry back interception. */ /** Synthetic history mark for URL-step / entry back interception. */
export const WIZARD_BACK_HISTORY_KEY = 'teqoWizardBack' as const export const WIZARD_BACK_HISTORY_KEY = 'teqoWizardBack' as const
@ -106,38 +105,21 @@ export const wizardStepPreviousHref = (input: WizardStepPreviousHrefInput): stri
} }
} }
/** `signalType` is unused for previous — body always returns to the type step. */
export const wizardSignalBodyPreviousHref = (
actionSlug: string,
municipalitySlug: string,
_signalType: MunicipalitySignalType,
entryAction?: CampaignWizardActionId,
returnPath?: string,
): string =>
wizardStepPreviousHref({
step: 'signal-body',
actionSlug,
municipalitySlug,
entryAction,
returnPath,
})
export const isWizardBackHistoryState = (state: unknown): state is WizardBackHistoryState => export const isWizardBackHistoryState = (state: unknown): state is WizardBackHistoryState =>
typeof state === 'object' && typeof state === 'object' &&
state !== null && state !== null &&
WIZARD_BACK_HISTORY_KEY in state && (state as Record<string, unknown>)[WIZARD_BACK_HISTORY_KEY] === true
(state as WizardBackHistoryState)[WIZARD_BACK_HISTORY_KEY] === true
export const isWizardLayerHistoryState = ( export const isWizardLayerHistoryState = (
state: unknown, state: unknown,
): state is WizardBackHistoryState & { [WIZARD_LAYER_HISTORY_KEY]: WizardClientLayer } => ): state is WizardBackHistoryState & { [WIZARD_LAYER_HISTORY_KEY]: WizardClientLayer } =>
typeof state === 'object' && typeof state === 'object' &&
state !== null && state !== null &&
(state as WizardBackHistoryState)[WIZARD_LAYER_HISTORY_KEY] === WIZARD_LEADERSHIP_FORM_LAYER (state as Record<string, unknown>)[WIZARD_LAYER_HISTORY_KEY] === WIZARD_LEADERSHIP_FORM_LAYER
/** /**
* After popstate, handle when we had pushed a synthetic wizard entry and * After popstate, handle when we had pushed a synthetic wizard entry and
* are not closing that entry ourselves (header dismiss cleanup). * are not closing that entry ourselves.
*/ */
export const shouldHandleWizardBackPopstate = (input: { export const shouldHandleWizardBackPopstate = (input: {
wasHistoryPushed: boolean wasHistoryPushed: boolean

View file

@ -9,7 +9,6 @@ import {
WIZARD_BACK_HISTORY_KEY, WIZARD_BACK_HISTORY_KEY,
WIZARD_LAYER_HISTORY_KEY, WIZARD_LAYER_HISTORY_KEY,
WIZARD_LEADERSHIP_FORM_LAYER, WIZARD_LEADERSHIP_FORM_LAYER,
wizardSignalBodyPreviousHref,
wizardStepPreviousHref, wizardStepPreviousHref,
} from '@/lib/wizardBack' } from '@/lib/wizardBack'
@ -57,13 +56,12 @@ describe('wizardBack', () => {
}) })
expect(search).toBe(`/campanha/acoes/${signalSlug}?from=%2Fcampanha`) expect(search).toBe(`/campanha/acoes/${signalSlug}?from=%2Fcampanha`)
const type = wizardSignalBodyPreviousHref( const type = wizardStepPreviousHref({
signalSlug, step: 'signal-body',
'cairu', actionSlug: signalSlug,
'invasao', municipalitySlug: 'cairu',
undefined, returnPath: '/campanha',
'/campanha', })
)
expect(type).toBe(`/campanha/acoes/${signalSlug}?municipio=cairu&from=%2Fcampanha`) expect(type).toBe(`/campanha/acoes/${signalSlug}?municipio=cairu&from=%2Fcampanha`)
expect( expect(