Color and I18n support
This commit is contained in:
parent
523f537aa4
commit
ba82c13fe1
19 changed files with 630 additions and 303 deletions
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>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue