Skip to content

Commit

Permalink
refactor(app): do not show progress indication during drop tip wizard (
Browse files Browse the repository at this point in the history
…#16954)

Closes RQA-3643

Because drop tip flows is no longer deterministic, we shouldn't show the progress bar and step counter.
  • Loading branch information
mjhuff authored Nov 22, 2024
1 parent 8b2196a commit 64aaeb9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 84 deletions.
66 changes: 1 addition & 65 deletions app/src/organisms/DropTipWizardFlows/DropTipWizardHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { useState, useEffect } from 'react'
import { useTranslation } from 'react-i18next'

import { BEFORE_BEGINNING, BLOWOUT_SUCCESS, DT_ROUTES } from './constants'
import { WizardHeader } from '/app/molecules/WizardHeader'

import type { DropTipWizardProps } from './DropTipWizard'
import type { DropTipFlowsRoute, DropTipFlowsStep, ErrorDetails } from './types'
import type { ErrorDetails } from './types'

type DropTipWizardHeaderProps = DropTipWizardProps & {
isExitInitiated: boolean
Expand All @@ -16,9 +14,6 @@ type DropTipWizardHeaderProps = DropTipWizardProps & {

export function DropTipWizardHeader({
confirmExit,
currentStep,
currentRoute,
currentStepIdx,
isExitInitiated,
isFinalWizardStep,
errorDetails,
Expand All @@ -36,73 +31,14 @@ export function DropTipWizardHeader({
handleCleanUpAndClose,
})

const { totalSteps, currentStepNumber } = useSeenBlowoutSuccess({
currentStep,
currentRoute,
currentStepIdx,
})

return (
<WizardHeader
title={i18n.format(t('drop_tips'), 'capitalize')}
currentStep={currentStepNumber}
totalSteps={totalSteps}
onExit={!showConfirmExit ? wizardHeaderOnExit : null}
/>
)
}

interface UseSeenBlowoutSuccessProps {
currentStep: DropTipFlowsStep
currentRoute: DropTipFlowsRoute
currentStepIdx: number
}

interface UseSeenBlowoutSuccessResult {
currentStepNumber: number | null
totalSteps: number | null
}

// Calculate the props used for determining step count based on the route. Because blowout and drop tip are separate routes,
// there's a need for state to track whether we've seen blowout, so the step counter is accurate when the drop tip route is active.
export function useSeenBlowoutSuccess({
currentStep,
currentRoute,
currentStepIdx,
}: UseSeenBlowoutSuccessProps): UseSeenBlowoutSuccessResult {
const [hasSeenBlowoutSuccess, setHasSeenBlowoutSuccess] = useState(false)

useEffect(() => {
if (currentStep === BLOWOUT_SUCCESS) {
setHasSeenBlowoutSuccess(true)
} else if (currentStep === BEFORE_BEGINNING) {
setHasSeenBlowoutSuccess(false)
}
}, [currentStep])

const shouldRenderStepCounter = currentRoute !== DT_ROUTES.BEFORE_BEGINNING

let totalSteps: null | number
if (!shouldRenderStepCounter) {
totalSteps = null
} else if (currentRoute === DT_ROUTES.BLOWOUT || hasSeenBlowoutSuccess) {
totalSteps = DT_ROUTES.BLOWOUT.length + DT_ROUTES.DROP_TIP.length
} else {
totalSteps = currentRoute.length
}

let currentStepNumber: null | number
if (!shouldRenderStepCounter) {
currentStepNumber = null
} else if (hasSeenBlowoutSuccess && currentRoute === DT_ROUTES.DROP_TIP) {
currentStepNumber = DT_ROUTES.BLOWOUT.length + currentStepIdx + 1
} else {
currentStepNumber = currentStepIdx + 1
}

return { currentStepNumber, totalSteps }
}

export interface UseWizardExitHeaderProps {
isFinalStep: boolean
hasInitiatedExit: boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import type * as React from 'react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { renderHook, screen } from '@testing-library/react'
import { screen } from '@testing-library/react'

import { renderWithProviders } from '/app/__testing-utils__'
import { i18n } from '/app/i18n'
import { mockDropTipWizardContainerProps } from '../__fixtures__'
import {
useWizardExitHeader,
useSeenBlowoutSuccess,
DropTipWizardHeader,
} from '../DropTipWizardHeader'
import { DT_ROUTES } from '../constants'

import type { Mock } from 'vitest'
import type { UseWizardExitHeaderProps } from '../DropTipWizardHeader'
Expand All @@ -31,22 +29,6 @@ describe('DropTipWizardHeader', () => {
it('renders appropriate copy and onClick behavior', () => {
render(props)
screen.getByText('Drop tips')
screen.getByText('Step 1 / 5')
})
})

describe('useSeenBlowoutSuccess', () => {
it('should not render step counter when currentRoute is BEFORE_BEGINNING', () => {
const { result } = renderHook(() =>
useSeenBlowoutSuccess({
currentStep: 'SOME_STEP' as any,
currentRoute: DT_ROUTES.BEFORE_BEGINNING,
currentStepIdx: 0,
})
)

expect(result.current.totalSteps).toBe(null)
expect(result.current.currentStepNumber).toBe(null)
})
})

Expand Down

0 comments on commit 64aaeb9

Please sign in to comment.