fix(back button): back button work with recovery phrase
This commit is contained in:
parent
8c4cb7bc6c
commit
d703904b68
|
@ -4,22 +4,35 @@ import { ArrowLeftIcon } from '@status-im/icons'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { FORM_STEPS, STEPPER_PATHS } from '../../../constants'
|
import { FORM_STEPS, STEPPER_PATHS } from '../../../constants'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { RootState } from '../../../redux/store'
|
||||||
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
|
import { setIsConfirmPhraseStage } from '../../../redux/ValidatorOnboarding/KeyGeneration/slice'
|
||||||
|
import { setActiveStep } from '../../../redux/ValidatorOnboarding/slice'
|
||||||
|
|
||||||
type BackButtonProps = {
|
const BackButton = () => {
|
||||||
prevPageIndex: number
|
const dispatch = useDispatch()
|
||||||
}
|
const isConfirmPhraseStage = useSelector(
|
||||||
|
(state: RootState) => state.keyGeneration.isConfirmPhraseStage,
|
||||||
const BackButton = ({ prevPageIndex }: BackButtonProps) => {
|
)
|
||||||
|
const { activeStep } = useSelector(
|
||||||
|
(state: RootState) => state.validatorOnboarding,
|
||||||
|
)
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const [buttonState, setButtonState] = useState<
|
const [buttonState, setButtonState] = useState<
|
||||||
'disabled' | 'enabled' | 'pressed'
|
'disabled' | 'enabled' | 'pressed'
|
||||||
>('disabled')
|
>('disabled')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setButtonState(prevPageIndex > 0 ? 'enabled' : 'disabled')
|
setButtonState(activeStep > 0 ? 'enabled' : 'disabled')
|
||||||
}, [prevPageIndex])
|
}, [activeStep])
|
||||||
|
|
||||||
const prevPageName = FORM_STEPS[prevPageIndex - 1]?.label || 'Back'
|
const prevPageName = () => {
|
||||||
|
let name = FORM_STEPS[activeStep - 1]?.label || 'Back'
|
||||||
|
if (activeStep === 7) {
|
||||||
|
name = 'Key Generation'
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
const handleMouseEnter = () => {
|
const handleMouseEnter = () => {
|
||||||
if (buttonState === 'enabled') {
|
if (buttonState === 'enabled') {
|
||||||
|
@ -44,10 +57,20 @@ const BackButton = ({ prevPageIndex }: BackButtonProps) => {
|
||||||
textColor: buttonState === 'disabled' ? 'CED4DB' : '09101C',
|
textColor: buttonState === 'disabled' ? 'CED4DB' : '09101C',
|
||||||
}
|
}
|
||||||
const handleNavigateBack = () => {
|
const handleNavigateBack = () => {
|
||||||
const prevPath =
|
|
||||||
STEPPER_PATHS[prevPageIndex - 2] || '/validator-onboarding/'
|
|
||||||
navigate(prevPath)
|
if (activeStep === 7 && isConfirmPhraseStage) {
|
||||||
|
|
||||||
|
dispatch(setIsConfirmPhraseStage(false))
|
||||||
|
navigate('/validator-onboarding/key-generation')
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
// Handle other cases as before
|
||||||
|
let prevPath = STEPPER_PATHS[activeStep - 1] || '/validator-onboarding/'
|
||||||
|
navigate(prevPath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<XStack
|
<XStack
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
|
@ -68,7 +91,7 @@ const BackButton = ({ prevPageIndex }: BackButtonProps) => {
|
||||||
<ArrowLeftIcon size={16} color={`#${buttonStyle.color}`} />
|
<ArrowLeftIcon size={16} color={`#${buttonStyle.color}`} />
|
||||||
</Stack>
|
</Stack>
|
||||||
<Text size={15} color={`#${buttonStyle.textColor}`} weight={'semibold'}>
|
<Text size={15} color={`#${buttonStyle.textColor}`} weight={'semibold'}>
|
||||||
{prevPageName}
|
{prevPageName()}
|
||||||
</Text>
|
</Text>
|
||||||
</XStack>
|
</XStack>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue