mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-26 21:53:06 +00:00
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:
parent
962d704a54
commit
e880299170
6 changed files with 17 additions and 44 deletions
|
|
@ -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' ? (
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<string, unknown>)[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<string, unknown>)[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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue