Skip to content

Commit

Permalink
feat(web-client): Add chakra ui to authentication pages, sidebar and …
Browse files Browse the repository at this point in the history
…dashboard (#210)

* feat(web-client): Add chakra ui to authentication pages

* feat(web-client): Add chakra ui to sidebar

* feat(web-client): Add chakra ui to dashboard
  • Loading branch information
alllenshibu authored Dec 30, 2023
1 parent 6a5d622 commit 0277b39
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 197 deletions.
95 changes: 27 additions & 68 deletions apps/web-client/src/components/Sidebar.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useRouter } from 'next/router';
import Link from 'next/link';

import { cn } from '@/lib/utils';
import { Button } from '@/components/ui/button';
import { Box, Text, Button, Flex } from '@chakra-ui/react';

import {
Accordion,
AccordionContent,
Expand All @@ -21,72 +21,31 @@ const Sidebar = ({ className }) => {
};

return (
<div className={cn('pb-12', className)}>
<div className="space-y-4 py-4">
<div className="px-3 py-2">
<h2 className="mb-2 px-4 text-lg font-semibold tracking-tight">Quick Access</h2>
<div className="space-y-1">
<Button variant="ghost" className="w-full justify-start">
<Link href={`/organizations/${organizationId}`}>Events</Link>
</Button>
<Button variant="ghost" className="w-full justify-start">
Participants
</Button>
<Button variant="ghost" className="w-full justify-start">
Attributes
</Button>
<Button variant="ghost" className="w-full justify-start">
Extras
</Button>
</div>
</div>
<div className="px-6 py-2">
<Accordion type="single" collapsible className="w-full">
<AccordionItem value="item-1">
<AccordionTrigger>Organization 1</AccordionTrigger>
<AccordionContent>
<Accordion type="single" collapsible className="w-full">
<AccordionItem value="item-1">
<AccordionTrigger>Event 1</AccordionTrigger>
<AccordionContent>Something</AccordionContent>
</AccordionItem>
<AccordionItem value="item-2">
<AccordionTrigger>Event 2</AccordionTrigger>
<AccordionContent>Something</AccordionContent>
</AccordionItem>
</Accordion>
</AccordionContent>
</AccordionItem>
<AccordionItem value="item-2">
<AccordionTrigger>Organization 2</AccordionTrigger>
<AccordionContent>
<Accordion type="single" collapsible className="w-full">
<AccordionItem value="item-1">
<AccordionTrigger>Event 1</AccordionTrigger>
<AccordionContent>Something</AccordionContent>
</AccordionItem>
<AccordionItem value="item-2">
<AccordionTrigger>Event 2</AccordionTrigger>
<AccordionContent>Something</AccordionContent>
</AccordionItem>
</Accordion>
</AccordionContent>
</AccordionItem>
</Accordion>
</div>
<div className="px-3 py-2">
{/*<h2 className="mb-2 px-4 text-lg font-semibold tracking-tight">Library</h2>*/}
<div className="space-y-1">
<Button variant="ghost" className="w-full justify-start">
Settings
</Button>
<Button className="w-full justify-start" onClick={handleLogout}>
Logout
</Button>
</div>
</div>
</div>
</div>
<Box padding={4}>
<Box paddingY={4}>
<Text fontSize="4xl" fontWeight="bold">
techno
</Text>
</Box>
<Flex paddingY={4} direction="column" gap={2}>
<Text fontSize="xl">
<Link href="/organizations">Organizations</Link>
</Text>
<Text fontSize="xl">
<Link href="/organizations">Events</Link>
</Text>
</Flex>
<Box paddingY={4}>
<Text fontSize="xl">
<Link href="/settings">Settings</Link>
</Text>
</Box>
<Box paddingY={4}>
<Button onClick={handleLogout} width="100%">
Logout
</Button>
</Box>
</Box>
);
};

Expand Down
8 changes: 1 addition & 7 deletions apps/web-client/src/layouts/DashboardLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import Image from 'next/image';
import Menu from '@/components/Menu';
import Sidebar from '@/components/Sidebar';

import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Button } from '@/components/ui/button';
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';

import { PlusCircledIcon } from '@radix-ui/react-icons';

const DashboardLayout = ({ children }) => {
return (
<>
Expand All @@ -18,7 +12,7 @@ const DashboardLayout = ({ children }) => {
<div className="border-t">
<div className="bg-background">
<div className="grid lg:grid-cols-5">
<Sidebar className="hidden lg:block" />
<Sidebar />
<div className="col-span-3 lg:col-span-4 lg:border-l">
<div className="h-full px-4 py-6 lg:px-8">{children}</div>
</div>
Expand Down
22 changes: 22 additions & 0 deletions apps/web-client/src/pages/404.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Flex, Text, Button } from '@chakra-ui/react';
import Link from 'next/link';

export default function P404() {
return (
<Flex
height="100vh"
width="100vw"
direction="column"
alignItems="center"
justifyContent="center"
>
<Text fontSize="9xl" fontWeight="bold">
404
</Text>

<Button>
<Link href="/">Back home</Link>
</Button>
</Flex>
);
}
13 changes: 10 additions & 3 deletions apps/web-client/src/pages/_app.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import '@/styles/globals.css';
import React, { useEffect, useState } from 'react';
import { useRouter } from 'next/router';
import { ChakraProvider } from '@chakra-ui/react';

import { extendTheme, ChakraProvider, withDefaultColorScheme } from '@chakra-ui/react';

const theme = extendTheme(
withDefaultColorScheme({
colorScheme: 'purple',
}),
);

export default function App({ Component, pageProps }) {
const router = useRouter();
Expand All @@ -12,10 +19,10 @@ export default function App({ Component, pageProps }) {
if (!token && router.pathname !== '/login' && router.pathname !== '/signup')
router.push('/login');
}
}, []);
}, [router]);

return (
<ChakraProvider>
<ChakraProvider theme={theme}>
<Component {...pageProps} />
</ChakraProvider>
);
Expand Down
88 changes: 60 additions & 28 deletions apps/web-client/src/pages/login/index.jsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,79 @@
import React, { useState } from 'react';
import { useRouter } from 'next/router';
import Link from 'next/link';

import useLocalStorage from '@/hooks/useLocalStorage';
import { loginService } from '@/services/authenticationService';

import {
Button,
Box,
Card,
CardBody,
FormControl,
FormLabel,
Input,
Flex,
Text,
} from '@chakra-ui/react';

export default function Login() {
const router = useRouter();

const [loading, setLoading] = useState(false);

const [email, setEmail] = useState('');
const [password, setPassword] = useState('');

const [token, setToken] = useLocalStorage('token', null);

const handleSubmit = async (e) => {
e.preventDefault();
setLoading(true);
if (await loginService({ email, password })) router.push('/organizations');
else console.error('Error when logging in');
};

return (
<div>
<form onSubmit={handleSubmit}>
<label>
Email:
<input
type="text"
name="email"
onChange={(e) => {
setEmail(e.target.value);
}}
/>
</label>
<label>
Password:
<input
type="passwor"
name="password"
onChange={(e) => {
setPassword(e.target.value);
}}
/>
</label>
<input type="submit" value="Submit" />
</form>
</div>
<Flex direction="column" height="100vh" alignItems="center" justifyContent="center" gap={8}>
<Box textAlign="center">
<Text fontSize="3xl" fontWeight="bold">
Login to your account
</Text>
<Text>
Don&apos;t have an account?{' '}
<Text as="span" color="blue" fontWeight="semibold">
<Link href="/signup">Sign up</Link>
</Text>
</Text>
</Box>
<Card width="100%" maxWidth="400px" height="auto">
<CardBody>
<form onSubmit={handleSubmit}>
<FormControl isRequired my={4}>
<FormLabel>Email address</FormLabel>
<Input
type="email"
name="email"
onChange={(e) => {
setEmail(e.target.value);
}}
/>
</FormControl>
<FormControl isRequired my={4}>
<FormLabel>Password</FormLabel>
<Input
type="password"
name="password"
onChange={(e) => {
setPassword(e.target.value);
}}
/>
</FormControl>

<Button type="submit" width="100%" my="4" isLoading={loading} loadingText="Please Wait">
Login
</Button>
</form>
</CardBody>
</Card>
</Flex>
);
}
71 changes: 25 additions & 46 deletions apps/web-client/src/pages/organizations/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@ import axiosInstance from '@/lib/axios';
import DashboardLayout from '../../layouts/DashboardLayout';

import { Skeleton } from '@/components/ui/skeleton';
import {
Table,
TableBody,
TableCaption,
TableCell,
TableFooter,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table';
import { Button } from '@/components/ui/button';
import { Table, Thead, Tbody, Tr, Th, Td, TableContainer } from '@chakra-ui/react';

import { useRouter } from 'next/router';

Expand All @@ -28,7 +18,7 @@ const Dashboard = () => {
try {
const { data, status } = await axiosInstance.get('/users/organizations');
if (status === 200) setOrganizations(data.organizations || []);
setLoading(false);
//setLoading(false);
} catch (error) {
console.error(error);
setLoading(true);
Expand All @@ -44,45 +34,34 @@ const Dashboard = () => {
<div className="h-full w-full bg-black-russian flex flex-row justify-start items-start overflow-y-auto gap-8 flex-wrap p-6">
{loading && (
<>
<Skeleton className="w-[100px] h-[20px] rounded-full" />
<Skeleton className="w-[100px] h-[20px] rounded-full" />
<Skeleton className="w-[100px] h-[20px] rounded-full" />
<Skeleton className="w-[100px] h-[20px] rounded-full" />
<Skeleton className="w-full h-[20px] rounded-full" />
</>
)}
<Table>
<TableCaption>Organization</TableCaption>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Role</TableHead>
<TableHead>Role</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{organizations.map((o) => (
<TableRow key={o.id}>
<TableCell>{o.name}</TableCell>
<TableCell>{o.role}</TableCell>
<TableCell>
<Button
{!loading && organizations.length > 0 && (
<TableContainer width="100%">
<Table>
<Thead>
<Tr>
<Th>Name</Th>
<Th>Role</Th>
</Tr>
</Thead>
<Tbody>
{organizations.map((organization) => (
<Tr
key={organization.id}
onClick={() => {
router.push(`/organizations/${o.id}`);
router.push(`/organizations/${organization.id}`);
}}
>
Manage
</Button>
</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TableCell colSpan={2}>Total</TableCell>
<TableCell className="text-right">{organizations?.length}</TableCell>
</TableRow>
</TableFooter>
</Table>
<Td>{organization.name}</Td>
<Td>{organization.role}</Td>
</Tr>
))}
</Tbody>
</Table>
</TableContainer>
)}

{!loading && organizations.length === 0 && (
<div className="w-full h-full flex flex-col justify-center items-center">
Expand Down
Loading

0 comments on commit 0277b39

Please sign in to comment.