// ** React Imports import { SyntheticEvent, useEffect, useState } from 'react' // ** Next Imports import Link from 'next/link' import { useRouter } from 'next/router' // ** MUI Imports import Box from '@mui/material/Box' import Tab from '@mui/material/Tab' import Card from '@mui/material/Card' import TabPanel from '@mui/lab/TabPanel' import Button from '@mui/material/Button' import Divider from '@mui/material/Divider' import TabContext from '@mui/lab/TabContext' import { styled } from '@mui/material/styles' import Typography from '@mui/material/Typography' import CardContent from '@mui/material/CardContent' import MuiTabList, { TabListProps } from '@mui/lab/TabList' import CircularProgress from '@mui/material/CircularProgress' // ** Icon Imports import Icon from 'src/@core/components/icon' // ** Custom Components Import import CustomAvatar from 'src/@core/components/mui/avatar' // ** Types import { HelpCenterSubcategoriesType, HelpCenterSubcategoryArticlesType } from 'src/@fake-db/types' interface Props { articles: HelpCenterSubcategoryArticlesType[] activeSubcategory: HelpCenterSubcategoriesType activeArticle: HelpCenterSubcategoryArticlesType } const TabList = styled(MuiTabList)(({ theme }) => ({ border: 0, marginRight: 0, overflow: 'visible', '& .MuiTabs-flexContainer': { flexDirection: 'column' }, '& .MuiTabs-indicator': { display: 'none' }, '& .Mui-selected': { backgroundColor: theme.palette.primary.main, color: `${theme.palette.common.white} !important` }, '& .MuiTab-root': { minHeight: 40, minWidth: 300, maxWidth: 300, textAlign: 'start', flexDirection: 'row', justifyContent: 'flex-start', borderRadius: theme.shape.borderRadius, '& svg': { marginBottom: 0, marginRight: theme.spacing(1) }, [theme.breakpoints.down('md')]: { minWidth: '100%', maxWidth: '100%' } } })) const HelpCenterArticle = ({ articles, activeArticle, activeSubcategory }: Props) => { // ** State const [isLoading, setIsLoading] = useState(false) const [tabValue, setTabValue] = useState(activeArticle.slug) // ** Hooks const router = useRouter() const handleChange = (event: SyntheticEvent, newValue: string) => { setIsLoading(true) router .push({ pathname: `/pages/help-center/${router.query.category}/${router.query.subcategory}/${newValue}` }) .then(() => setIsLoading(false)) } useEffect(() => { if (activeArticle && activeArticle.slug !== tabValue) { setTabValue(activeArticle.slug) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [activeArticle]) const renderTabs = () => { return ( articles && articles.map((article: HelpCenterSubcategoryArticlesType) => ( )) ) } const renderContent = () => ( {activeArticle.title}
{activeArticle.title} 55 People found this helpful
Still need help? e.preventDefault()} sx={{ fontWeight: 600, color: 'primary.main', textDecoration: 'none' }} > Contact us?
) return ( {activeSubcategory.title} {renderTabs()} {isLoading ? ( Loading... ) : ( renderContent() )} ) } export default HelpCenterArticle