From 430049df9d540dbe9be458a63e4150dd4db02dc1 Mon Sep 17 00:00:00 2001 From: Llewellyn Dsouza Date: Sun, 27 Feb 2022 11:22:31 +0530 Subject: [PATCH] Merge Nested to Edit warehouse --- src/pages/editWarehouseDetails/index.js | 356 ++++++++++++++++++++++-- src/pages/warehouse/index.js | 2 +- src/routes/index.js | 2 +- 3 files changed, 342 insertions(+), 18 deletions(-) diff --git a/src/pages/editWarehouseDetails/index.js b/src/pages/editWarehouseDetails/index.js index 3bc732c..9eb6dfa 100644 --- a/src/pages/editWarehouseDetails/index.js +++ b/src/pages/editWarehouseDetails/index.js @@ -1,7 +1,19 @@ import React, { useState } from 'react'; -import { useDispatch } from 'react-redux'; -import { Box, Grid, MenuItem, OutlinedInput, Chip, Select } from '@mui/material'; -import { makeStyles } from '@mui/styles'; +import PropTypes from 'prop-types'; +import { useDispatch, useSelector } from 'react-redux'; +import { + Box, + Grid, + MenuItem, + OutlinedInput, + Chip, + Select, + Dialog, + DialogTitle, + DialogContent, + TextField, + DialogActions +} from '@mui/material'; import DashboardNavbar from 'components/DashboardNavbar'; import DashboardLayout from 'layouts/DashboardLayout'; import ImageUpload from 'components/ImageUpload'; @@ -13,21 +25,300 @@ import { useLocation } from 'react-router-dom'; import WarehouseActions from 'redux/WarehouseRedux'; import SnackBar from 'components/SnackBar'; import { useNavigate } from 'react-router-dom'; +import { getChildLocationType } from 'utils/nestedTableTools'; +import { getPropertiesOfLocationType } from 'utils/nestedTableTools'; +import { getInitialvaluesFromParentData } from 'utils/nestedTableTools'; +import LOGGER from 'services/Logger'; +import WarehouseLocationsActions from 'redux/WarehouseLocationsRedux'; +import { getAPIslugOfLocationType } from 'utils/nestedTableTools'; +import { toTitleCase } from 'utils/nestedTableTools'; +import { useParams } from 'react-router-dom'; +import { WarehouseLocationsSelectors } from 'redux/WarehouseLocationsRedux'; +import { API } from 'constant'; +import NestedDataTable from 'components/NestedTable'; -const useStyles = makeStyles({ - labelSize: { - fontSize: '16px', - letterSpacing: '0.01em', - color: '#000', - marginBottom: '4px' - } -}); +const bottomButtonStyling = { + width: '100%', + textTransform: 'uppercase', + borderRadius: '100px', + padding: '13px 30px' +}; + +const AddForm = ({ addFormOpen, setAddFormOpen, selected, warehouseId }) => { + const dispatch = useDispatch(); + const data = addFormOpen !== 'zone' ? selected : { location: 'warehouse', id: warehouseId }; + + const childLocationType = getChildLocationType(data.location); + const fields = getPropertiesOfLocationType(childLocationType); + + const formik = useFormik({ + initialValues: getInitialvaluesFromParentData(data), + onSubmit: (values) => { + LOGGER.log('Form values and parent info', values, data); + const formData = { ...values }; + formData[`${data.location}_id`] = data.id; + dispatch( + WarehouseLocationsActions.addLocationRequest({ + loader: 'location-request', + slug: getAPIslugOfLocationType(childLocationType), + method: 'post', + data: formData, + parent: { + id: data.id, + type: data.location + } + }) + ); + setAddFormOpen(false); + } + }); + + return ( + { + setAddFormOpen(false); + }} + > + Add new {childLocationType} details + + {/* Some more text if needed */} + {fields && + fields.map((fieldName) => ( + + ))} + {childLocationType === 'sublevel' ? ( + <> + Type:{' '} + + Positions:{' '} + + + ) : null} + + + { + setAddFormOpen(false); + }} + > + Cancel + + Save + + + ); +}; + +AddForm.propTypes = { + addFormOpen: PropTypes.any, + setAddFormOpen: PropTypes.any, + selected: PropTypes.any, + warehouseId: PropTypes.any +}; + +const WarehouseNestedDetails = () => { + const [selected, setSelected] = React.useState(null); + const [addFormOpen, setAddFormOpen] = React.useState(false); + const dispatch = useDispatch(); + + const { warehouseId } = useParams(); + LOGGER.log('warehouseID', warehouseId); + const data = useSelector(WarehouseLocationsSelectors.getChildrenOfParent(warehouseId)); + + const populateChildren = (id, type) => { + LOGGER.log('populating:', id, type); + dispatch( + WarehouseLocationsActions.locationRequest({ + loader: 'location-request', + slug: API.GET_CHILDREN_FROM_PARENT, + method: 'post', + data: { id, type } + }) + ); + }; + + React.useEffect(() => { + populateChildren(warehouseId, 'warehouse'); + }, []); + + return ( + <> + + {data && + data.map((data) => ( + + ))} + {/* Debugging */} + {/*
{JSON.stringify(selected, null, 4)}
*/} + {/* Bottom buttons */} + + { + setAddFormOpen('zone'); + }} + > + Add zone + + { + setAddFormOpen(true); + }} + > + Add area + + { + setAddFormOpen(true); + }} + > + Add row + + { + setAddFormOpen(true); + }} + > + Add bay + + { + setAddFormOpen(true); + }} + > + Add Level + + { + setAddFormOpen(true); + }} + > + Add Sublevel + + +
+ {addFormOpen && ( + + )} + + ); +}; const inventoryTypes = ['Perishable', 'Material', 'Product', 'Inventory', 'Fleet']; function EditWarehouseDetails() { const navigate = useNavigate(); - const classes = useStyles(); const location = useLocation(); const [open, setOpen] = useState(false); const ITEM_HEIGHT = 48; @@ -96,7 +387,15 @@ function EditWarehouseDetails() { - + Warehouse name - + Address - + Types of inventories hosted