🎨 styles: change query tab logic in acc page

:%s
This commit is contained in:
lytrankieio123
2021-09-15 09:35:04 +07:00
parent c20150902e
commit cda96f21e3
2 changed files with 42 additions and 25 deletions

View File

@@ -1,41 +1,23 @@
import React, { useRef, useEffect, Children, ReactElement, PropsWithChildren, useState, cloneElement } from "react"
import s from './AccountNavigation.module.scss'
import AccountNavigationItem from './components/AccountNavigationItem/AccountNavigationItem'
import {TabPaneProps} from '../../../common/TabCommon/components/TabPane/TabPane'
import { ACCOUNT_TAB, QUERY_KEY } from "src/utils/constanst.utils"
import { useRouter } from "next/router"
interface AccountNavigationProps {
defaultActiveIndex: number;
children: React.ReactNode
}
const getTabIndex = (tab?: string): number => {
switch (tab) {
case ACCOUNT_TAB.CUSTOMER_INFO:
return 0;
case ACCOUNT_TAB.ORDER:
return 1;
case ACCOUNT_TAB.FAVOURITE:
return 2;
default:
return 0
}
}
const AccountNavigation = ({ defaultActiveIndex, children } : AccountNavigationProps) => {
const router = useRouter()
const [active, setActive] = useState(defaultActiveIndex)
const sliderRef = useRef<HTMLDivElement>(null);
const headerRef = useRef<HTMLUListElement>(null)
useEffect(() => {
const query = router.query[QUERY_KEY.TAB] as string
const index = getTabIndex(query)
setActive(index)
}, [router.query[QUERY_KEY.TAB]])
if (defaultActiveIndex !== undefined) {
setActive(defaultActiveIndex)
}
}, [defaultActiveIndex])
const onTabClick = (index: number) => {
setActive(index)