Color and I18n support
This commit is contained in:
parent
523f537aa4
commit
ba82c13fe1
19 changed files with 630 additions and 303 deletions
13
frontend/package-lock.json
generated
13
frontend/package-lock.json
generated
|
|
@ -8510,6 +8510,11 @@
|
|||
"json5": "^2.1.2"
|
||||
}
|
||||
},
|
||||
"localized-strings": {
|
||||
"version": "0.2.4",
|
||||
"resolved": "https://registry.npmjs.org/localized-strings/-/localized-strings-0.2.4.tgz",
|
||||
"integrity": "sha512-TKDhqFPkIIN/if2FSvVVZTaM/GP9TzfgdQ2uY65mr32xgFu5nqkKXprXbzy5rfx32DF5LDvS/y1UqYF/mAscYA=="
|
||||
},
|
||||
"locate-path": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz",
|
||||
|
|
@ -10266,6 +10271,14 @@
|
|||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
||||
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
|
||||
},
|
||||
"react-localization": {
|
||||
"version": "1.0.19",
|
||||
"resolved": "https://registry.npmjs.org/react-localization/-/react-localization-1.0.19.tgz",
|
||||
"integrity": "sha512-f4E6T8xRis19K8qMOnnhjGV2quy1YH2lrSsnAiytvgt7uOSp6WgDhrZH6XZEaEFqupTOCFSf8uagIoIAkjl4JA==",
|
||||
"requires": {
|
||||
"localized-strings": "^0.2.0"
|
||||
}
|
||||
},
|
||||
"react-phone-input-2": {
|
||||
"version": "2.15.0",
|
||||
"resolved": "https://registry.npmjs.org/react-phone-input-2/-/react-phone-input-2-2.15.0.tgz",
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
"react-currency-input-field": "^3.6.4",
|
||||
"react-dom": "^18.0.0",
|
||||
"react-icons": "^4.3.1",
|
||||
"react-localization": "^1.0.19",
|
||||
"react-phone-input-2": "^2.15.0",
|
||||
"react-redux": "^7.2.8",
|
||||
"react-router-dom": "^6.3.0",
|
||||
|
|
|
|||
|
|
@ -22,88 +22,13 @@
|
|||
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;
|
||||
-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);
|
||||
body.chakra-ui-light .chakra-input.currency {
|
||||
background: var(--chakra-colors-gray-50);
|
||||
color: var(--chakra-colors-black);
|
||||
}
|
||||
|
||||
.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);
|
||||
body.chakra-ui-dark .chakra-input.currency {
|
||||
background: var(--chakra-colors-gray-700);
|
||||
color: var(--chakra-colors-white);
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +57,6 @@
|
|||
border-bottom-color: currentcolor;
|
||||
border-left-color: currentcolor;
|
||||
border-color: inherit;
|
||||
background: var(--chakra-colors-gray-50);
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,16 @@
|
|||
import React from 'react';
|
||||
import { ChakraProvider, theme } from '@chakra-ui/react';
|
||||
import { ChakraProvider, extendTheme } from '@chakra-ui/react';
|
||||
import { Provider } from 'react-redux';
|
||||
import Routes from './Routes';
|
||||
import store from './redux/store';
|
||||
|
||||
const theme = extendTheme({
|
||||
config: {
|
||||
initialColorMode: window.localStorage.getItem('color-mode') || 'light',
|
||||
useSystemColorMode: false,
|
||||
},
|
||||
});
|
||||
|
||||
export default () => (
|
||||
<React.StrictMode>
|
||||
<Provider store={store}>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import React from 'react';
|
||||
import { MdAdminPanelSettings } from 'react-icons/md';
|
||||
import { FaShoppingBag } from 'react-icons/fa';
|
||||
import { BrowserRouter, Routes as RouterRoutes, Route } from 'react-router-dom';
|
||||
import { connect } from 'react-redux';
|
||||
|
|
@ -23,7 +24,7 @@ export const Pages = [
|
|||
{
|
||||
name: 'Manage',
|
||||
path: '/manage',
|
||||
icon: null,
|
||||
icon: (<MdAdminPanelSettings />),
|
||||
element: (<Manage />),
|
||||
adminOnly: true,
|
||||
hidden: false,
|
||||
|
|
|
|||
|
|
@ -1,16 +1,14 @@
|
|||
import React from 'react';
|
||||
import { Box, Flex, Text } from '@chakra-ui/react';
|
||||
import { General as i18n } from '../i18n';
|
||||
|
||||
export default () => (
|
||||
<Box margin="2rem auto 1rem" width="max-content">
|
||||
<Flex>
|
||||
<Text>
|
||||
Made with 💙 by
|
||||
{' '}
|
||||
{`${i18n.footer.part1} `}
|
||||
<a href="https://oitsjustjose.com">oitsjustjose</a>
|
||||
{' '}
|
||||
using
|
||||
{' '}
|
||||
{` ${i18n.footer.part2} `}
|
||||
<a href="https://chakra-ui.com">Chakra-UI</a>
|
||||
</Text>
|
||||
</Flex>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
import React from 'react';
|
||||
import {
|
||||
FormControl, Input, InputGroup, InputLeftAddon, Text, useColorModeValue,
|
||||
} from '@chakra-ui/react';
|
||||
import IconTextDuo from '../IconTextDuo';
|
||||
|
||||
export default ({
|
||||
type, value, propKeyPressEvt, propSubmitEvt,
|
||||
propChangeEvt, required, error, labelText, labelIcon,
|
||||
labelBgColor, labelFgColor,
|
||||
}) => {
|
||||
const id = Math.random().toString(36);
|
||||
return (
|
||||
<FormControl
|
||||
onKeyPress={propKeyPressEvt}
|
||||
onSubmit={propSubmitEvt}
|
||||
isRequired={required}
|
||||
padding=".5rem"
|
||||
borderRadius="8px"
|
||||
margin="auto"
|
||||
>
|
||||
<InputGroup style={{ marginTop: '1rem', marginBottom: '1rem' }}>
|
||||
<InputLeftAddon backgroundColor={labelBgColor} color={labelFgColor}>
|
||||
<IconTextDuo icon={labelIcon} text={labelText} />
|
||||
</InputLeftAddon>
|
||||
<Input
|
||||
id={id}
|
||||
type={type}
|
||||
isRequired={required}
|
||||
onChange={propChangeEvt}
|
||||
background={useColorModeValue('gray.50', 'gray.700')}
|
||||
color={useColorModeValue('black', 'white')}
|
||||
value={value}
|
||||
/>
|
||||
</InputGroup>
|
||||
|
||||
<Text fontSize=".75rem" color="red.500">{error}</Text>
|
||||
</FormControl>
|
||||
);
|
||||
};
|
||||
36
frontend/src/global/components/FormControl/StandardInput.jsx
Normal file
36
frontend/src/global/components/FormControl/StandardInput.jsx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import React from 'react';
|
||||
import {
|
||||
FormControl, Input, Text, useColorModeValue,
|
||||
} from '@chakra-ui/react';
|
||||
import IconTextDuo from '../IconTextDuo';
|
||||
|
||||
export default ({
|
||||
type, value, propKeyPressEvt, propSubmitEvt,
|
||||
propChangeEvt, required, error, labelText, labelIcon,
|
||||
}) => {
|
||||
const id = Math.random().toString(36);
|
||||
return (
|
||||
<FormControl
|
||||
onKeyPress={propKeyPressEvt}
|
||||
onSubmit={propSubmitEvt}
|
||||
isRequired={required}
|
||||
padding=".5rem"
|
||||
borderRadius="8px"
|
||||
margin="auto"
|
||||
>
|
||||
<IconTextDuo icon={labelIcon} text={labelText} />
|
||||
<Input
|
||||
mt={4}
|
||||
id={id}
|
||||
type={type}
|
||||
isRequired={required}
|
||||
onChange={propChangeEvt}
|
||||
background={useColorModeValue('gray.50', 'gray.700')}
|
||||
color={useColorModeValue('black', 'white')}
|
||||
value={value}
|
||||
/>
|
||||
|
||||
<Text fontSize=".75rem" color="red.500">{error}</Text>
|
||||
</FormControl>
|
||||
);
|
||||
};
|
||||
|
|
@ -5,6 +5,7 @@ import {
|
|||
} from '@chakra-ui/react';
|
||||
import { connect } from 'react-redux';
|
||||
import store from '../../../redux/store';
|
||||
import { General as i18n } from '../../i18n';
|
||||
|
||||
const AlertModal = ({
|
||||
open, header, content,
|
||||
|
|
@ -20,7 +21,7 @@ const AlertModal = ({
|
|||
|
||||
<ModalFooter>
|
||||
<Button colorScheme="blue" mr={3} onClick={() => store.dispatch({ type: 'SET_ALERT', data: null })}>
|
||||
Close
|
||||
{i18n.close}
|
||||
</Button>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
|
|
|
|||
|
|
@ -1,32 +1,50 @@
|
|||
import React from 'react';
|
||||
import {
|
||||
Avatar, Box,
|
||||
Avatar,
|
||||
Box,
|
||||
Button,
|
||||
Flex,
|
||||
HStack,
|
||||
IconButton, Stack, useColorModeValue, useDisclosure,
|
||||
IconButton,
|
||||
Stack,
|
||||
useColorModeValue,
|
||||
useDisclosure,
|
||||
useColorMode,
|
||||
} from '@chakra-ui/react';
|
||||
import { AiOutlineClose } from 'react-icons/ai';
|
||||
import { FaHamburger } from 'react-icons/fa';
|
||||
import { connect } from 'react-redux';
|
||||
import { AiOutlineClose, AiOutlineMenu } from 'react-icons/ai';
|
||||
import { MdLogin, MdLogout } from 'react-icons/md';
|
||||
import Item from './NavbarItem';
|
||||
import { BsSunFill, BsMoonFill } from 'react-icons/bs';
|
||||
import { connect } from 'react-redux';
|
||||
import { useNavigate, useLocation } from 'react-router-dom';
|
||||
import { Pages } from '../../../Routes';
|
||||
import IconTextDuo from '../IconTextDuo';
|
||||
import { General as i18n } from '../../i18n';
|
||||
|
||||
const NavBar = ({ user }) => {
|
||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||
const { colorMode, setColorMode } = useColorMode();
|
||||
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
return (
|
||||
<Box bg={useColorModeValue('gray.100', 'gray.900')} px={4} borderRadius="8px">
|
||||
<Box bg={useColorModeValue('blackAlpha.300', 'gray.900')} px={4} borderRadius="8px">
|
||||
<Flex h={16} alignItems="center" justifyContent="space-between">
|
||||
{/* Mobile Menu Toggle Icon */}
|
||||
<IconButton
|
||||
size="md"
|
||||
icon={isOpen ? <AiOutlineClose /> : <FaHamburger />}
|
||||
aria-label="Open Menu"
|
||||
icon={isOpen ? <AiOutlineClose style={{ margin: 'auto' }} /> : <AiOutlineMenu style={{ margin: 'auto' }} />}
|
||||
aria-label={i18n.openMenu}
|
||||
display={{ md: 'none' }}
|
||||
onClick={isOpen ? onClose : onOpen}
|
||||
colorScheme="gray"
|
||||
textAlign="center"
|
||||
/>
|
||||
|
||||
<HStack spacing={8} alignItems="center">
|
||||
<Box><Avatar backgroundColor="transparent" size="sm" src="/img/icon/oc.svg" /></Box>
|
||||
<Box>
|
||||
<Avatar backgroundColor="transparent" size="sm" src="/img/icon/oc.svg" _placeholderShown={false} />
|
||||
</Box>
|
||||
<HStack
|
||||
as="nav"
|
||||
spacing={4}
|
||||
|
|
@ -37,11 +55,46 @@ const NavBar = ({ user }) => {
|
|||
.filter((x) => !x.hidden)
|
||||
.filter((x) => !x.adminOnly || (x.adminOnly && user?.admin))
|
||||
.map(({ icon, name, path }) => (
|
||||
<Item key={name} icon={icon} name={name} to={path} />
|
||||
<Button
|
||||
key={path}
|
||||
onClick={() => navigate(path, { replace: true })}
|
||||
colorScheme={location.pathname === path ? 'blue' : 'gray'}
|
||||
>
|
||||
<IconTextDuo icon={(icon)} text={name} />
|
||||
</Button>
|
||||
))
|
||||
}
|
||||
{!user && (<Item icon={(<MdLogin />)} name="Log In" to="/login" />)}
|
||||
{user && (<Item icon={(<MdLogout />)} name="Log Out" to="/logout" />) }
|
||||
|
||||
{!user && (
|
||||
<Button
|
||||
onClick={() => navigate('/login', { replace: true })}
|
||||
icon={MdLogin}
|
||||
colorScheme={location.pathname === '/login' ? 'blue' : 'gray'}
|
||||
>
|
||||
<IconTextDuo icon={(<MdLogin />)} text={i18n.login} />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{user && (
|
||||
<Button
|
||||
onClick={() => navigate('/logout', { replace: true })}
|
||||
colorScheme={location.pathname === '/logout' ? 'red' : 'gray'}
|
||||
>
|
||||
<IconTextDuo icon={(<MdLogout />)} text={i18n.logout} />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<IconButton
|
||||
icon={colorMode === 'light' ? <BsSunFill /> : <BsMoonFill />}
|
||||
aria-label={i18n.changeColorMode}
|
||||
onClick={() => {
|
||||
const newMode = colorMode === 'light' ? 'dark' : 'light';
|
||||
setColorMode(newMode);
|
||||
window.localStorage.setItem('color-mode', newMode);
|
||||
}}
|
||||
colorScheme="gray"
|
||||
textAlign="center"
|
||||
/>
|
||||
</HStack>
|
||||
</HStack>
|
||||
</Flex>
|
||||
|
|
@ -55,11 +108,34 @@ const NavBar = ({ user }) => {
|
|||
.filter((x) => !x.hidden)
|
||||
.filter((x) => !x.adminOnly || (x.adminOnly && user?.admin))
|
||||
.map(({ icon, name, path }) => (
|
||||
<Item key={name} icon={icon} name={name} to={path} />
|
||||
<Button
|
||||
key={path}
|
||||
onClick={() => navigate(path, { replace: true })}
|
||||
colorScheme={location.pathname === path ? 'blue' : 'gray'}
|
||||
>
|
||||
<IconTextDuo icon={(icon)} text={name} />
|
||||
</Button>
|
||||
))
|
||||
}
|
||||
{!user && (<Item icon={(<MdLogin />)} name="Log In" to="/login" />)}
|
||||
{user && (<Item icon={(<MdLogout />)} name="Log Out" to="/logout" />) }
|
||||
|
||||
{!user && (
|
||||
<Button
|
||||
onClick={() => navigate('/login', { replace: true })}
|
||||
icon={MdLogin}
|
||||
colorScheme={location.pathname === '/login' ? 'blue' : 'gray'}
|
||||
>
|
||||
<IconTextDuo icon={(<MdLogin />)} text={i18n.login} />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{user && (
|
||||
<Button
|
||||
onClick={() => navigate('/logout', { replace: true })}
|
||||
colorScheme={location.pathname === '/logout' ? 'blue' : 'gray'}
|
||||
>
|
||||
<IconTextDuo icon={(<MdLogout />)} text={i18n.logout} />
|
||||
</Button>
|
||||
)}
|
||||
</Stack>
|
||||
</Box>
|
||||
) : null}
|
||||
|
|
@ -67,8 +143,5 @@ const NavBar = ({ user }) => {
|
|||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = ({ user }) => ({
|
||||
user,
|
||||
});
|
||||
|
||||
const mapStateToProps = ({ user }) => ({ user });
|
||||
export default connect(mapStateToProps)(NavBar);
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
import React from 'react';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
|
||||
export default ({
|
||||
to, name, icon,
|
||||
}) => (
|
||||
<NavLink
|
||||
to={to}
|
||||
className={({ isActive }) => `chakra-button ${isActive ? 'nav-active' : 'nav-inactive'}`}
|
||||
>
|
||||
{icon && icon}
|
||||
{!!icon && !!name && (<div style={{ width: '8px' }} />)}
|
||||
{!!name && name}
|
||||
</NavLink>
|
||||
|
||||
);
|
||||
87
frontend/src/global/i18n.js
Normal file
87
frontend/src/global/i18n.js
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import LocalizedStrings from 'react-localization';
|
||||
|
||||
export const General = new LocalizedStrings({
|
||||
en: {
|
||||
close: 'Close',
|
||||
save: 'Save',
|
||||
openMenu: 'Open Menu',
|
||||
login: 'Log In',
|
||||
logout: 'Log Out',
|
||||
changeColorMode: 'Toggle Light/Dark Theme',
|
||||
footer: {
|
||||
part1: 'Made with 💙 by',
|
||||
part2: 'using',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const Home = new LocalizedStrings({
|
||||
en: {
|
||||
downloadFailedAlert: {
|
||||
header: 'Failed to Download Products',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const Manage = new LocalizedStrings({
|
||||
en: {
|
||||
create: {
|
||||
title: 'Create Product',
|
||||
fileUpload: (count) => `${count || 'No'} ${count === 1 ? 'File' : 'Files'} Selected`,
|
||||
itemCreatedSuccess: (id) => ({
|
||||
header: 'Item Added!',
|
||||
content: `Item created with ID ${id}`,
|
||||
}),
|
||||
labels: {
|
||||
name: 'Name',
|
||||
price: 'Price',
|
||||
qty: 'Quantity',
|
||||
required: 'This Field is Required',
|
||||
save: 'Save Product',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const Login = new LocalizedStrings({
|
||||
en: {
|
||||
logoutAlert: {
|
||||
header: 'You Have Been Logged Out',
|
||||
content: 'You\'ve been logged out automatically as it has been more than 1 day since you last logged in. Please log in again.',
|
||||
},
|
||||
labels: {
|
||||
register: 'Need an account? Click here!',
|
||||
email: 'Email Address',
|
||||
password: 'Password',
|
||||
required: 'This Field is Required',
|
||||
},
|
||||
buttons: {
|
||||
submit: 'Log In',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const Register = new LocalizedStrings({
|
||||
en: {
|
||||
createAccountSuccess: {
|
||||
header: 'Account Created!',
|
||||
content: 'You\'ll receive an account confirmation email shortly! Sit tight until you have verified your account.',
|
||||
},
|
||||
createAccountFailure: ({ error }) => ({
|
||||
header: 'Unable to Create Account',
|
||||
content: error,
|
||||
}),
|
||||
labels: {
|
||||
login: 'Already have an account? Sign in here!',
|
||||
first: 'First Name',
|
||||
last: 'Last Name',
|
||||
email: 'Email Address',
|
||||
password: 'Password',
|
||||
conf: 'Verify Password',
|
||||
match: 'Passwords must match',
|
||||
required: 'This Field is Required',
|
||||
privacy: 'None of this information will be shared',
|
||||
register: 'Register',
|
||||
},
|
||||
},
|
||||
});
|
||||
52
frontend/src/pages/Home/components/Card.jsx
Normal file
52
frontend/src/pages/Home/components/Card.jsx
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import React from 'react';
|
||||
import {
|
||||
Box,
|
||||
useColorModeValue,
|
||||
Heading,
|
||||
Text,
|
||||
Stack,
|
||||
Image,
|
||||
} from '@chakra-ui/react';
|
||||
|
||||
export default ({ product }) => {
|
||||
const images = product.images.filter((x) => !!x) || ['https://dv2ls.com/f/PpMcVb8gN'];
|
||||
return (
|
||||
<Box
|
||||
margin="auto"
|
||||
role="group"
|
||||
maxW="330px"
|
||||
w="full"
|
||||
bg={useColorModeValue('blackAlpha.300', 'gray.700')}
|
||||
transition="all .3s ease"
|
||||
cursor="pointer"
|
||||
rounded="lg"
|
||||
pos="relative"
|
||||
zIndex={1}
|
||||
_hover={{
|
||||
transition: 'all .3s ease',
|
||||
boxShadow: 'var(--chakra-shadows-2xl)',
|
||||
transform: 'scale(105%)',
|
||||
}}
|
||||
>
|
||||
<Box rounded="lg" pos="relative" height="256px">
|
||||
<Image
|
||||
loading="lazy"
|
||||
roundedTopLeft="lg"
|
||||
roundedTopRight="lg"
|
||||
height={230}
|
||||
width="100%"
|
||||
objectFit="cover"
|
||||
src={images[0]}
|
||||
/>
|
||||
</Box>
|
||||
<Stack p={6} align="center">
|
||||
<Heading fontSize="2xl" fontFamily="body" fontWeight={500}>
|
||||
{product.name}
|
||||
</Heading>
|
||||
<Text color="gray.500" fontSize="sm" textTransform="uppercase">
|
||||
{product.quantity === 0 ? 'Sold Out' : `$${product.price}`}
|
||||
</Text>
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,22 +1,47 @@
|
|||
/* eslint-disable max-len */
|
||||
import React from 'react';
|
||||
import { Heading, Text } from '@chakra-ui/react';
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Heading, Grid, GridItem } from '@chakra-ui/react';
|
||||
import { connect } from 'react-redux';
|
||||
import store from '../../redux/store';
|
||||
import Card from './components/Card';
|
||||
import { Home as i18n } from '../../global/i18n';
|
||||
|
||||
const Home = ({ user }) => (
|
||||
<div>
|
||||
<Heading textAlign="center">
|
||||
Hello
|
||||
{' '}
|
||||
{user?.first}
|
||||
!
|
||||
</Heading>
|
||||
const Home = ({ user }) => {
|
||||
const [products, setProducts] = useState([]);
|
||||
|
||||
<Text>
|
||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Laborum itaque hic pariatur ad voluptates possimus amet nostrum officia, nesciunt voluptatem. Eligendi reprehenderit explicabo, illo dolores, nemo minus facere voluptatibus eius fugit odit similique eum ullam. Assumenda reprehenderit hic nesciunt amet soluta? Aliquid accusamus architecto itaque ex, quibusdam suscipit libero voluptate eos pariatur, laudantium nulla inventore placeat. Sunt ex ut repudiandae architecto aspernatur quas, explicabo ipsa? Eligendi provident aperiam rem officiis quam dignissimos neque culpa a beatae iusto recusandae quaerat facilis, quidem, veritatis iste consectetur, est pariatur maxime repudiandae ipsa fugiat reiciendis rerum repellat voluptatum. Nihil laborum quisquam, omnis maiores, excepturi asperiores repellat repudiandae error voluptatem corporis tenetur! Non totam asperiores nam commodi suscipit. At animi unde aperiam deleniti ratione provident, fugit quam sunt error quis ad vitae reprehenderit! Mollitia soluta excepturi aspernatur iste reprehenderit, unde quidem necessitatibus animi. Veritatis, voluptatibus ullam autem, perspiciatis sequi debitis sunt, reiciendis placeat quasi perferendis quia exercitationem corporis. Minima consequatur a recusandae veniam explicabo, nihil praesentium doloribus, sapiente nulla totam aliquid corrupti quod. Obcaecati facilis vitae quia soluta consequuntur atque sed veniam ducimus exercitationem illo, numquam officia. Numquam, quae! Pariatur error alias ipsum ad, est harum animi nesciunt. Voluptatibus, cum illum modi rerum mollitia, consequuntur repudiandae voluptatum repellendus, dolorum eum harum neque exercitationem velit repellat. Repudiandae hic similique deleniti et. Nihil qui architecto quasi assumenda explicabo quas eius, odit aspernatur repellendus a veniam? Nesciunt, minima amet illum eligendi voluptate et maiores magnam, possimus corrupti, est voluptatem odit architecto culpa. Culpa sed omnis nobis in deleniti, corrupti minima repellendus non repudiandae qui dolorum numquam? A eos cumque doloremque, consequuntur maiores numquam adipisci obcaecati minima labore odio consectetur, magni ea in veritatis magnam, iusto quidem maxime! Accusantium possimus quia nisi corrupti amet! Neque autem quaerat harum eveniet libero et nemo illo porro quis itaque corporis fugiat facilis, nesciunt possimus tempore. Porro odit, voluptatum sapiente eveniet deleniti ex illum a! Ipsam earum, incidunt expedita provident nulla distinctio quaerat aliquam culpa repellendus vitae ipsum quae pariatur tempore placeat saepe sint quisquam inventore quasi ratione eum error esse maiores? Eveniet reprehenderit cupiditate veniam, dolorum dignissimos earum molestiae, asperiores fugiat magnam fugit accusamus, eum neque architecto error deserunt ipsum excepturi. Vel debitis laborum, fuga mollitia nesciunt necessitatibus architecto commodi quas exercitationem, alias odit consectetur eaque quaerat at dicta. Numquam quae sunt aliquid, dicta maiores doloremque, quos inventore esse facere excepturi porro, dolorem at eveniet assumenda eos minus iure voluptate ab incidunt odio illo tenetur asperiores deserunt. Eum eligendi dolorem ex labore earum molestias aspernatur, nostrum veniam tempora odio at nesciunt officia provident sit excepturi, deleniti pariatur ipsam harum quia? Soluta quam quas sit accusantium commodi! Dolor aperiam voluptatibus quos aspernatur a. Magni, quas dolor. Maxime molestias adipisci iste cumque quibusdam. Accusantium optio voluptate maxime facilis aspernatur odio blanditiis maiores, eius ad architecto reprehenderit quos iure facere, commodi quisquam labore, ullam itaque excepturi dolores ipsa eveniet incidunt deleniti ratione ut. Eveniet magnam provident, cupiditate, nisi ab porro temporibus mollitia, architecto dicta qui totam! Repellat, aliquid commodi. Unde vel esse accusamus velit omnis possimus, ducimus perspiciatis nobis necessitatibus corporis doloremque rem. Iste necessitatibus asperiores, rem excepturi illum ad repellat eveniet autem animi reiciendis veniam facere consectetur vel quis debitis, dolorem, placeat eius non! Quia doloremque nam a pariatur?
|
||||
</Text>
|
||||
</div>
|
||||
);
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const resp = await fetch('/api/v1/products');
|
||||
const data = await resp.json();
|
||||
if (resp.ok) {
|
||||
setProducts(data);
|
||||
} else {
|
||||
store.dispatch({ type: 'SET_ALERT', data: { header: i18n.downloadFailedAlert.header, content: JSON.stringify(data.error) } });
|
||||
}
|
||||
})();
|
||||
|
||||
return () => {};
|
||||
}, [products, setProducts]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Heading textAlign="center">
|
||||
Hello
|
||||
{' '}
|
||||
{user?.first}
|
||||
!
|
||||
</Heading>
|
||||
|
||||
<Grid templateColumns="repeat(auto-fit, minmax(384px, 1fr));" rowGap={6}>
|
||||
{products.map((x) => (
|
||||
<GridItem key={x._id}>
|
||||
<Card product={x} />
|
||||
</GridItem>
|
||||
))}
|
||||
</Grid>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = ({ user }) => ({ user });
|
||||
export default connect(mapStateToProps)(Home);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import {
|
|||
Input, InputGroup, InputLeftElement, Icon,
|
||||
} from '@chakra-ui/react';
|
||||
import { FiFile } from 'react-icons/fi';
|
||||
import { Manage as i18n } from '../../../global/i18n';
|
||||
|
||||
export const FileUpload = ({
|
||||
name,
|
||||
|
|
@ -39,7 +40,8 @@ export const FileUpload = ({
|
|||
placeholder={placeholder || 'Your file ...'}
|
||||
onClick={() => inputRef.current.click()}
|
||||
readOnly
|
||||
value={`${files.length || 'No'} ${files.length === 1 ? 'File' : 'Files'} Selected`}
|
||||
background="blue.300"
|
||||
value={i18n.create.fileUpload(files.length)}
|
||||
/>
|
||||
</InputGroup>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
Button,
|
||||
FormControl, Heading, Input, InputGroup, InputLeftAddon,
|
||||
Box, Button, FormControl, Heading, InputGroup, InputLeftAddon, Text,
|
||||
} from '@chakra-ui/react';
|
||||
import CurrencyInput from 'react-currency-input-field';
|
||||
import { AiOutlineNumber } from 'react-icons/ai';
|
||||
import { AiOutlineFileText, AiOutlineNumber } from 'react-icons/ai';
|
||||
import { BsCurrencyDollar } from 'react-icons/bs';
|
||||
import { MdTextFields } from 'react-icons/md';
|
||||
import InlineLabelInput from '../../global/components/FormControl/InlineLabelInput';
|
||||
import IconTextDuo from '../../global/components/IconTextDuo';
|
||||
import { Manage as i18n } from '../../global/i18n';
|
||||
import store from '../../redux/store';
|
||||
import { FileUpload } from './components/FileUpload';
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ const uploadImage = async (file) => {
|
|||
const { output, error } = await resp.json();
|
||||
if (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
error(error);
|
||||
console.error(error);
|
||||
return null;
|
||||
}
|
||||
return `/api/v1/fileupload/${output}`;
|
||||
|
|
@ -33,13 +33,18 @@ export default () => {
|
|||
const [loading, setLoading] = useState(false);
|
||||
const [state, setState] = useState({
|
||||
name: '',
|
||||
quantity: 0,
|
||||
price: 0.0,
|
||||
quantity: null,
|
||||
price: null,
|
||||
images: [],
|
||||
});
|
||||
|
||||
const save = async () => {
|
||||
setLoading(true);
|
||||
if (!state.name.length || !state.quantity || !state.price) {
|
||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Missing Info', content: 'Not all required fields have been filled. Please provide this info to proceed.' } });
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// Step 1: Upload image files
|
||||
const imageUrls = await Promise.all(state.images.map(uploadImage));
|
||||
|
|
@ -74,7 +79,7 @@ export default () => {
|
|||
useEffect(() => {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
if (params.has('_id')) {
|
||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Item Added!', content: `Item created with ID ${params.get('_id')}` } });
|
||||
store.dispatch({ type: 'SET_ALERT', data: { ...i18n.create.itemCreatedSuccess(params.get('_id')) } });
|
||||
window.history.replaceState(null, null, window.location.pathname);
|
||||
}
|
||||
return () => {};
|
||||
|
|
@ -82,78 +87,113 @@ export default () => {
|
|||
|
||||
return (
|
||||
<div>
|
||||
<Heading textAlign="center" marginBottom="1rem">Create Product</Heading>
|
||||
<Heading textAlign="center" marginBottom="1rem">
|
||||
{i18n.create.title}
|
||||
</Heading>
|
||||
|
||||
<FormControl
|
||||
onKeyPress={(e) => e.key === 'Enter' && save()}
|
||||
onSubmit={save}
|
||||
backgroundColor="gray.100"
|
||||
<Box
|
||||
borderRadius="2xl"
|
||||
padding="2rem"
|
||||
borderRadius="8px"
|
||||
maxW="50%"
|
||||
backgroundColor="blackAlpha.200"
|
||||
w="100%"
|
||||
maxW="768px"
|
||||
margin="auto"
|
||||
>
|
||||
<InputGroup style={InputGroupStyle}>
|
||||
<InputLeftAddon backgroundColor="#fa6663" color="black"><IconTextDuo icon={(<MdTextFields />)} text="Name" /></InputLeftAddon>
|
||||
<Input
|
||||
id="name"
|
||||
type="text"
|
||||
required
|
||||
value={state.name}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, name: e.target.value })}
|
||||
/>
|
||||
</InputGroup>
|
||||
<InlineLabelInput
|
||||
required
|
||||
type="text"
|
||||
propSubmitEvt={save}
|
||||
propChangeEvt={(e) => setState({ ...state, name: e.target.value })}
|
||||
propKeyPressEvt={(e) => e.key === 'Enter' && save()}
|
||||
value={state.name}
|
||||
labelText={i18n.create.labels.name}
|
||||
labelIcon={(<AiOutlineFileText />)}
|
||||
labelBgColor="#fa6663"
|
||||
labelFgColor="black"
|
||||
error={!state.name.length ? i18n.create.labels.required : null}
|
||||
/>
|
||||
|
||||
<InputGroup style={InputGroupStyle}>
|
||||
<InputLeftAddon backgroundColor="#8a56c2" color="white"><IconTextDuo icon={(<AiOutlineNumber />)} text="Qty" /></InputLeftAddon>
|
||||
{/* Use currency input to nicely handle whole numerical values */}
|
||||
<CurrencyInput
|
||||
prefix=""
|
||||
defaultValue={state.quantity}
|
||||
allowDecimals={false}
|
||||
className="chakra-input currency"
|
||||
onValueChange={(value) => setState({
|
||||
...state, quantity: JSON.parse(value),
|
||||
})}
|
||||
/>
|
||||
</InputGroup>
|
||||
<FormControl
|
||||
onSubmit={save}
|
||||
onKeyPress={(e) => e.key === 'Enter' && save()}
|
||||
isRequired
|
||||
padding=".5rem"
|
||||
borderRadius="8px"
|
||||
margin="auto"
|
||||
>
|
||||
<InputGroup style={InputGroupStyle}>
|
||||
<InputLeftAddon backgroundColor="#8a56c2" color="white">
|
||||
<IconTextDuo icon={(<AiOutlineNumber />)} text="Qty" />
|
||||
</InputLeftAddon>
|
||||
{/* Use currency input to nicely handle whole numerical values */}
|
||||
<CurrencyInput
|
||||
prefix=""
|
||||
allowDecimals={false}
|
||||
className="chakra-input currency"
|
||||
onValueChange={(value) => setState({
|
||||
...state, quantity: JSON.parse(value),
|
||||
})}
|
||||
/>
|
||||
</InputGroup>
|
||||
<Text fontSize=".75rem" color="red.500">{!state.quantity ? i18n.create.labels.required : null}</Text>
|
||||
</FormControl>
|
||||
|
||||
<InputGroup style={InputGroupStyle}>
|
||||
<InputLeftAddon backgroundColor="#fbb355" color="black"><IconTextDuo icon={(<BsCurrencyDollar />)} text="Price" /></InputLeftAddon>
|
||||
<CurrencyInput
|
||||
prefix="$"
|
||||
placeholder="Price"
|
||||
defaultValue={state.price}
|
||||
decimalsLimit={2}
|
||||
className="chakra-input currency"
|
||||
onValueChange={(value) => setState({
|
||||
...state, price: JSON.parse(value),
|
||||
})}
|
||||
/>
|
||||
</InputGroup>
|
||||
|
||||
<InputGroup style={InputGroupStyle}>
|
||||
<FileUpload
|
||||
name="image"
|
||||
acceptedFileTypes="image/*"
|
||||
required
|
||||
allowMultipleFiles
|
||||
propagateChange={(evt) => setState({ ...state, images: Array.from(evt.target.files) })}
|
||||
style={{ cursor: 'pointer !important' }}
|
||||
/>
|
||||
</InputGroup>
|
||||
<FormControl
|
||||
onSubmit={save}
|
||||
onKeyPress={(e) => e.key === 'Enter' && save()}
|
||||
isRequired
|
||||
padding=".5rem"
|
||||
borderRadius="8px"
|
||||
margin="auto"
|
||||
>
|
||||
<InputGroup style={InputGroupStyle}>
|
||||
<InputLeftAddon backgroundColor="#fbb355" color="black"><IconTextDuo icon={(<BsCurrencyDollar />)} text="Price" /></InputLeftAddon>
|
||||
<CurrencyInput
|
||||
prefix="$"
|
||||
decimalsLimit={2}
|
||||
className="chakra-input currency"
|
||||
onValueChange={(value) => setState({
|
||||
...state, price: JSON.parse(value),
|
||||
})}
|
||||
/>
|
||||
</InputGroup>
|
||||
<Text fontSize=".75rem" color="red.500">{!state.price ? i18n.create.labels.required : null}</Text>
|
||||
</FormControl>
|
||||
<FormControl
|
||||
onSubmit={save}
|
||||
onKeyPress={(e) => e.key === 'Enter' && save()}
|
||||
isRequired
|
||||
padding=".5rem"
|
||||
borderRadius="8px"
|
||||
margin="auto"
|
||||
>
|
||||
<InputGroup style={InputGroupStyle}>
|
||||
<FileUpload
|
||||
name="image"
|
||||
acceptedFileTypes="image/*"
|
||||
required
|
||||
allowMultipleFiles
|
||||
propagateChange={(evt) => setState({
|
||||
...state,
|
||||
images: Array.from(evt.target.files),
|
||||
})}
|
||||
/>
|
||||
</InputGroup>
|
||||
<Text fontSize=".75rem" color="red.500">{state.images.length === 0 ? i18n.create.labels.required : null}</Text>
|
||||
</FormControl>
|
||||
|
||||
<Button
|
||||
display="block"
|
||||
mx="auto"
|
||||
mt={4}
|
||||
colorScheme="blue"
|
||||
colorScheme="green"
|
||||
isLoading={loading}
|
||||
type="submit"
|
||||
onClick={save}
|
||||
>
|
||||
Submit
|
||||
{i18n.create.labels.save}
|
||||
</Button>
|
||||
</FormControl>
|
||||
</Box>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
import React, { useState } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
Button, FormControl, FormLabel, Input, Heading, Text,
|
||||
Button, Heading, Text, Box,
|
||||
} 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';
|
||||
import StandardInput from '../../global/components/FormControl/StandardInput';
|
||||
import IconTextDuo from '../../global/components/IconTextDuo';
|
||||
import { Login as i18n } from '../../global/i18n';
|
||||
|
||||
export default () => {
|
||||
const [state, setState] = useState({ email: '', password: '' });
|
||||
|
|
@ -13,6 +15,7 @@ export default () => {
|
|||
const navigate = useNavigate();
|
||||
|
||||
const login = async () => {
|
||||
if (state.email.length === 0 || state.password.length === 0) return;
|
||||
setLoading(true);
|
||||
|
||||
const resp = await fetch('/api/v1/user/auth/login', {
|
||||
|
|
@ -38,58 +41,86 @@ export default () => {
|
|||
setLoading(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
if (params.has('invalidOrExpired')) {
|
||||
store.dispatch({
|
||||
type: 'SET_ALERT',
|
||||
data: {
|
||||
header: i18n.logoutAlert.header,
|
||||
content: i18n.logoutAlert.content,
|
||||
},
|
||||
});
|
||||
|
||||
// Remove the query to prevent it being annoying
|
||||
params.delete('invalidOrExpired');
|
||||
navigate({
|
||||
pathname: window.location.pathname,
|
||||
search: params.toString(),
|
||||
}, { replace: true });
|
||||
}
|
||||
return () => {};
|
||||
}, []);
|
||||
|
||||
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
|
||||
color="purple.600"
|
||||
cursor="pointer"
|
||||
transition="all"
|
||||
textAlign="center"
|
||||
marginBottom="0.5rem"
|
||||
onClick={() => navigate('/register', { replace: true })}
|
||||
_hover={{ fontWeight: 600, color: 'var(--chakra-colors-purple-500) !important' }}
|
||||
>
|
||||
{i18n.labels.register}
|
||||
</Text>
|
||||
|
||||
<FormControl
|
||||
onKeyPress={(e) => e.key === 'Enter' && login()}
|
||||
onSubmit={login}
|
||||
backgroundColor="gray.100"
|
||||
<Box
|
||||
borderRadius="2xl"
|
||||
padding="2rem"
|
||||
borderRadius="8px"
|
||||
maxW="50%"
|
||||
backgroundColor="blackAlpha.200"
|
||||
w="100%"
|
||||
maxW="768px"
|
||||
margin="auto"
|
||||
>
|
||||
<FormLabel htmlFor="email">
|
||||
<IconTextDuo icon={(<MdAlternateEmail />)} text="Email" />
|
||||
</FormLabel>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
<StandardInput
|
||||
required
|
||||
type="email"
|
||||
propSubmitEvt={login}
|
||||
propChangeEvt={(e) => setState({ ...state, email: e.target.value })}
|
||||
propKeyPressEvt={(e) => e.key === 'Enter' && login()}
|
||||
value={state.email}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, email: e.target.value })}
|
||||
labelText={i18n.labels.email}
|
||||
labelIcon={(<MdAlternateEmail />)}
|
||||
error={!state.email.length ? i18n.labels.required : null}
|
||||
/>
|
||||
|
||||
<FormLabel htmlFor="password">
|
||||
<IconTextDuo icon={(<MdPassword />)} text="Password" />
|
||||
</FormLabel>
|
||||
<Input
|
||||
id="password"
|
||||
type="Password"
|
||||
<StandardInput
|
||||
required
|
||||
type="password"
|
||||
propSubmitEvt={login}
|
||||
propChangeEvt={(e) => setState({ ...state, password: e.target.value })}
|
||||
propKeyPressEvt={(e) => e.key === 'Enter' && login()}
|
||||
value={state.password}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, password: e.target.value })}
|
||||
labelText={i18n.labels.password}
|
||||
labelIcon={(<MdPassword />)}
|
||||
error={!state.password.length ? i18n.labels.required : null}
|
||||
/>
|
||||
|
||||
<Button
|
||||
display="block"
|
||||
mt={4}
|
||||
colorScheme="blue"
|
||||
mx="auto"
|
||||
colorScheme="green"
|
||||
isLoading={loading}
|
||||
type="submit"
|
||||
onClick={login}
|
||||
>
|
||||
<IconTextDuo iconOnRight icon={(<MdLogin />)} text="Log In" />
|
||||
<IconTextDuo iconOnRight icon={(<MdLogin />)} text={i18n.buttons.submit} />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</Box>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import React, { useState } from 'react';
|
||||
import {
|
||||
Button, FormControl, FormLabel, Input, Heading, Text, FormHelperText,
|
||||
Button, Heading, Text, Box,
|
||||
} 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';
|
||||
import { Register as i18n } from '../../global/i18n';
|
||||
import StandardInput from '../../global/components/FormControl/StandardInput';
|
||||
|
||||
export default () => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
|
@ -25,105 +27,115 @@ export default () => {
|
|||
});
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
const message = resp.ok ? i18n.createAccountSuccess : i18n.createAccountFailure(data);
|
||||
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
|
||||
color="purple.600"
|
||||
cursor="pointer"
|
||||
transition="all"
|
||||
textAlign="center"
|
||||
marginBottom="0.5rem"
|
||||
onClick={() => navigate('/login', { replace: true })}
|
||||
_hover={{ fontWeight: 600, color: 'var(--chakra-colors-purple-500) !important' }}
|
||||
>
|
||||
{i18n.labels.login}
|
||||
</Text>
|
||||
|
||||
<FormControl
|
||||
onKeyPress={(e) => e.key === 'Enter' && register()}
|
||||
onSubmit={register}
|
||||
backgroundColor="gray.100"
|
||||
<Box
|
||||
borderRadius="2xl"
|
||||
padding="2rem"
|
||||
borderRadius="8px"
|
||||
maxW="50%"
|
||||
backgroundColor="blackAlpha.200"
|
||||
w="100%"
|
||||
maxW="768px"
|
||||
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"
|
||||
<StandardInput
|
||||
required
|
||||
type="text"
|
||||
propSubmitEvt={register}
|
||||
propKeyPressEvt={(e) => e.key === 'Enter' && register()}
|
||||
propChangeEvt={(e) => setState({ ...state, first: e.target.value })}
|
||||
value={state.first}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, first: e.target.value })}
|
||||
labelText={i18n.labels.first}
|
||||
labelIcon={(<BiRename />)}
|
||||
error={!state.first.length ? i18n.labels.required : null}
|
||||
/>
|
||||
|
||||
<FormLabel htmlFor="last">
|
||||
<IconTextDuo icon={(<BiRename />)} text="Last Name" />
|
||||
</FormLabel>
|
||||
<Input
|
||||
id="last"
|
||||
<StandardInput
|
||||
required
|
||||
type="text"
|
||||
required
|
||||
propSubmitEvt={register}
|
||||
propKeyPressEvt={(e) => e.key === 'Enter' && register()}
|
||||
propChangeEvt={(e) => setState({ ...state, last: e.target.value })}
|
||||
value={state.last}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, last: e.target.value })}
|
||||
labelText={i18n.labels.last}
|
||||
labelIcon={(<BiRename />)}
|
||||
error={!state.last.length ? i18n.labels.required : null}
|
||||
/>
|
||||
|
||||
<FormLabel htmlFor="email">
|
||||
<IconTextDuo icon={(<MdAlternateEmail />)} text="Email" />
|
||||
</FormLabel>
|
||||
<Input
|
||||
id="email"
|
||||
<StandardInput
|
||||
required
|
||||
type="email"
|
||||
required
|
||||
propSubmitEvt={register}
|
||||
propKeyPressEvt={(e) => e.key === 'Enter' && register()}
|
||||
propChangeEvt={(e) => setState({ ...state, email: e.target.value })}
|
||||
value={state.email}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, email: e.target.value })}
|
||||
labelText={i18n.labels.email}
|
||||
labelIcon={(<MdAlternateEmail />)}
|
||||
error={!state.email.length ? i18n.labels.required : null}
|
||||
/>
|
||||
|
||||
<FormLabel htmlFor="password">
|
||||
<IconTextDuo icon={(<MdPassword />)} text="Password" />
|
||||
</FormLabel>
|
||||
<Input
|
||||
id="password"
|
||||
type="Password"
|
||||
<StandardInput
|
||||
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"
|
||||
propSubmitEvt={register}
|
||||
propKeyPressEvt={(e) => e.key === 'Enter' && register()}
|
||||
propChangeEvt={(e) => setState({ ...state, password: e.target.value })}
|
||||
value={state.password}
|
||||
labelText={i18n.labels.password}
|
||||
labelIcon={(<MdPassword />)}
|
||||
error={(!state.password.length && i18n.labels.required)
|
||||
|| (state.password !== state.conf && i18n.labels.match)
|
||||
|| null}
|
||||
/>
|
||||
|
||||
<StandardInput
|
||||
required
|
||||
type="password"
|
||||
propSubmitEvt={register}
|
||||
propKeyPressEvt={(e) => e.key === 'Enter' && register()}
|
||||
propChangeEvt={(e) => setState({ ...state, conf: e.target.value })}
|
||||
value={state.conf}
|
||||
background="gray.50"
|
||||
onChange={(e) => setState({ ...state, conf: e.target.value })}
|
||||
labelText={i18n.labels.conf}
|
||||
labelIcon={(<MdPassword />)}
|
||||
error={(!state.conf.length && i18n.labels.required)
|
||||
|| (state.password !== state.conf && i18n.labels.match)
|
||||
|| null}
|
||||
/>
|
||||
|
||||
<Button
|
||||
display="block"
|
||||
mt={4}
|
||||
colorScheme="blue"
|
||||
mx="auto"
|
||||
colorScheme="green"
|
||||
isLoading={loading}
|
||||
type="submit"
|
||||
onClick={register}
|
||||
>
|
||||
<IconTextDuo iconOnRight icon={(<MdSend />)} text="Register" />
|
||||
<IconTextDuo
|
||||
iconOnRight
|
||||
icon={<MdSend />}
|
||||
text={i18n.labels.register}
|
||||
/>
|
||||
</Button>
|
||||
</FormControl>
|
||||
</Box>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ const decodeAndDispatch = async (token) => {
|
|||
if (resp.status === 410 && window.localStorage.getItem('auth-token')) {
|
||||
window.localStorage.removeItem('auth-token');
|
||||
}
|
||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Login Is Invalid', content: resp.error } });
|
||||
window.location.href = '/login?invalidOrExpired=true';
|
||||
}
|
||||
} catch (ex) {
|
||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Login Is Invalid', content: ex } });
|
||||
window.location.href = '/login?invalidOrExpired=true';
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue