Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/new-frontend/src/components/ActionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ActionsMenu: React.FC<ActionsMenuProps> = ({ type, id }) => {
return (
<>
<Menu>
<MenuButton as={Button} bg="white" rightIcon={<BsThreeDotsVertical />} variant="unstyled">
<MenuButton as={Button} rightIcon={<BsThreeDotsVertical />} variant="unstyled">
</MenuButton>
<MenuList>
<MenuItem onClick={editUserModal.onOpen} icon={<FiEdit fontSize="16px" />}>Edit {type}</MenuItem>
Expand Down
16 changes: 10 additions & 6 deletions src/new-frontend/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

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

import Logo from "../assets/images/fastapi-logo.svg";
Expand All @@ -9,6 +9,10 @@ import { useUserStore } from '../store/user-store';


const Sidebar: React.FC = () => {
const bgColor = useColorModeValue("white", "#1a202c");
const textColor = useColorModeValue("gray", "white");
const secBgColor = useColorModeValue("ui.secondary", "#252d3d");

const { isOpen, onOpen, onClose } = useDisclosure();
const { user } = useUserStore();

Expand All @@ -18,7 +22,7 @@ const Sidebar: React.FC = () => {
<IconButton onClick={onOpen} display={{ base: 'flex', md: 'none' }} aria-label="Open Menu" position="absolute" fontSize='20px' m={4} icon={<FiMenu />} />
<Drawer isOpen={isOpen} placement="left" onClose={onClose}>
<DrawerOverlay />
<DrawerContent bg="ui.secondary" maxW="250px">
<DrawerContent maxW="250px">
<DrawerCloseButton />
<DrawerBody py={8}>
<Flex flexDir="column" justify="space-between">
Expand All @@ -28,23 +32,23 @@ const Sidebar: React.FC = () => {
</Box>
{
user?.email &&
<Text color='gray' noOfLines={2} fontSize="sm" p={2}>Logged in as: {user.email}</Text>
<Text color={textColor} 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={4} borderRadius={12}>
<Box bg={bgColor} p={3} h="100vh" position="sticky" top="0" display={{ base: 'none', md: 'flex' }}>
<Flex flexDir="column" justify="space-between" bg={secBgColor} p={4} borderRadius={12}>
<Box>
<Image src={Logo} alt="Logo" w="180px" maxW="2xs" p={6} />
<SidebarItems />
</Box>
{
user?.email &&
<Text color='gray' noOfLines={2} fontSize="sm" p={2} maxW="180px">Logged in as: {user.email}</Text>
<Text color={textColor} noOfLines={2} fontSize="sm" p={2} maxW="180px">Logged in as: {user.email}</Text>
}
</Flex>
</Box>
Expand Down
18 changes: 12 additions & 6 deletions src/new-frontend/src/components/SidebarItems.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';

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

import { useUserStore } from '../store/user-store';

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" },
];

Expand All @@ -16,20 +17,25 @@ interface SidebarItemsProps {
}

const SidebarItems: React.FC<SidebarItemsProps> = ({ onClose }) => {
const textColor = useColorModeValue("ui.main", "#E2E8F0");
const bgActive = useColorModeValue("#E2E8F0", "#4A5568");
const location = useLocation();
const { user } = useUserStore();

const finalItems = user?.is_superuser ? [...items, { icon: FiUsers, title: 'Admin', path: "/admin" }] : items;

const listItems = items.map((item) => (
const listItems = finalItems.map((item) => (
<Flex
as={Link}
to={item.path}
w="100%"
p={2}
key={item.title}
style={location.pathname === item.path ? {
background: "#E2E8F0",
background: bgActive,
borderRadius: "12px",
} : {}}
color="ui.main"
color={textColor}
onClick={onClose}
>
<Icon as={item.icon} alignSelf="center" />
Expand All @@ -42,7 +48,7 @@ const SidebarItems: React.FC<SidebarItemsProps> = ({ onClose }) => {
<Box>
{listItems}
</Box>

</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/new-frontend/src/components/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const UserMenu: React.FC = () => {
<MenuItem icon={<FiUser fontSize="18px" />} as={Link} to="settings">
My profile
</MenuItem>
<MenuItem icon={<FiLogOut fontSize="18px" />} onClick={handleLogout} color="ui.danger">
<MenuItem icon={<FiLogOut fontSize="18px" />} onClick={handleLogout} color="ui.danger" fontWeight="bold">
Log out
</MenuItem>
</MenuList>
Expand Down
2 changes: 1 addition & 1 deletion src/new-frontend/src/modals/DeleteAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const Delete: React.FC<DeleteProps> = ({ type, id, isOpen, onClose }) => {
>
<AlertDialogOverlay>
<AlertDialogContent as="form" onSubmit={handleSubmit(onSubmit)}>
<AlertDialogHeader fontSize='lg' fontWeight='bold'>
<AlertDialogHeader>
Delete {type}
</AlertDialogHeader>

Expand Down
72 changes: 72 additions & 0 deletions src/new-frontend/src/modals/DeleteConfirmation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React, { useState } from 'react';

import { AlertDialog, AlertDialogBody, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, Button, useToast } from '@chakra-ui/react';
import { useForm } from 'react-hook-form';

interface DeleteProps {
isOpen: boolean;
onClose: () => void;
}

const DeleteConfirmation: React.FC<DeleteProps> = ({ isOpen, onClose }) => {
const toast = useToast();
const cancelRef = React.useRef<HTMLButtonElement | null>(null);
const [isLoading, setIsLoading] = useState(false);
const { handleSubmit } = useForm();

const onSubmit = async () => {
setIsLoading(true);
try {
// TODO: Delete user account when API is ready
onClose();
} catch (err) {
toast({
title: "An error occurred.",
description: `An error occurred while deleting your account.`,
status: "error",
isClosable: true,
});
} finally {
setIsLoading(false);
}
}

return (
<>
<AlertDialog
isOpen={isOpen}
onClose={onClose}
leastDestructiveRef={cancelRef}
size={{ base: "sm", md: "md" }}
isCentered
>
<AlertDialogOverlay>
<AlertDialogContent as="form" onSubmit={handleSubmit(onSubmit)}>
<AlertDialogHeader>
Confirmation Required
</AlertDialogHeader>

<AlertDialogBody>
All your account data will be <b>permanently deleted.</b> If you're sure, please click <b>'Confirm'</b> to proceed.
</AlertDialogBody>

<AlertDialogFooter gap={3}>
<Button bg="ui.danger" color="white" _hover={{ opacity: 0.8 }} type="submit" isLoading={isLoading}>
Confirm
</Button>
<Button ref={cancelRef} onClick={onClose} isDisabled={isLoading}>
Cancel
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialogOverlay>
</AlertDialog >
</>
)
}

export default DeleteConfirmation;




2 changes: 1 addition & 1 deletion src/new-frontend/src/pages/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Admin: React.FC = () => {
) : (
users &&
<Container maxW="full">
<Heading size="lg" color="gray.700" textAlign={{ base: "center", md: "left" }} pt={12}>
<Heading size="lg" textAlign={{ base: "center", md: "left" }} pt={12}>
User Management
</Heading>
<Navbar type={"User"} />
Expand Down
6 changes: 3 additions & 3 deletions src/new-frontend/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { Box, Text } from '@chakra-ui/react';
import { Container, Text } from '@chakra-ui/react';

import { useUserStore } from '../store/user-store';

Expand All @@ -10,10 +10,10 @@ const Dashboard: React.FC = () => {

return (
<>
<Box width="100%" p={8}>
<Container maxW="full" pt={12}>
<Text fontSize="2xl">Hi, {user?.full_name || user?.email} 👋🏼</Text>
<Text>Welcome back, nice to see you again!</Text>
</Box>
</Container>
</>

)
Expand Down
2 changes: 1 addition & 1 deletion src/new-frontend/src/pages/Items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const Items: React.FC = () => {
) : (
items &&
<Container maxW="full">
<Heading size="lg" color="gray.700" textAlign={{ base: "center", md: "left" }} pt={12}>
<Heading size="lg" textAlign={{ base: "center", md: "left" }} pt={12}>
Items Management
</Heading>
<Navbar type={"Item"} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Flex, useToast } from '@chakra-ui/react';
import { useUserStore } from '../store/user-store';
import UserMenu from '../components/UserMenu';

const Root: React.FC = () => {
const Layout: React.FC = () => {
const toast = useToast();
const { getUser } = useUserStore();

Expand Down Expand Up @@ -39,4 +39,4 @@ const Root: React.FC = () => {
);
};

export default Root;
export default Layout;
2 changes: 1 addition & 1 deletion src/new-frontend/src/pages/RecoverPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const RecoverPassword: React.FC = () => {
Password Recovery
</Heading>
<FormControl id="username">
<Text align="center" color="gray.600">
<Text align="center">
A password recovery email will be sent to the registered account.
</Text>
<Input
Expand Down
2 changes: 1 addition & 1 deletion src/new-frontend/src/pages/UserSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const UserSettings: React.FC = () => {
return (
<>
<Container maxW="full">
<Heading size="lg" color="gray.700" textAlign={{ base: "center", md: "left" }} py={12}>
<Heading size="lg" textAlign={{ base: "center", md: "left" }} py={12}>
User Settings
</Heading>
<Tabs variant='enclosed' >
Expand Down
14 changes: 5 additions & 9 deletions src/new-frontend/src/panels/Appearance.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
import React from 'react';

import { Button, Container, Heading, Radio, RadioGroup, Stack } from '@chakra-ui/react';
import { Container, Heading, Radio, RadioGroup, Stack, useColorMode } from '@chakra-ui/react';

const Appearance: React.FC = () => {
const [value, setValue] = React.useState('system');
const { colorMode, toggleColorMode } = useColorMode();

return (
<>
<Container maxW="full">
<Heading size="sm" py={4}>
Appearance
</Heading>
<RadioGroup onChange={setValue} value={value}>
<RadioGroup onChange={toggleColorMode} value={colorMode}>
<Stack>
<Radio value="system" colorScheme="teal" defaultChecked>
Use system settings (default)
</Radio>
<Radio value="light" colorScheme="teal">
Light
Light <i>(default)</i>
</Radio>
<Radio value="dark" colorScheme="teal">
Dark
</Radio>
</Stack>
</RadioGroup>
<Button bg="ui.main" color="white" _hover={{ opacity: 0.8 }} mt={4}>Save</Button>
</ Container>
</Container>
</>
);
}
Expand Down
9 changes: 5 additions & 4 deletions src/new-frontend/src/panels/ChangePassword.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';

import { Box, Button, Container, FormControl, FormLabel, Heading, Input } from '@chakra-ui/react';
import { Box, Button, Container, FormControl, FormLabel, Heading, Input, useColorModeValue } from '@chakra-ui/react';

const ChangePassword: React.FC = () => {
const color = useColorModeValue("gray.700", "white");

return (
<>
Expand All @@ -12,15 +13,15 @@ const ChangePassword: React.FC = () => {
</Heading>
<Box as="form" display="flex" flexDirection="column" alignItems="start">
<FormControl>
<FormLabel color="gray.700">Old password</FormLabel>
<FormLabel color={color}>Old password</FormLabel>
<Input placeholder='Password' type="password" />
</FormControl>
<FormControl mt={4}>
<FormLabel color="gray.700">New password</FormLabel>
<FormLabel color={color}>New password</FormLabel>
<Input placeholder='Password' type="password" />
</FormControl>
<FormControl mt={4}>
<FormLabel color="gray.700">Confirm new password</FormLabel>
<FormLabel color={color}>Confirm new password</FormLabel>
<Input placeholder='Password' type="password" />
</FormControl>
<Button bg="ui.main" color="white" _hover={{ opacity: 0.8 }} mt={4} type="submit">
Expand Down
8 changes: 6 additions & 2 deletions src/new-frontend/src/panels/DeleteAccount.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React from 'react';

import { Button, Container, Heading, Text } from '@chakra-ui/react';
import { Button, Container, Heading, Text, useDisclosure } from '@chakra-ui/react';

import DeleteConfirmation from '../modals/DeleteConfirmation';

const DeleteAccount: React.FC = () => {
const confirmationModal = useDisclosure();

return (
<>
Expand All @@ -13,9 +16,10 @@ const DeleteAccount: React.FC = () => {
<Text>
Are you sure you want to delete your account? This action cannot be undone.
</Text>
<Button bg="ui.danger" color="white" _hover={{ opacity: 0.8 }} mt={4}>
<Button bg="ui.danger" color="white" _hover={{ opacity: 0.8 }} mt={4} onClick={confirmationModal.onOpen}>
Delete
</Button>
<DeleteConfirmation isOpen={confirmationModal.isOpen} onClose={confirmationModal.onClose} />
</ Container>
</>
);
Expand Down
Loading