Files
full-stack-fastapi-template/frontend/src/components/Common/SidebarItems.tsx

58 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-03-08 14:58:36 +01:00
import React from 'react'
import { Box, Flex, Icon, Text, useColorModeValue } from '@chakra-ui/react'
import { FiBriefcase, FiHome, FiSettings, FiUsers } from 'react-icons/fi'
import { Link } from '@tanstack/react-router'
import { useQueryClient } from 'react-query'
2024-01-29 16:40:11 -05:00
2024-03-08 14:58:36 +01:00
import { UserOut } from '../../client'
2024-01-29 16:40:11 -05:00
const items = [
2024-03-08 14:58:36 +01:00
{ icon: FiHome, title: 'Dashboard', path: '/' },
{ icon: FiBriefcase, title: 'Items', path: '/items' },
{ icon: FiSettings, title: 'User Settings', path: '/settings' },
]
2024-01-29 16:40:11 -05:00
interface SidebarItemsProps {
2024-03-08 14:58:36 +01:00
onClose?: () => void
}
const SidebarItems: React.FC<SidebarItemsProps> = ({ onClose }) => {
2024-03-08 14:58:36 +01:00
const queryClient = useQueryClient()
2024-03-11 17:56:59 +01:00
const textColor = useColorModeValue('ui.main', 'ui.white')
2024-03-08 14:58:36 +01:00
const bgActive = useColorModeValue('#E2E8F0', '#4A5568')
const currentUser = queryClient.getQueryData<UserOut>('currentUser')
const finalItems = currentUser?.is_superuser
? [...items, { icon: FiUsers, title: 'Admin', path: '/admin' }]
: items
const listItems = finalItems.map((item) => (
<Flex
as={Link}
to={item.path}
w="100%"
p={2}
key={item.title}
activeProps={{
style: {
background: bgActive,
borderRadius: '12px',
},
}}
color={textColor}
onClick={onClose}
>
<Icon as={item.icon} alignSelf="center" />
<Text ml={2}>{item.title}</Text>
</Flex>
))
return (
<>
<Box>{listItems}</Box>
</>
)
}
export default SidebarItems