mirror of
https://github.com/fsolla/teqo.git
synced 2026-12-05 17:03:05 +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}
|
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' ? (
|
||||||
|
|
|
||||||
|
|
@ -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}
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue