2024-01-29 16:40:11 -05:00
|
|
|
import React from 'react';
|
|
|
|
|
2024-02-16 13:38:00 -05:00
|
|
|
import { Box, Flex, Icon, Text, useColorModeValue } from '@chakra-ui/react';
|
2024-02-15 17:17:26 -05:00
|
|
|
import { FiBriefcase, FiHome, FiSettings, FiUsers } from 'react-icons/fi';
|
|
|
|
import { Link, useLocation } from 'react-router-dom';
|
2024-01-29 16:40:11 -05:00
|
|
|
|
2024-02-26 09:39:09 -05:00
|
|
|
import { useUserStore } from '../../store/user-store';
|
2024-02-16 13:38:00 -05:00
|
|
|
|
2024-01-29 16:40:11 -05:00
|
|
|
const items = [
|
|
|
|
{ icon: FiHome, title: 'Dashboard', path: "/" },
|
|
|
|
{ icon: FiBriefcase, title: 'Items', path: "/items" },
|
2024-02-12 16:46:51 -05:00
|
|
|
{ icon: FiSettings, title: 'User Settings', path: "/settings" },
|
2024-01-29 16:40:11 -05:00
|
|
|
];
|
|
|
|
|
2024-01-29 17:42:09 -05:00
|
|
|
interface SidebarItemsProps {
|
|
|
|
onClose?: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SidebarItems: React.FC<SidebarItemsProps> = ({ onClose }) => {
|
2024-02-16 13:38:00 -05:00
|
|
|
const textColor = useColorModeValue("ui.main", "#E2E8F0");
|
|
|
|
const bgActive = useColorModeValue("#E2E8F0", "#4A5568");
|
2024-02-15 17:17:26 -05:00
|
|
|
const location = useLocation();
|
2024-02-16 13:38:00 -05:00
|
|
|
const { user } = useUserStore();
|
|
|
|
|
|
|
|
const finalItems = user?.is_superuser ? [...items, { icon: FiUsers, title: 'Admin', path: "/admin" }] : items;
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-02-16 13:38:00 -05:00
|
|
|
const listItems = finalItems.map((item) => (
|
2024-02-15 17:17:26 -05:00
|
|
|
<Flex
|
|
|
|
as={Link}
|
|
|
|
to={item.path}
|
|
|
|
w="100%"
|
|
|
|
p={2}
|
|
|
|
key={item.title}
|
|
|
|
style={location.pathname === item.path ? {
|
2024-02-16 13:38:00 -05:00
|
|
|
background: bgActive,
|
2024-02-15 17:17:26 -05:00
|
|
|
borderRadius: "12px",
|
|
|
|
} : {}}
|
2024-02-16 13:38:00 -05:00
|
|
|
color={textColor}
|
2024-02-15 17:17:26 -05:00
|
|
|
onClick={onClose}
|
|
|
|
>
|
|
|
|
<Icon as={item.icon} alignSelf="center" />
|
|
|
|
<Text ml={2}>{item.title}</Text>
|
2024-01-29 16:40:11 -05:00
|
|
|
</Flex>
|
|
|
|
));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-02-15 17:17:26 -05:00
|
|
|
<Box>
|
|
|
|
{listItems}
|
|
|
|
</Box>
|
2024-02-16 13:38:00 -05:00
|
|
|
|
2024-01-29 16:40:11 -05:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SidebarItems;
|