UI tweaks and fixes
This commit is contained in:
parent
0440003a02
commit
cb889cc826
10 changed files with 94 additions and 96 deletions
|
|
@ -22,11 +22,12 @@ export default async (req: Request, res: Response) => {
|
||||||
.json({ error: `No such product with ID ${req.params.id} found` });
|
.json({ error: `No such product with ID ${req.params.id} found` });
|
||||||
}
|
}
|
||||||
|
|
||||||
product.quantity = req.body.quantity || product.quantity;
|
req.body.name && (product.name = req.body.name);
|
||||||
product.price = req.body.price || product.price;
|
req.body.description && (product.description = req.body.description);
|
||||||
product.hidden = req.body.hidden || product.hidden;
|
req.body.quantity && (product.quantity = req.body.quantity);
|
||||||
product.description = req.body.description || product.description;
|
req.body.price && (product.price = req.body.price);
|
||||||
product.images = req.body.images || product.images;
|
req.body.images && (product.images = req.body.images);
|
||||||
|
req.body.hidden && (product.hidden = req.body.hidden);
|
||||||
|
|
||||||
await product.save();
|
await product.save();
|
||||||
return res.status(200).json(product);
|
return res.status(200).json(product);
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ const theme = extendTheme({
|
||||||
label: {
|
label: {
|
||||||
...activeLabelStyles,
|
...activeLabelStyles,
|
||||||
},
|
},
|
||||||
|
textarea: {
|
||||||
|
paddingTop: 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
'input:not(:placeholder-shown) + label, .chakra-select__wrapper + label':
|
'input:not(:placeholder-shown) + label, .chakra-select__wrapper + label':
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,4 +11,7 @@ export const uploadImage = async (file) => {
|
||||||
return `/api/v1/fileupload/${output}`;
|
return `/api/v1/fileupload/${output}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default uploadImage;
|
export const getAuthHeaders = () => ({
|
||||||
|
authorization: `Bearer ${window.localStorage.getItem('auth-token')}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ export const General = new LocalizedStrings({
|
||||||
yes: 'Yes',
|
yes: 'Yes',
|
||||||
no: 'No',
|
no: 'No',
|
||||||
close: 'Close',
|
close: 'Close',
|
||||||
|
cancel: 'Cancel',
|
||||||
save: 'Save',
|
save: 'Save',
|
||||||
openMenu: 'Open Menu',
|
openMenu: 'Open Menu',
|
||||||
login: 'Log In',
|
login: 'Log In',
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import { BsStarFill, BsStarHalf } from 'react-icons/bs';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
export default ({ product }) => {
|
export default ({ product }) => {
|
||||||
const filtered = product.images.filter((x) => !!x);
|
const filtered = product.images.filter((x) => x !== null);
|
||||||
const images = filtered.length ? filtered : ['https://dv2ls.com/f/PpMcVb8gN'];
|
const images = filtered.length ? filtered : ['https://dv2ls.com/f/PpMcVb8gN'];
|
||||||
const nav = useNavigate();
|
const nav = useNavigate();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,19 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
Button, Modal, ModalBody,
|
Modal, ModalBody,
|
||||||
ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay,
|
ModalCloseButton, ModalContent, ModalHeader, ModalOverlay,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { General as i18n } from '../../../global/i18n';
|
|
||||||
|
|
||||||
export default ({
|
export default ({
|
||||||
open, header, superOnClose, size, children,
|
open, header, superOnClose, size, children,
|
||||||
}) => (
|
}) => (
|
||||||
<Modal isOpen={open} onClose={superOnClose} size={size || 'md'}>
|
<Modal
|
||||||
|
isOpen={open}
|
||||||
|
onClose={superOnClose}
|
||||||
|
size={size || 'md'}
|
||||||
|
closeOnOverlayClick={false}
|
||||||
|
closeOnEsc={false}
|
||||||
|
>
|
||||||
<ModalOverlay />
|
<ModalOverlay />
|
||||||
<ModalContent>
|
<ModalContent>
|
||||||
<ModalHeader>{header}</ModalHeader>
|
<ModalHeader>{header}</ModalHeader>
|
||||||
|
|
@ -16,12 +21,6 @@ export default ({
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
{children}
|
{children}
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
|
|
||||||
<ModalFooter>
|
|
||||||
<Button colorScheme="blue" mr={3} onClick={superOnClose}>
|
|
||||||
{i18n.close}
|
|
||||||
</Button>
|
|
||||||
</ModalFooter>
|
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,14 @@ import { Manage as i18n } from '../../../../global/i18n';
|
||||||
import store from '../../../../redux/store';
|
import store from '../../../../redux/store';
|
||||||
import FileUpload from '../FileUpload';
|
import FileUpload from '../FileUpload';
|
||||||
import DeletableImage from '../DeletableImage';
|
import DeletableImage from '../DeletableImage';
|
||||||
import { uploadImage } from '../../../../global/api';
|
import { getAuthHeaders, uploadImage } from '../../../../global/api';
|
||||||
|
|
||||||
const InputGroupStyle = {
|
const InputGroupStyle = {
|
||||||
marginTop: '1rem',
|
marginTop: '1rem',
|
||||||
marginBottom: '1rem',
|
marginBottom: '1rem',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ({ product }) => {
|
export default ({ product, closeModal }) => {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
name: product.name,
|
name: product.name,
|
||||||
|
|
@ -35,37 +35,30 @@ export default ({ product }) => {
|
||||||
if (!state.name.length || !state.quantity || !state.price || !state.description) {
|
if (!state.name.length || !state.quantity || !state.price || !state.description) {
|
||||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Missing Info', content: 'Not all required fields have been filled. Please provide this info to proceed.' } });
|
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);
|
setLoading(false);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Step 1: Upload image files
|
|
||||||
// Join the old image files with the new ones as well
|
|
||||||
const imageUrls = (await Promise.all(state.newImages.map(uploadImage))).concat(state.images);
|
const imageUrls = (await Promise.all(state.newImages.map(uploadImage))).concat(state.images);
|
||||||
// Step 2: Upload the rest
|
|
||||||
// eslint-disable-next-line no-underscore-dangle
|
// eslint-disable-next-line no-underscore-dangle
|
||||||
const resp = await fetch(`/api/v1/products/${product._id}`, {
|
const resp = await fetch(`/api/v1/products/${product._id}`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
headers: {
|
headers: getAuthHeaders(),
|
||||||
authorization: `Bearer ${window.localStorage.getItem('auth-token')}`,
|
body: JSON.stringify({ ...state, images: imageUrls }),
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
...state,
|
|
||||||
images: imageUrls.length,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
if (resp.ok) {
|
if (resp.ok) {
|
||||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Item Updated Successfully!', content: 'Your Changes have Been Saved and Will Be Reflected on the Management Page' } });
|
store.dispatch({ type: 'SET_ALERT', data: { header: 'Item Updated Successfully!', content: 'Your Changes have Been Saved and Will Be Reflected on the Management Page' } });
|
||||||
} else {
|
setLoading(false);
|
||||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Failed to Add Item', content: JSON.stringify(data) } });
|
return true;
|
||||||
}
|
}
|
||||||
|
store.dispatch({ type: 'SET_ALERT', data: { header: 'Failed to Add Item', content: JSON.stringify(data) } });
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Failed to Edit Item in Catch Block', content: ex } });
|
store.dispatch({ type: 'SET_ALERT', data: { header: 'Failed to Edit Item in Catch Block', content: ex } });
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -85,9 +78,9 @@ export default ({ product }) => {
|
||||||
<InlineLabelInput
|
<InlineLabelInput
|
||||||
required
|
required
|
||||||
type="text"
|
type="text"
|
||||||
propSubmitEvt={save}
|
propSubmitEvt={() => {}}
|
||||||
|
propKeyPressEvt={() => {}}
|
||||||
propChangeEvt={(e) => setState({ ...state, name: e.target.value })}
|
propChangeEvt={(e) => setState({ ...state, name: e.target.value })}
|
||||||
propKeyPressEvt={(e) => e.key === 'Enter' && save()}
|
|
||||||
value={state.name}
|
value={state.name}
|
||||||
labelText={i18n.labels.name}
|
labelText={i18n.labels.name}
|
||||||
labelIcon={(<AiOutlineFileText />)}
|
labelIcon={(<AiOutlineFileText />)}
|
||||||
|
|
@ -110,20 +103,20 @@ export default ({ product }) => {
|
||||||
background={useColorModeValue('gray.50', 'gray.700')}
|
background={useColorModeValue('gray.50', 'gray.700')}
|
||||||
resize="vertical"
|
resize="vertical"
|
||||||
size="md"
|
size="md"
|
||||||
|
paddingTop="32px"
|
||||||
|
transition="padding ease-in-out 150ms"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{state.description.length === 0 && (
|
|
||||||
<FormLabel background="green.400" borderTopLeftRadius="8px" px={2} py={1}>
|
<FormLabel background="green.400" borderTopLeftRadius="8px" px={2} py={1}>
|
||||||
<IconTextDuo icon={(<BsMarkdown />)} text={i18n.labels.desc} />
|
<IconTextDuo icon={(<BsMarkdown />)} text={i18n.labels.desc} />
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
)}
|
|
||||||
|
|
||||||
<Text fontSize=".75rem" color="red.500">{!state.description.length ? i18n.labels.required : null}</Text>
|
<Text fontSize=".75rem" color="red.500">{!state.description.length ? i18n.labels.required : null}</Text>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
<FormControl
|
<FormControl
|
||||||
onSubmit={save}
|
onSubmit={() => {}}
|
||||||
onKeyPress={(e) => e.key === 'Enter' && save()}
|
onKeyPress={() => {}}
|
||||||
isRequired
|
isRequired
|
||||||
padding=".5rem"
|
padding=".5rem"
|
||||||
borderRadius="8px"
|
borderRadius="8px"
|
||||||
|
|
@ -148,8 +141,8 @@ export default ({ product }) => {
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
<FormControl
|
<FormControl
|
||||||
onSubmit={save}
|
onSubmit={() => {}}
|
||||||
onKeyPress={(e) => e.key === 'Enter' && save()}
|
onKeyPress={() => {}}
|
||||||
isRequired
|
isRequired
|
||||||
padding=".5rem"
|
padding=".5rem"
|
||||||
borderRadius="8px"
|
borderRadius="8px"
|
||||||
|
|
@ -170,8 +163,8 @@ export default ({ product }) => {
|
||||||
<Text fontSize=".75rem" color="red.500">{!state.price ? i18n.labels.required : null}</Text>
|
<Text fontSize=".75rem" color="red.500">{!state.price ? i18n.labels.required : null}</Text>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormControl
|
<FormControl
|
||||||
onSubmit={save}
|
onSubmit={() => {}}
|
||||||
onKeyPress={(e) => e.key === 'Enter' && save()}
|
onKeyPress={() => {}}
|
||||||
isRequired
|
isRequired
|
||||||
padding=".5rem"
|
padding=".5rem"
|
||||||
borderRadius="8px"
|
borderRadius="8px"
|
||||||
|
|
@ -217,7 +210,7 @@ export default ({ product }) => {
|
||||||
colorScheme="green"
|
colorScheme="green"
|
||||||
isLoading={loading}
|
isLoading={loading}
|
||||||
type="submit"
|
type="submit"
|
||||||
onClick={save}
|
onClick={() => save().then((x) => { if (x) closeModal(); })}
|
||||||
>
|
>
|
||||||
{i18n.labels.saveChanges}
|
{i18n.labels.saveChanges}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,14 @@ import IconTextDuo from '../../../../global/components/IconTextDuo';
|
||||||
import { Manage as i18n } from '../../../../global/i18n';
|
import { Manage as i18n } from '../../../../global/i18n';
|
||||||
import store from '../../../../redux/store';
|
import store from '../../../../redux/store';
|
||||||
import FileUpload from '../FileUpload';
|
import FileUpload from '../FileUpload';
|
||||||
import { uploadImage } from '../../../../global/api';
|
import { getAuthHeaders, uploadImage } from '../../../../global/api';
|
||||||
|
|
||||||
const InputGroupStyle = {
|
const InputGroupStyle = {
|
||||||
marginTop: '1rem',
|
marginTop: '1rem',
|
||||||
marginBottom: '1rem',
|
marginBottom: '1rem',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default () => {
|
export default ({ closeModal }) => {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
name: '',
|
name: '',
|
||||||
|
|
@ -33,34 +33,29 @@ export default () => {
|
||||||
if (!state.name.length || !state.quantity || !state.price || !state.description) {
|
if (!state.name.length || !state.quantity || !state.price || !state.description) {
|
||||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Missing Info', content: 'Not all required fields have been filled. Please provide this info to proceed.' } });
|
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);
|
setLoading(false);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Step 1: Upload image files
|
|
||||||
const imageUrls = await Promise.all(state.images.map(uploadImage));
|
const imageUrls = await Promise.all(state.images.map(uploadImage));
|
||||||
// Step 2: Upload the rest
|
|
||||||
const resp = await fetch('/api/v1/products', {
|
const resp = await fetch('/api/v1/products', {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: getAuthHeaders(),
|
||||||
authorization: `Bearer ${window.localStorage.getItem('auth-token')}`,
|
body: JSON.stringify({ ...state, images: imageUrls }),
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
...state,
|
|
||||||
images: imageUrls.length ? imageUrls : ['https://dv2ls.com/f/PpMcVb8gN'],
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
if (resp.ok) {
|
if (resp.ok) {
|
||||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Added New Product!', content: 'Your New Product has Been Saved and Will Be Reflected on the Management Page' } });
|
store.dispatch({ type: 'SET_ALERT', data: { header: 'Added New Product!', content: 'Your New Product has Been Saved and Will Be Reflected on the Management Page' } });
|
||||||
} else {
|
setLoading(false);
|
||||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Failed to Add Product', content: JSON.stringify(data) } });
|
return true;
|
||||||
}
|
}
|
||||||
|
store.dispatch({ type: 'SET_ALERT', data: { header: 'Failed to Add Product', content: JSON.stringify(data) } });
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Failed to Add Product', content: ex } });
|
store.dispatch({ type: 'SET_ALERT', data: { header: 'Failed to Add Product', content: ex } });
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -80,9 +75,9 @@ export default () => {
|
||||||
<InlineLabelInput
|
<InlineLabelInput
|
||||||
required
|
required
|
||||||
type="text"
|
type="text"
|
||||||
propSubmitEvt={save}
|
propSubmitEvt={() => {}}
|
||||||
|
propKeyPressEvt={() => {}}
|
||||||
propChangeEvt={(e) => setState({ ...state, name: e.target.value })}
|
propChangeEvt={(e) => setState({ ...state, name: e.target.value })}
|
||||||
propKeyPressEvt={(e) => e.key === 'Enter' && save()}
|
|
||||||
value={state.name}
|
value={state.name}
|
||||||
labelText={i18n.labels.name}
|
labelText={i18n.labels.name}
|
||||||
labelIcon={(<AiOutlineFileText />)}
|
labelIcon={(<AiOutlineFileText />)}
|
||||||
|
|
@ -105,20 +100,20 @@ export default () => {
|
||||||
background={useColorModeValue('gray.50', 'gray.700')}
|
background={useColorModeValue('gray.50', 'gray.700')}
|
||||||
resize="vertical"
|
resize="vertical"
|
||||||
size="md"
|
size="md"
|
||||||
|
paddingTop="32px"
|
||||||
|
transition="padding ease-in-out 150ms"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{state.description.length === 0 && (
|
|
||||||
<FormLabel background="green.400" borderTopLeftRadius="8px" px={2} py={1}>
|
<FormLabel background="green.400" borderTopLeftRadius="8px" px={2} py={1}>
|
||||||
<IconTextDuo icon={(<BsMarkdown />)} text={i18n.labels.desc} />
|
<IconTextDuo icon={(<BsMarkdown />)} text={i18n.labels.desc} />
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
)}
|
|
||||||
|
|
||||||
<Text fontSize=".75rem" color="red.500">{!state.description.length ? i18n.labels.required : null}</Text>
|
<Text fontSize=".75rem" color="red.500">{!state.description.length ? i18n.labels.required : null}</Text>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
<FormControl
|
<FormControl
|
||||||
onSubmit={save}
|
onSubmit={() => {}}
|
||||||
onKeyPress={(e) => e.key === 'Enter' && save()}
|
onKeyPress={() => {}}
|
||||||
isRequired
|
isRequired
|
||||||
padding=".5rem"
|
padding=".5rem"
|
||||||
borderRadius="8px"
|
borderRadius="8px"
|
||||||
|
|
@ -142,8 +137,8 @@ export default () => {
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
<FormControl
|
<FormControl
|
||||||
onSubmit={save}
|
onSubmit={() => {}}
|
||||||
onKeyPress={(e) => e.key === 'Enter' && save()}
|
onKeyPress={() => {}}
|
||||||
isRequired
|
isRequired
|
||||||
padding=".5rem"
|
padding=".5rem"
|
||||||
borderRadius="8px"
|
borderRadius="8px"
|
||||||
|
|
@ -163,8 +158,8 @@ export default () => {
|
||||||
<Text fontSize=".75rem" color="red.500">{!state.price ? i18n.labels.required : null}</Text>
|
<Text fontSize=".75rem" color="red.500">{!state.price ? i18n.labels.required : null}</Text>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormControl
|
<FormControl
|
||||||
onSubmit={save}
|
onSubmit={() => {}}
|
||||||
onKeyPress={(e) => e.key === 'Enter' && save()}
|
onKeyPress={() => {}}
|
||||||
isRequired
|
isRequired
|
||||||
padding=".5rem"
|
padding=".5rem"
|
||||||
borderRadius="8px"
|
borderRadius="8px"
|
||||||
|
|
@ -191,7 +186,7 @@ export default () => {
|
||||||
colorScheme="green"
|
colorScheme="green"
|
||||||
isLoading={loading}
|
isLoading={loading}
|
||||||
type="submit"
|
type="submit"
|
||||||
onClick={save}
|
onClick={() => save().then((x) => { if (x) closeModal(); })}
|
||||||
>
|
>
|
||||||
{i18n.labels.save}
|
{i18n.labels.save}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import {
|
||||||
Table, Thead, Tbody, Tr, Th, Td, TableContainer, Box, Button, Flex,
|
Table, Thead, Tbody, Tr, Th, Td, TableContainer, Box, Button, Flex,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { BiSearchAlt2 } from 'react-icons/bi';
|
import { BiSearchAlt2 } from 'react-icons/bi';
|
||||||
import { Manage as i18n, General } from '../../global/i18n';
|
import { Manage as i18n } from '../../global/i18n';
|
||||||
import Loading from '../../global/components/Loading';
|
import Loading from '../../global/components/Loading';
|
||||||
import store from '../../redux/store';
|
import store from '../../redux/store';
|
||||||
import InlineLabelInput from '../../global/components/FormControl/InlineLabelInput';
|
import InlineLabelInput from '../../global/components/FormControl/InlineLabelInput';
|
||||||
|
|
@ -72,10 +72,8 @@ export default () => {
|
||||||
<Thead>
|
<Thead>
|
||||||
<Tr>
|
<Tr>
|
||||||
<Th>{i18n.labels.name}</Th>
|
<Th>{i18n.labels.name}</Th>
|
||||||
<Th>{i18n.labels.desc}</Th>
|
|
||||||
<Th>{i18n.labels.price}</Th>
|
<Th>{i18n.labels.price}</Th>
|
||||||
<Th>{i18n.labels.qty}</Th>
|
<Th>{i18n.labels.qty}</Th>
|
||||||
<Th>{i18n.labels.hidden}</Th>
|
|
||||||
<Th>{i18n.labels.rating}</Th>
|
<Th>{i18n.labels.rating}</Th>
|
||||||
</Tr>
|
</Tr>
|
||||||
</Thead>
|
</Thead>
|
||||||
|
|
@ -88,16 +86,8 @@ export default () => {
|
||||||
key={x.name}
|
key={x.name}
|
||||||
>
|
>
|
||||||
<Td>{x.name}</Td>
|
<Td>{x.name}</Td>
|
||||||
<Td>
|
<Td>{`$${x.price}`}</Td>
|
||||||
{x.description?.substring(0, 24)}
|
|
||||||
...
|
|
||||||
</Td>
|
|
||||||
<Td>
|
|
||||||
$
|
|
||||||
{x.price}
|
|
||||||
</Td>
|
|
||||||
<Td>{x.quantity}</Td>
|
<Td>{x.quantity}</Td>
|
||||||
<Td>{x.hidden ? General.yes : General.no}</Td>
|
|
||||||
<Td>{x.overallRating || 'No Reviews'}</Td>
|
<Td>{x.overallRating || 'No Reviews'}</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
))}
|
))}
|
||||||
|
|
@ -108,25 +98,27 @@ export default () => {
|
||||||
<DynamicModal
|
<DynamicModal
|
||||||
open={newModal}
|
open={newModal}
|
||||||
header={i18n.create.title}
|
header={i18n.create.title}
|
||||||
superOnClose={() => {
|
superOnClose={() => setNewModal(false)}
|
||||||
setNewModal(false);
|
|
||||||
init(setProducts, setLoaded, setAllProducts);
|
|
||||||
}}
|
|
||||||
size="3xl"
|
size="3xl"
|
||||||
>
|
>
|
||||||
<New />
|
<New closeModal={() => {
|
||||||
|
init(setProducts, setLoaded, setAllProducts).then(() => setNewModal(false));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</DynamicModal>
|
</DynamicModal>
|
||||||
|
|
||||||
<DynamicModal
|
<DynamicModal
|
||||||
open={!!editItem}
|
open={!!editItem}
|
||||||
header={i18n.edit.title(editItem?.name)}
|
header={i18n.edit.title(editItem?.name)}
|
||||||
superOnClose={() => {
|
superOnClose={() => setEditItem(null)}
|
||||||
setEditItem(null);
|
|
||||||
init(setProducts, setLoaded, setAllProducts);
|
|
||||||
}}
|
|
||||||
size="3xl"
|
size="3xl"
|
||||||
>
|
>
|
||||||
<Edit product={editItem} />
|
<Edit
|
||||||
|
product={editItem}
|
||||||
|
closeModal={() => {
|
||||||
|
init(setProducts, setLoaded, setAllProducts).then(() => setEditItem(null));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</DynamicModal>
|
</DynamicModal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import Carousel from './components/Carousel';
|
||||||
export default () => {
|
export default () => {
|
||||||
const [product, setProduct] = useState(null);
|
const [product, setProduct] = useState(null);
|
||||||
const [loaded, setLoaded] = useState(false);
|
const [loaded, setLoaded] = useState(false);
|
||||||
|
const [errored, setErrored] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (loaded) return () => {};
|
if (loaded) return () => {};
|
||||||
|
|
@ -20,7 +21,7 @@ export default () => {
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
if (!params.has('productId')) {
|
if (!params.has('productId')) {
|
||||||
store.dispatch({ type: 'SET_ALERT', data: { header: i18n.downloadFailedAlert.header, content: 'URL is invalid as it\'s missing the Product ID' } });
|
store.dispatch({ type: 'SET_ALERT', data: { header: i18n.downloadFailedAlert.header, content: 'URL is invalid as it\'s missing the Product ID' } });
|
||||||
setLoadedPt(true);
|
setErrored(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,17 +40,27 @@ export default () => {
|
||||||
return () => {};
|
return () => {};
|
||||||
}, [setProduct, loaded, setLoaded]);
|
}, [setProduct, loaded, setLoaded]);
|
||||||
|
|
||||||
if (!loaded) {
|
if (errored) {
|
||||||
|
return <div />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!errored && !loaded) {
|
||||||
return (<Loading />);
|
return (<Loading />);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ maxWidth: '768px', margin: 'auto' }}>
|
<div style={{ maxWidth: '768px', margin: 'auto' }}>
|
||||||
<Heading textAlign="center" mb={4}>{product.name}</Heading>
|
<Heading textAlign="center" mb={4}>{product.name}</Heading>
|
||||||
{product.images && product.images.length && (
|
{(product.images && product.images.length) ? (
|
||||||
<Carousel photos={product.images} />
|
<Carousel photos={product.images} />
|
||||||
|
) : (
|
||||||
|
<Heading textAlign="center" size="md">
|
||||||
|
(No Photos Available)
|
||||||
|
</Heading>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<hr style={{ margin: '2rem auto' }} />
|
||||||
|
|
||||||
<Box my={2} mx="auto" display="block" textAlign="center">
|
<Box my={2} mx="auto" display="block" textAlign="center">
|
||||||
<Heading my={2} size="md">
|
<Heading my={2} size="md">
|
||||||
{/* TODO: currency support */}
|
{/* TODO: currency support */}
|
||||||
|
|
@ -62,7 +73,7 @@ export default () => {
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<hr />
|
<hr style={{ margin: '2rem auto' }} />
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Heading my={3}>Description</Heading>
|
<Heading my={3}>Description</Heading>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue