import React, { useState } from 'react'; 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'; import MDButton from 'components/Button'; import { useFormik } from 'formik'; import schema from 'services/ValidationServices'; import MDInput from 'components/MDInput'; 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 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 location = useLocation(); const [open, setOpen] = useState(false); const ITEM_HEIGHT = 48; const ITEM_PADDING_TOP = 8; const MenuProps = { PaperProps: { style: { maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP, width: 250 } } }; const dispatch = useDispatch(); const formik = useFormik({ initialValues: { warehousename: location.state.name, address: location.state.address, inventorytype: [], attributes: '', images: [] }, validationSchema: schema.warehouseForm, onSubmit: (values, onSubmitProps) => { dispatch( WarehouseActions.editWarehouseAction({ loader: 'loading-request', slug: `/warehouse/${location.state.id}`, method: 'patch', data: { name: values.warehousename, address: values.address, specs: '', company_id: '' } }) ); onSubmitProps.resetForm(); setOpen(true); } }); const handleClose = (event, reason) => { if (reason === 'clickaway') { return; } setOpen(false); }; return ( <>
Form to Input Warehouse name Address Types of inventories hosted Other attributes { formik.setFieldValue('images', images); }} /> {/* ---edit-- */} SAVE { navigate(`/setup/warehouse/warehouse-details/${location.state.id}`); }} > SHOW DETAILS
); } export default EditWarehouseDetails;