fix(validator onboarding): implement back button functionality

This commit is contained in:
Hristo Nedelkov 2024-02-07 23:52:55 +02:00 committed by Emil Ivanichkov
parent 6e81f0d109
commit f93d68bc36
1 changed files with 9 additions and 5 deletions

View File

@ -2,13 +2,15 @@ import { Text } from '@status-im/components'
import { Stack, XStack } from 'tamagui' import { Stack, XStack } from 'tamagui'
import { ArrowLeftIcon } from '@status-im/icons' import { ArrowLeftIcon } from '@status-im/icons'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { FORM_STEPS } from '../../../constants' import { FORM_STEPS, STEPPER_PATHS } from '../../../constants'
import { useNavigate } from 'react-router-dom'
type BackButtonProps = { type BackButtonProps = {
prevPageIndex: number prevPageIndex: number
} }
const BackButton = ({ prevPageIndex }: BackButtonProps) => { const BackButton = ({ prevPageIndex }: BackButtonProps) => {
const navigate = useNavigate()
const [buttonState, setButtonState] = useState< const [buttonState, setButtonState] = useState<
'disabled' | 'enabled' | 'pressed' 'disabled' | 'enabled' | 'pressed'
>('disabled') >('disabled')
@ -41,15 +43,17 @@ const BackButton = ({ prevPageIndex }: BackButtonProps) => {
fill: buttonState === 'pressed' ? '2A4AF5' : '', fill: buttonState === 'pressed' ? '2A4AF5' : '',
textColor: buttonState === 'disabled' ? 'CED4DB' : '09101C', textColor: buttonState === 'disabled' ? 'CED4DB' : '09101C',
} }
const handleNavigateBack = () => {
const prevPath =
STEPPER_PATHS[prevPageIndex - 2] || '/validator-onboarding/'
navigate(prevPath)
}
return ( return (
<XStack <XStack
alignItems="center" alignItems="center"
space="$3" space="$3"
cursor={buttonState !== 'disabled' ? 'pointer' : 'default'} cursor={buttonState !== 'disabled' ? 'pointer' : 'default'}
onClick={() => onClick={() => buttonState !== 'disabled' && handleNavigateBack()}
buttonState !== 'disabled' && console.log('Back button clicked')
}
onMouseEnter={handleMouseEnter} onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave} onMouseLeave={handleMouseLeave}
> >