Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Migrate to RouterProvider and other refactors #598

Merged
merged 12 commits into from
Feb 15, 2024
42 changes: 0 additions & 42 deletions src/new-frontend/src/App.css

This file was deleted.

61 changes: 0 additions & 61 deletions src/new-frontend/src/App.tsx

This file was deleted.

Binary file removed src/new-frontend/src/assets/images/fastapi-logo.png
Binary file not shown.
51 changes: 51 additions & 0 deletions src/new-frontend/src/assets/images/fastapi-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/new-frontend/src/assets/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/new-frontend/src/components/ActionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Button, Menu, MenuButton, MenuItem, MenuList, useDisclosure } from '@ch
import { BsThreeDotsVertical } from 'react-icons/bs';
import { FiTrash, FiEdit } from 'react-icons/fi';

import Delete from '../pages/modals/DeleteAlert';
import EditUser from '../pages/modals/EditUser';
import EditItem from '../pages/modals/EditItem';
import Delete from '../modals/DeleteAlert';
import EditUser from '../modals/EditUser';
import EditItem from '../modals/EditItem';

interface ActionsMenuProps {
type: string;
Expand Down
30 changes: 18 additions & 12 deletions src/new-frontend/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
import React from 'react';

import { Button, Flex, Icon, useDisclosure } from '@chakra-ui/react';
import { FaPlus } from "react-icons/fa";
import { Button, Flex, Icon, Input, InputGroup, InputLeftElement, useDisclosure } from '@chakra-ui/react';
import { FaPlus, FaSearch } from "react-icons/fa";

import CreateItem from '../pages/modals/CreateItem';
import CreateUser from '../pages/modals/CreateUser';
import AddUser from '../modals/AddUser';
import AddItem from '../modals/AddItem';

interface NavbarProps {
type: string;
}

const Navbar: React.FC<NavbarProps> = ({ type }) => {
const createUserModal = useDisclosure();
const createItemModal = useDisclosure();
const addUserModal = useDisclosure();
const addItemModal = useDisclosure();

return (
<>
<Flex gap={4} py={{ base: "8", md: "4" }} justify={{ base: "center", md: "end" }}>
<Button bg="ui.main" color="white" gap={1} fontSize={{ base: "sm", md: "inherit" }} onClick={type === "User" ? createUserModal.onOpen : createItemModal.onOpen}>
<Icon as={FaPlus} /> Create {type}
<Flex py={8} gap={4}>
<InputGroup w={{ base: "100%", md: "auto" }}>
<InputLeftElement pointerEvents="none">
<Icon as={FaSearch} color="gray.400" />
</InputLeftElement>
<Input type="text" placeholder="Search" fontSize={{ base: "sm", md: "inherit" }} borderRadius="8px" />
</InputGroup>
<Button bg="ui.main" color="white" _hover={{ opacity: 0.8 }} gap={1} fontSize={{ base: "sm", md: "inherit" }} onClick={type === "User" ? addUserModal.onOpen : addItemModal.onOpen}>
<Icon as={FaPlus} /> Add {type}
</Button>
<CreateUser isOpen={createUserModal.isOpen} onClose={createUserModal.onClose} />
<CreateItem isOpen={createItemModal.isOpen} onClose={createItemModal.onClose} />
</Flex>
<AddUser isOpen={addUserModal.isOpen} onClose={addUserModal.onClose} />
<AddItem isOpen={addItemModal.isOpen} onClose={addItemModal.onClose} />
</Flex >
</>
);
};
Expand Down
25 changes: 16 additions & 9 deletions src/new-frontend/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React from 'react';

import { Box, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerOverlay, Flex, IconButton, Image, useDisclosure } from '@chakra-ui/react';
import { Box, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerOverlay, Flex, IconButton, Image, useDisclosure, Text } from '@chakra-ui/react';
import { FiMenu } from 'react-icons/fi';

import Logo from "../assets/images/fastapi-logo.png";
import Logo from "../assets/images/fastapi-logo.svg";
import SidebarItems from './SidebarItems';
import UserInfo from './UserInfo';
import { useUserStore } from '../store/user-store';


const Sidebar: React.FC = () => {
const { isOpen, onOpen, onClose } = useDisclosure();
const { user } = useUserStore();

return (
<>
Expand All @@ -20,25 +21,31 @@ const Sidebar: React.FC = () => {
<DrawerContent bg="ui.secondary" maxW="250px">
<DrawerCloseButton />
<DrawerBody py={8}>
<Flex flexDir="column" justify="space-between" h="100%">
<Flex flexDir="column" justify="space-between">
<Box>
<Image src={Logo} alt="Logo" />
<Image src={Logo} alt="Logo" p={6} />
<SidebarItems onClose={onClose} />
</Box>
<UserInfo />
{
user?.email &&
<Text color='gray' noOfLines={2} fontSize="sm" p={2}>Logged in as: {user.email}</Text>
}
</Flex>
</DrawerBody>
</DrawerContent>
</Drawer>

{/* Desktop */}
<Box bg="white" p={3} h="100vh" position="sticky" top="0" display={{ base: 'none', md: 'flex' }}>
<Flex flexDir="column" justify="space-between" bg="ui.secondary" p={6} borderRadius={12}>
<Flex flexDir="column" justify="space-between" bg="ui.secondary" p={4} borderRadius={12}>
<Box>
<Image src={Logo} alt="Logo" w="180px" maxW="2xs" />
<Image src={Logo} alt="Logo" w="180px" maxW="2xs" p={6} />
<SidebarItems />
</Box>
<UserInfo />
{
user?.email &&
<Text color='gray' noOfLines={2} fontSize="sm" p={2} maxW="180px">Logged in as: {user.email}</Text>
}
</Flex>
</Box>
</>
Expand Down
47 changes: 23 additions & 24 deletions src/new-frontend/src/components/SidebarItems.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
import React from 'react';

import { Flex, Icon, Text } from '@chakra-ui/react';
import { FiBriefcase, FiHome, FiLogOut, FiSettings, FiUsers } from 'react-icons/fi';
import { Link, useNavigate } from 'react-router-dom';

import { Box, Flex, Icon, Text } from '@chakra-ui/react';
import { FiBriefcase, FiHome, FiSettings, FiUsers } from 'react-icons/fi';
import { Link, useLocation } from 'react-router-dom';

const items = [
{ icon: FiHome, title: 'Dashboard', path: "/" },
{ icon: FiBriefcase, title: 'Items', path: "/items" },
{ icon: FiUsers, title: 'Admin', path: "/admin" },
{ icon: FiSettings, title: 'User Settings', path: "/settings" },
{ icon: FiLogOut, title: 'Log out' }
];

interface SidebarItemsProps {
onClose?: () => void;
}

const SidebarItems: React.FC<SidebarItemsProps> = ({ onClose }) => {
const navigate = useNavigate();

const handleLogout = async () => {
localStorage.removeItem("access_token");
navigate("/login");
// TODO: reset all Zustand states
};
const location = useLocation();

const listItems = items.map((item) => (
<Flex w="100%" p={2} key={item.title} _hover={{
background: "gray.200",
borderRadius: "12px",
}} onClick={item.title === 'Log out' ? handleLogout : onClose}>
<Link to={item.path || "/"}>
<Flex gap={4}>
<Icon color="ui.main" as={item.icon} alignSelf="center" />
<Text>{item.title}</Text>

</Flex>
</Link>
<Flex
as={Link}
to={item.path}
w="100%"
p={2}
key={item.title}
style={location.pathname === item.path ? {
background: "#E2E8F0",
borderRadius: "12px",
} : {}}
color="ui.main"
onClick={onClose}
>
<Icon as={item.icon} alignSelf="center" />
<Text ml={2}>{item.title}</Text>
</Flex>
));

return (
<>
{listItems}
<Box>
{listItems}
</Box>

</>
);
};
Expand Down
29 changes: 0 additions & 29 deletions src/new-frontend/src/components/UserInfo.tsx

This file was deleted.

Loading