Update Advisories.tsx

This commit is contained in:
Hristo Nedelkov 2023-10-21 18:51:45 +03:00
parent 03b874f961
commit 92bb610dfc
1 changed files with 14 additions and 10 deletions

View File

@ -3,25 +3,23 @@ import { useState, useEffect } from 'react'
import { Stack, XStack, YStack } from 'tamagui' import { Stack, XStack, YStack } from 'tamagui'
import AdvisoriesContent from './AdvisoriesContent' import AdvisoriesContent from './AdvisoriesContent'
import { useSelector } from 'react-redux' import { useDispatch, useSelector } from 'react-redux'
import { RootState } from '../../../redux/store' import { RootState } from '../../../redux/store'
import { setSubStepAdvisories } from '../../../redux/ValidatorOnboarding/Advisories/slice'
type AdvisoryTopicsType = { type AdvisoryTopicsType = {
[key: string]: string[] [key: string]: string[]
} }
const Advisories = () => { const Advisories = () => {
const dispatch = useDispatch();
const { subStepAdvisories } = useSelector((state: RootState) => state.advisories) const { subStepAdvisories } = useSelector((state: RootState) => state.advisories)
const [selectedTitle, setSelectedTitle] = useState(Object.keys(advisoryTopics)[0]) const [selectedTitle, setSelectedTitle] = useState(Object.keys(advisoryTopics)[0])
const unicodeNumbers = ['➀', '➁', '➂', '➃', '➄', '➅'] const unicodeNumbers = ['➀', '➁', '➂', '➃', '➄', '➅']
const advisoriesIcons = unicodeNumbers.map((number, index) => { const advisoriesIcons = unicodeNumbers.map((number, index) =>
if (selectedTitle === Object.keys(advisoryTopics)[index]) { index <= subStepAdvisories ? '✓' : number,
return '✓' )
} else {
return index <= subStepAdvisories ? '✓' : number
}
})
useEffect(() => { useEffect(() => {
setSelectedTitle(Object.keys(advisoryTopics)[subStepAdvisories]) setSelectedTitle(Object.keys(advisoryTopics)[subStepAdvisories])
@ -32,6 +30,12 @@ const Advisories = () => {
const index = topics.indexOf(currentTitle) const index = topics.indexOf(currentTitle)
return index <= subStepAdvisories ? true : false return index <= subStepAdvisories ? true : false
} }
const getIndexTitle = (title: string): number => {
const topics = Object.keys(advisoryTopics)
const index = topics.indexOf(title)
return index
}
return ( return (
<XStack <XStack
@ -48,7 +52,7 @@ const Advisories = () => {
{Object.keys(advisoryTopics).map((title, index) => ( {Object.keys(advisoryTopics).map((title, index) => (
<XStack <XStack
key={title} key={title}
onPress={() => setSelectedTitle(title)} onPress={() => dispatch(setSubStepAdvisories(getIndexTitle(title)))}
style={{ cursor: 'pointer', alignItems: 'center' }} style={{ cursor: 'pointer', alignItems: 'center' }}
space={'$2'} space={'$2'}
> >
@ -62,7 +66,7 @@ const Advisories = () => {
<Text <Text
size={19} size={19}
weight={isCurrent(title) ? 'semibold' : ''} weight={isCurrent(title) ? 'semibold' : ''}
color={title === selectedTitle ? 'blue' : isCurrent(title) ? 'blue' : ''} color={isCurrent(title) ? 'blue' : ''}
> >
{title} {title}
</Text> </Text>