diff --git a/src/components/campaign/leadership/WizardLeadershipStep.tsx b/src/components/campaign/leadership/WizardLeadershipStep.tsx index 89bf09fe..445ba04e 100644 --- a/src/components/campaign/leadership/WizardLeadershipStep.tsx +++ b/src/components/campaign/leadership/WizardLeadershipStep.tsx @@ -143,7 +143,7 @@ export const WizardLeadershipStep = ({ skip={skipConfig} trailingAction={trailingAction} 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} > {mode.kind === 'form' ? ( diff --git a/src/components/campaign/municipality/WizardSignalBodyStep.tsx b/src/components/campaign/municipality/WizardSignalBodyStep.tsx index c620841f..ad950b0b 100644 --- a/src/components/campaign/municipality/WizardSignalBodyStep.tsx +++ b/src/components/campaign/municipality/WizardSignalBodyStep.tsx @@ -21,7 +21,7 @@ import { wizardChainContinueHref, wizardChainEndHref, } from '@/lib/wizardActionChain' -import { wizardSignalBodyPreviousHref } from '@/lib/wizardBack' +import { wizardStepPreviousHref } from '@/lib/wizardBack' import { resolveWizardSignalSkip, WIZARD_SIGNAL_BODY_STEP_TITLE_PREFIX, @@ -68,13 +68,13 @@ export const WizardSignalBodyStep = ({ flowTitle={wizardFlowTitleForSlug(actionSlug)} isEntryStep={false} stepTitle={stepTitle} - previousHref={wizardSignalBodyPreviousHref( + previousHref={wizardStepPreviousHref({ + step: 'signal-body', actionSlug, municipalitySlug, - signalType, entryAction, returnPath, - )} + })} dismissHref={wizardChainEndHref(returnPath)} municipalityLabel={municipalityName} skip={skip} diff --git a/src/components/campaign/shared/CampaignWizardShell.tsx b/src/components/campaign/shared/CampaignWizardShell.tsx index 5a5f3e84..2bec7814 100644 --- a/src/components/campaign/shared/CampaignWizardShell.tsx +++ b/src/components/campaign/shared/CampaignWizardShell.tsx @@ -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. */ contentFocus?: 'title' | 'none' /** Client-only layer (e.g. leadership form) — Voltar / Android pop this before leaving the URL step. */ - clientLayer?: WizardClientLayer | null + clientLayer?: WizardClientLayer onPopClientLayer?: () => void children: ReactNode } @@ -44,7 +44,7 @@ export const CampaignWizardShell = ({ trailingAction, contentAlign = 'start', contentFocus = 'title', - clientLayer = null, + clientLayer, onPopClientLayer, children, }: CampaignWizardShellProps) => { @@ -56,7 +56,7 @@ export const CampaignWizardShell = ({ stepKind: isEntryStep ? 'entry' : 'continue', previousHref: isEntryStep ? undefined : previousHref, dismissHref, - clientLayer, + clientLayer: clientLayer ?? null, onPopClientLayer, }) diff --git a/src/components/campaign/shared/useWizardBackHistory.ts b/src/components/campaign/shared/useWizardBackHistory.ts index 60b26174..f8af31a6 100644 --- a/src/components/campaign/shared/useWizardBackHistory.ts +++ b/src/components/campaign/shared/useWizardBackHistory.ts @@ -35,7 +35,6 @@ export const useWizardBackHistory = ( const backPushedRef = useRef(false) const layerPushedRef = useRef(false) - const closingBackProgrammaticallyRef = useRef(false) const closingLayerProgrammaticallyRef = useRef(false) const onPopClientLayerRef = useRef(onPopClientLayer) const navigateHrefRef = useRef(dismissHref) @@ -133,12 +132,6 @@ export const useWizardBackHistory = ( return } - if (closingBackProgrammaticallyRef.current) { - closingBackProgrammaticallyRef.current = false - backPushedRef.current = false - return - } - if ( !shouldHandleWizardBackPopstate({ wasHistoryPushed: backPushedRef.current, diff --git a/src/lib/wizardBack.ts b/src/lib/wizardBack.ts index 7a8e95ef..2fdf896c 100644 --- a/src/lib/wizardBack.ts +++ b/src/lib/wizardBack.ts @@ -9,7 +9,6 @@ import { wizardTrendHref, type CampaignWizardActionId, } from '@/lib/campaignActionRoutes' -import type { MunicipalitySignalType } from '@/lib/schemas/municipalityUpdate' /** Synthetic history mark for URL-step / entry back interception. */ 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 => typeof state === 'object' && state !== null && - WIZARD_BACK_HISTORY_KEY in state && - (state as WizardBackHistoryState)[WIZARD_BACK_HISTORY_KEY] === true + (state as Record)[WIZARD_BACK_HISTORY_KEY] === true export const isWizardLayerHistoryState = ( state: unknown, ): state is WizardBackHistoryState & { [WIZARD_LAYER_HISTORY_KEY]: WizardClientLayer } => typeof state === 'object' && state !== null && - (state as WizardBackHistoryState)[WIZARD_LAYER_HISTORY_KEY] === WIZARD_LEADERSHIP_FORM_LAYER + (state as Record)[WIZARD_LAYER_HISTORY_KEY] === WIZARD_LEADERSHIP_FORM_LAYER /** * 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: { wasHistoryPushed: boolean diff --git a/tests/unit/wizardBack.unit.spec.ts b/tests/unit/wizardBack.unit.spec.ts index 7ddb3748..c6953f39 100644 --- a/tests/unit/wizardBack.unit.spec.ts +++ b/tests/unit/wizardBack.unit.spec.ts @@ -9,7 +9,6 @@ import { WIZARD_BACK_HISTORY_KEY, WIZARD_LAYER_HISTORY_KEY, WIZARD_LEADERSHIP_FORM_LAYER, - wizardSignalBodyPreviousHref, wizardStepPreviousHref, } from '@/lib/wizardBack' @@ -57,13 +56,12 @@ describe('wizardBack', () => { }) expect(search).toBe(`/campanha/acoes/${signalSlug}?from=%2Fcampanha`) - const type = wizardSignalBodyPreviousHref( - signalSlug, - 'cairu', - 'invasao', - undefined, - '/campanha', - ) + const type = wizardStepPreviousHref({ + step: 'signal-body', + actionSlug: signalSlug, + municipalitySlug: 'cairu', + returnPath: '/campanha', + }) expect(type).toBe(`/campanha/acoes/${signalSlug}?municipio=cairu&from=%2Fcampanha`) expect(