Delightful UI updates
This commit is contained in:
parent
76cbd10a6f
commit
3bcc854ba1
19 changed files with 576 additions and 88 deletions
5
frontend/.dockerignore
Normal file
5
frontend/.dockerignore
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
build/**
|
||||
.idea/
|
||||
node_modules/
|
||||
vs_code/
|
||||
Dockerfile
|
||||
21
frontend/Dockerfile
Normal file
21
frontend/Dockerfile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
FROM node:14-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm install --production
|
||||
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
FROM node:14-alpine AS server
|
||||
|
||||
ENV NODE_ENV=production
|
||||
RUN npm install -g serve
|
||||
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
COPY --from=builder /app/build ./build
|
||||
|
||||
ENV PORT=3000
|
||||
EXPOSE 3000
|
||||
USER node
|
||||
CMD ["serve", "-s", "build"]
|
||||
5
frontend/package-lock.json
generated
5
frontend/package-lock.json
generated
|
|
@ -8771,6 +8771,11 @@
|
|||
"minimist": "^1.2.6"
|
||||
}
|
||||
},
|
||||
"moment": {
|
||||
"version": "2.29.2",
|
||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.2.tgz",
|
||||
"integrity": "sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg=="
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
"@emotion/styled": "^11.8.1",
|
||||
"framer-motion": "^6.3.0",
|
||||
"jwt-decode": "^3.1.2",
|
||||
"moment": "^2.29.2",
|
||||
"react": "^18.0.0",
|
||||
"react-dom": "^18.0.0",
|
||||
"react-icons": "^4.3.1",
|
||||
|
|
|
|||
|
|
@ -4,32 +4,105 @@
|
|||
margin: auto;
|
||||
}
|
||||
|
||||
/* body.chakra-ui-dark nav.main {
|
||||
background-color: var(--chakra-colors-whiteAlpha-300) !important;
|
||||
border: 2px solid var(--chakra-colors-whiteAlpha-100) !important;
|
||||
.react-icons {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
nav.main {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
.chakra-text a {
|
||||
color: var(--chakra-colors-purple-600) !important;
|
||||
transition: font-weight ease-in-out 150ms;
|
||||
}
|
||||
|
||||
.chakra-text a:visited {
|
||||
color: var(--chakra-colors-yellow-500) !important;
|
||||
}
|
||||
|
||||
.chakra-text a:hover {
|
||||
font-weight: 600;
|
||||
color: var(--chakra-colors-purple-500) !important;
|
||||
}
|
||||
|
||||
.nav-inactive {
|
||||
display: -webkit-inline-box;
|
||||
display: -webkit-inline-flex;
|
||||
display: -ms-inline-flexbox;
|
||||
display: inline-flex;
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
-ms-appearance: none;
|
||||
appearance: none;
|
||||
-webkit-align-items: center;
|
||||
-webkit-box-align: center;
|
||||
-ms-flex-align: center;
|
||||
align-items: center;
|
||||
|
||||
border-radius: 8px;
|
||||
background-color: var(--chakra-colors-blackAlpha-300);
|
||||
border: 2px solid var(--chakra-colors-blackAlpha-100);
|
||||
|
||||
margin: auto;
|
||||
padding: 0.35rem 0.5rem;
|
||||
|
||||
width: 100%;
|
||||
max-width: 768px;
|
||||
-webkit-box-pack: center;
|
||||
-ms-flex-pack: center;
|
||||
-webkit-justify-content: center;
|
||||
justify-content: center;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
position: relative;
|
||||
white-space: nowrap;
|
||||
vertical-align: middle;
|
||||
outline: 2px solid transparent;
|
||||
outline-offset: 2px;
|
||||
width: auto;
|
||||
line-height: 1.2;
|
||||
border-radius: var(--chakra-radii-md);
|
||||
font-weight: var(--chakra-fontWeights-semibold);
|
||||
transition-property: var(--chakra-transition-property-common);
|
||||
transition-duration: var(--chakra-transition-duration-normal);
|
||||
height: var(--chakra-sizes-10);
|
||||
min-width: var(--chakra-sizes-10);
|
||||
font-size: var(--chakra-fontSizes-md);
|
||||
-webkit-padding-start: var(--chakra-space-4);
|
||||
padding-inline-start: var(--chakra-space-4);
|
||||
-webkit-padding-end: var(--chakra-space-4);
|
||||
padding-inline-end: var(--chakra-space-4);
|
||||
background: var(--chakra-colors-gray-100);
|
||||
}
|
||||
|
||||
nav.main .item {
|
||||
transition: background-color ease-in-out 250ms;
|
||||
background-color: transparent;
|
||||
.nav-active {
|
||||
display: -webkit-inline-box;
|
||||
display: -webkit-inline-flex;
|
||||
display: -ms-inline-flexbox;
|
||||
display: inline-flex;
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
-ms-appearance: none;
|
||||
appearance: none;
|
||||
-webkit-align-items: center;
|
||||
-webkit-box-align: center;
|
||||
-ms-flex-align: center;
|
||||
align-items: center;
|
||||
-webkit-box-pack: center;
|
||||
-ms-flex-pack: center;
|
||||
-webkit-justify-content: center;
|
||||
justify-content: center;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
position: relative;
|
||||
white-space: nowrap;
|
||||
vertical-align: middle;
|
||||
outline: 2px solid transparent;
|
||||
outline-offset: 2px;
|
||||
width: auto;
|
||||
line-height: 1.2;
|
||||
border-radius: var(--chakra-radii-md);
|
||||
font-weight: var(--chakra-fontWeights-semibold);
|
||||
transition-property: var(--chakra-transition-property-common);
|
||||
transition-duration: var(--chakra-transition-duration-normal);
|
||||
height: var(--chakra-sizes-10);
|
||||
min-width: var(--chakra-sizes-10);
|
||||
font-size: var(--chakra-fontSizes-md);
|
||||
-webkit-padding-start: var(--chakra-space-4);
|
||||
padding-inline-start: var(--chakra-space-4);
|
||||
-webkit-padding-end: var(--chakra-space-4);
|
||||
padding-inline-end: var(--chakra-space-4);
|
||||
background: var(--chakra-colors-blue-500);
|
||||
color: var(--chakra-colors-white);
|
||||
}
|
||||
nav.main .item:hover {
|
||||
background-color: var(--chakra-colors-blackAlpha-500);
|
||||
} */
|
||||
|
|
|
|||
|
|
@ -2,11 +2,49 @@ import React from 'react';
|
|||
import { ChakraProvider, theme } from '@chakra-ui/react';
|
||||
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
||||
import { Provider } from 'react-redux';
|
||||
import NavBar from './global/components/Nav/Bar';
|
||||
import { FaShoppingBag } from 'react-icons/fa';
|
||||
import store from './redux/store';
|
||||
|
||||
import Navbar from './global/components/Nav/Navbar';
|
||||
import FakeNavItem from './global/components/Nav/FakeNavItem';
|
||||
import AlertModal from './global/components/Modal/Alert';
|
||||
import Footer from './components/Footer';
|
||||
|
||||
// Pages
|
||||
import Home from './pages/Home/index';
|
||||
import Login from './pages/User/Login';
|
||||
import Register from './pages/User/Register';
|
||||
|
||||
export const Pages = [
|
||||
{
|
||||
name: 'Shop',
|
||||
path: '/',
|
||||
icon: (<FaShoppingBag />),
|
||||
element: (<Home />),
|
||||
hidden: false,
|
||||
},
|
||||
{
|
||||
name: 'Login',
|
||||
path: '/login',
|
||||
icon: null,
|
||||
element: (<Login />),
|
||||
hidden: true,
|
||||
},
|
||||
{
|
||||
name: 'Logout',
|
||||
path: '/logout',
|
||||
icon: null,
|
||||
element: (<FakeNavItem dispatch={{ type: 'CLEAR_USER' }} redirect="/" />),
|
||||
hidden: true,
|
||||
},
|
||||
{
|
||||
name: 'Register',
|
||||
path: '/register',
|
||||
icon: null,
|
||||
element: (<Register />),
|
||||
hidden: true,
|
||||
},
|
||||
];
|
||||
|
||||
export default () => (
|
||||
<React.StrictMode>
|
||||
|
|
@ -14,11 +52,15 @@ export default () => (
|
|||
<ChakraProvider theme={theme}>
|
||||
<BrowserRouter>
|
||||
<div style={{ marginBottom: '1rem' }} />
|
||||
<NavBar />
|
||||
<Navbar />
|
||||
<div style={{ marginBottom: '2rem' }} />
|
||||
<Routes>
|
||||
<Route exact path="/" index element={(<Home />)} />
|
||||
{ Pages.map((x) => (
|
||||
<Route exact path={x.path} element={x.element} />
|
||||
))}
|
||||
</Routes>
|
||||
<AlertModal />
|
||||
<Footer />
|
||||
</BrowserRouter>
|
||||
</ChakraProvider>
|
||||
</Provider>
|
||||
|
|
|
|||
18
frontend/src/components/Footer.jsx
Normal file
18
frontend/src/components/Footer.jsx
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import React from 'react';
|
||||
import { Box, Flex, Text } from '@chakra-ui/react';
|
||||
|
||||
export default () => (
|
||||
<Box margin="2rem auto 1rem" width="max-content">
|
||||
<Flex>
|
||||
<Text>
|
||||
Made with 💙 by
|
||||
{' '}
|
||||
<a href="https://oitsjustjose.com">oitsjustjose</a>
|
||||
{' '}
|
||||
using
|
||||
{' '}
|
||||
<a href="https://chakra-ui.com">Chakra-UI</a>
|
||||
</Text>
|
||||
</Flex>
|
||||
</Box>
|
||||
);
|
||||
10
frontend/src/global/components/IconTextDuo.jsx
Normal file
10
frontend/src/global/components/IconTextDuo.jsx
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import React from 'react';
|
||||
import { Flex } from '@chakra-ui/react';
|
||||
|
||||
export default ({ icon, text, iconOnRight }) => (
|
||||
<Flex alignItems="center">
|
||||
{iconOnRight ? text : icon}
|
||||
<div style={{ width: '8px' }} />
|
||||
{iconOnRight ? icon : text}
|
||||
</Flex>
|
||||
);
|
||||
36
frontend/src/global/components/Modal/Alert.jsx
Normal file
36
frontend/src/global/components/Modal/Alert.jsx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import React from 'react';
|
||||
import {
|
||||
Button, Modal, ModalBody,
|
||||
ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay,
|
||||
} from '@chakra-ui/react';
|
||||
import { connect } from 'react-redux';
|
||||
import store from '../../../redux/store';
|
||||
|
||||
const AlertModal = ({
|
||||
open, header, content,
|
||||
}) => (
|
||||
<Modal isOpen={open} onClose={() => store.dispatch({ type: 'SET_ALERT', data: null })}>
|
||||
<ModalOverlay />
|
||||
<ModalContent>
|
||||
<ModalHeader>{header}</ModalHeader>
|
||||
<ModalCloseButton />
|
||||
<ModalBody>
|
||||
<p>{content}</p>
|
||||
</ModalBody>
|
||||
|
||||
<ModalFooter>
|
||||
<Button colorScheme="blue" mr={3} onClick={() => store.dispatch({ type: 'SET_ALERT', data: null })}>
|
||||
Close
|
||||
</Button>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
const mapStateToProps = ({ alert }) => ({
|
||||
open: !!alert,
|
||||
header: alert?.header || null,
|
||||
content: alert?.content || null,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(AlertModal);
|
||||
16
frontend/src/global/components/Nav/FakeNavItem.jsx
Normal file
16
frontend/src/global/components/Nav/FakeNavItem.jsx
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import React, { useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import store from '../../../redux/store';
|
||||
|
||||
export default ({ func, dispatch, redirect }) => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
func && func();
|
||||
dispatch && store.dispatch(dispatch);
|
||||
redirect && navigate(redirect, { replace: true });
|
||||
return () => {};
|
||||
}, [func, dispatch, redirect]);
|
||||
|
||||
return (<div />);
|
||||
};
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
import { Button, Icon } from '@chakra-ui/react';
|
||||
import React from 'react';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
|
||||
export default ({
|
||||
to, name, icon,
|
||||
}) => (
|
||||
<NavLink exact activeClassName="active" to={to}>
|
||||
<Button>
|
||||
{!!icon && (<Icon name={icon} />)}
|
||||
{!!icon && !!name && ' '}
|
||||
{!!name && name}
|
||||
</Button>
|
||||
</NavLink>
|
||||
|
||||
);
|
||||
|
|
@ -7,21 +7,16 @@ import {
|
|||
} from '@chakra-ui/react';
|
||||
import { AiOutlineClose } from 'react-icons/ai';
|
||||
import { FaHamburger } from 'react-icons/fa';
|
||||
import Item from './Item';
|
||||
import { connect } from 'react-redux';
|
||||
import { MdLogin, MdLogout } from 'react-icons/md';
|
||||
import Item from './NavbarItem';
|
||||
import { Pages } from '../../../App';
|
||||
|
||||
export const Pages = [
|
||||
{
|
||||
name: 'Home',
|
||||
path: '/',
|
||||
icon: null,
|
||||
},
|
||||
];
|
||||
|
||||
export default function Simple() {
|
||||
const NavBar = ({ user }) => {
|
||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||
|
||||
return (
|
||||
<Box bg={useColorModeValue('gray.100', 'gray.900')} px={4}>
|
||||
<Box bg={useColorModeValue('gray.100', 'gray.900')} px={4} borderRadius="8px">
|
||||
<Flex h={16} alignItems="center" justifyContent="space-between">
|
||||
<IconButton
|
||||
size="md"
|
||||
|
|
@ -38,45 +33,33 @@ export default function Simple() {
|
|||
display={{ base: 'none', md: 'flex' }}
|
||||
>
|
||||
|
||||
{Pages.map(({ icon, name, path }) => (
|
||||
{Pages.filter((x) => !x.hidden).map(({ icon, name, path }) => (
|
||||
<Item icon={icon} name={name} to={path} />
|
||||
))}
|
||||
|
||||
{!user && (<Item icon={(<MdLogin />)} name="Log In" to="/login" />)}
|
||||
{user && (<Item icon={(<MdLogout />)} name="Log Out" to="/logout" />) }
|
||||
</HStack>
|
||||
</HStack>
|
||||
{/* This chunk handles the dropdown menu */}
|
||||
{/* <Flex alignItems="center">
|
||||
<Menu>
|
||||
<MenuButton
|
||||
as={Button}
|
||||
rounded="full"
|
||||
variant="link"
|
||||
cursor="pointer"
|
||||
minW={0}
|
||||
>
|
||||
<Avatar
|
||||
size="sm"
|
||||
src="https://images.unsplash.com/photo-1493666438817-866a91353ca9?ixlib=rb-0.3.5&q=80&fm=jpg&crop=faces&fit=crop&h=200&w=200&s=b616b2c5b373a80ffc9636ba24f7a4a9"
|
||||
/>
|
||||
</MenuButton>
|
||||
<MenuList>
|
||||
<MenuItem>Link 1</MenuItem>
|
||||
<MenuItem>Link 2</MenuItem>
|
||||
<MenuDivider />
|
||||
<MenuItem>Link 3</MenuItem>
|
||||
</MenuList>
|
||||
</Menu>
|
||||
</Flex> */}
|
||||
</Flex>
|
||||
|
||||
{/* Handles the mobile version of the menu. */}
|
||||
{isOpen ? (
|
||||
<Box pb={4} display={{ md: 'none' }}>
|
||||
<Stack as="nav" spacing={4}>
|
||||
{Pages.map(({ icon, name, path }) => (
|
||||
{Pages.filter((x) => !x.hidden).map(({ icon, name, path }) => (
|
||||
<Item icon={icon} name={name} to={path} />
|
||||
))}
|
||||
|
||||
</Stack>
|
||||
</Box>
|
||||
) : null}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const mapStateToProps = ({ user }) => ({
|
||||
user,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(NavBar);
|
||||
17
frontend/src/global/components/Nav/NavbarItem.jsx
Normal file
17
frontend/src/global/components/Nav/NavbarItem.jsx
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import React from 'react';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
|
||||
export default ({
|
||||
to, name, icon,
|
||||
}) => (
|
||||
<NavLink
|
||||
exact
|
||||
to={to}
|
||||
className={({ isActive }) => `chakra-button ${isActive ? 'nav-active' : 'nav-inactive'}`}
|
||||
>
|
||||
{icon && icon}
|
||||
{!!icon && !!name && (<div style={{ width: '8px' }} />)}
|
||||
{!!name && name}
|
||||
</NavLink>
|
||||
|
||||
);
|
||||
File diff suppressed because one or more lines are too long
95
frontend/src/pages/User/Login.jsx
Normal file
95
frontend/src/pages/User/Login.jsx
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
import React, { useState } from 'react';
|
||||
import {
|
||||
Button, FormControl, FormLabel, Input, Heading, Text,
|
||||
} from '@chakra-ui/react';
|
||||
import { MdAlternateEmail, MdPassword, MdLogin } from 'react-icons/md';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import IconTextDuo from '../../global/components/IconTextDuo';
|
||||
import store from '../../redux/store';
|
||||
|
||||
export default () => {
|
||||
const [state, setState] = useState({ email: '', password: '' });
|
||||
const [loading, setLoading] = useState(false);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const login = async () => {
|
||||
setLoading(true);
|
||||
|
||||
const resp = await fetch('/api/v1/user/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(state),
|
||||
});
|
||||
|
||||
const data = await resp.json();
|
||||
|
||||
if (resp.ok) {
|
||||
store.dispatch({ type: 'SET_USER_TOKEN', token: data.token });
|
||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Logged In!', content: '' } });
|
||||
setTimeout(() => store.dispatch({ type: 'SET_ALERT', data: null }), 1000);
|
||||
navigate('/', { replace: true });
|
||||
} else {
|
||||
store.dispatch({
|
||||
type: 'SET_ALERT',
|
||||
data: { header: 'There was an Error Logging In', content: data.error },
|
||||
});
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Heading textAlign="center" marginBottom="1rem">User Login</Heading>
|
||||
<Text textAlign="center" marginBottom="0.5rem">
|
||||
Need an account? Click
|
||||
{' '}
|
||||
<a href="/register">here!</a>
|
||||
</Text>
|
||||
|
||||
<FormControl
|
||||
onKeyPress={(e) => e.key === 'Enter' && login()}
|
||||
onSubmit={login}
|
||||
backgroundColor="gray.100"
|
||||
padding="2rem"
|
||||
borderRadius="8px"
|
||||
maxW="50%"
|
||||
margin="auto"
|
||||
>
|
||||
<FormLabel htmlFor="email">
|
||||
<IconTextDuo icon={(<MdAlternateEmail />)} text="Email" />
|
||||
</FormLabel>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
required
|
||||
value={state.email}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, email: e.target.value })}
|
||||
/>
|
||||
|
||||
<FormLabel htmlFor="password">
|
||||
<IconTextDuo icon={(<MdPassword />)} text="Password" />
|
||||
</FormLabel>
|
||||
<Input
|
||||
id="password"
|
||||
type="Password"
|
||||
required
|
||||
value={state.password}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, password: e.target.value })}
|
||||
/>
|
||||
|
||||
<Button
|
||||
mt={4}
|
||||
colorScheme="blue"
|
||||
isLoading={loading}
|
||||
type="submit"
|
||||
onClick={login}
|
||||
>
|
||||
<IconTextDuo iconOnRight icon={(<MdLogin />)} text="Log In" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
129
frontend/src/pages/User/Register.jsx
Normal file
129
frontend/src/pages/User/Register.jsx
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
import React, { useState } from 'react';
|
||||
import {
|
||||
Button, FormControl, FormLabel, Input, Heading, Text, FormHelperText,
|
||||
} from '@chakra-ui/react';
|
||||
import { MdAlternateEmail, MdPassword, MdSend } from 'react-icons/md';
|
||||
import { BiRename } from 'react-icons/bi';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import store from '../../redux/store';
|
||||
import IconTextDuo from '../../global/components/IconTextDuo';
|
||||
|
||||
export default () => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [state, setState] = useState({
|
||||
first: '', last: '', email: '', password: '', conf: '',
|
||||
});
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const register = async () => {
|
||||
setLoading(true);
|
||||
const resp = await fetch('/api/v1/user/', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(state),
|
||||
});
|
||||
|
||||
const data = await resp.json();
|
||||
const message = {
|
||||
header: resp.ok ? 'Account Created!' : 'Unable to Create Account',
|
||||
content: resp.ok ? 'You will receive an account confirmation email shortly! Sit tight until you have verified your account.' : data.error,
|
||||
};
|
||||
|
||||
store.dispatch({ type: 'SET_ALERT', data: message });
|
||||
resp.ok && navigate('/login', { replace: true });
|
||||
setLoading(false);
|
||||
};
|
||||
return (
|
||||
<div>
|
||||
<Heading textAlign="center" marginBottom="1rem">Account Setup</Heading>
|
||||
<Text textAlign="center" marginBottom="0.5rem">
|
||||
Already have an account? Sign in
|
||||
{' '}
|
||||
<a href="/login">here!</a>
|
||||
</Text>
|
||||
|
||||
<FormControl
|
||||
onKeyPress={(e) => e.key === 'Enter' && register()}
|
||||
onSubmit={register}
|
||||
backgroundColor="gray.100"
|
||||
padding="2rem"
|
||||
borderRadius="8px"
|
||||
maxW="50%"
|
||||
margin="auto"
|
||||
>
|
||||
<FormHelperText marginBottom="0.5rem" marginTop="0 !important">None of this information will be shared</FormHelperText>
|
||||
|
||||
<FormLabel htmlFor="first">
|
||||
<IconTextDuo icon={(<BiRename />)} text="First Name " />
|
||||
</FormLabel>
|
||||
<Input
|
||||
id="first"
|
||||
type="text"
|
||||
required
|
||||
value={state.first}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, first: e.target.value })}
|
||||
/>
|
||||
|
||||
<FormLabel htmlFor="last">
|
||||
<IconTextDuo icon={(<BiRename />)} text="Last Name" />
|
||||
</FormLabel>
|
||||
<Input
|
||||
id="last"
|
||||
type="text"
|
||||
required
|
||||
value={state.last}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, last: e.target.value })}
|
||||
/>
|
||||
|
||||
<FormLabel htmlFor="email">
|
||||
<IconTextDuo icon={(<MdAlternateEmail />)} text="Email" />
|
||||
</FormLabel>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
required
|
||||
value={state.email}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, email: e.target.value })}
|
||||
/>
|
||||
|
||||
<FormLabel htmlFor="password">
|
||||
<IconTextDuo icon={(<MdPassword />)} text="Password" />
|
||||
</FormLabel>
|
||||
<Input
|
||||
id="password"
|
||||
type="Password"
|
||||
required
|
||||
value={state.password}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, password: e.target.value })}
|
||||
/>
|
||||
|
||||
<FormLabel htmlFor="conf">
|
||||
<IconTextDuo icon={(<MdPassword />)} text="Verify Password" />
|
||||
</FormLabel>
|
||||
<Input
|
||||
id="conf"
|
||||
type="password"
|
||||
required
|
||||
value={state.conf}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, conf: e.target.value })}
|
||||
/>
|
||||
|
||||
<Button
|
||||
mt={4}
|
||||
colorScheme="blue"
|
||||
isLoading={loading}
|
||||
type="submit"
|
||||
onClick={register}
|
||||
>
|
||||
<IconTextDuo iconOnRight icon={(<MdSend />)} text="Register" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,26 +1,46 @@
|
|||
import JwtDecode from 'jwt-decode';
|
||||
import moment from 'moment';
|
||||
|
||||
const getUserFromLocalStorage = () => {
|
||||
const u = JSON.parse(window.localStorage.getItem('redux-persistent'));
|
||||
if (!u) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (moment().isAfter(moment(u.expiresAt))) {
|
||||
window.localStorage.removeItem('redux-persistent');
|
||||
return null;
|
||||
}
|
||||
return u;
|
||||
};
|
||||
|
||||
const defaultState = {
|
||||
isAuthenticated: false,
|
||||
user: null,
|
||||
user: getUserFromLocalStorage(),
|
||||
i18n: null,
|
||||
langs: null,
|
||||
alert: null,
|
||||
};
|
||||
|
||||
const decodeUser = (token) => {
|
||||
const user = JwtDecode(token);
|
||||
const userData = { ...user, token };
|
||||
window.localStorage.setItem('redux-persistent', JSON.stringify(userData));
|
||||
return userData;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line default-param-last
|
||||
export default (state = defaultState, action) => {
|
||||
switch (action.type) {
|
||||
case 'SET_USER':
|
||||
case 'SET_USER_TOKEN':
|
||||
return {
|
||||
...state,
|
||||
user: {
|
||||
...action.user,
|
||||
},
|
||||
isAuthenticated: true,
|
||||
user: decodeUser(action.token),
|
||||
};
|
||||
case 'CLEAR_USER':
|
||||
window.localStorage.removeItem('redux-persistent');
|
||||
return {
|
||||
...state,
|
||||
user: null,
|
||||
isAuthenticated: false,
|
||||
};
|
||||
case 'SET_I18N':
|
||||
return {
|
||||
|
|
@ -32,6 +52,11 @@ export default (state = defaultState, action) => {
|
|||
...state,
|
||||
langs: action.data,
|
||||
};
|
||||
case 'SET_ALERT':
|
||||
return {
|
||||
...state,
|
||||
alert: action.data || null,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue