/* eslint-disable indent */
import {
Box,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
Grid,
TextField
} from '@mui/material';
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
import IconButton from '@mui/material/IconButton';
import MDButton from 'components/Button';
import { useDispatch, useSelector } from 'react-redux';
import { WidgetSelectors } from 'redux/WidgetRedux';
import WidgetActions from 'redux/WidgetRedux';
import { API } from 'constant';
import { useFormik } from 'formik';
import LOGGER from 'services/Logger';
function MaterialForm({ formType, setFormOpen, selected, inventoryId }) {
const dispatch = useDispatch();
const formik = useFormik({
initialValues:
formType === 'family'
? { name: '', inventoryId }
: formType === 'subfamily'
? { name: '', inventoryId, parentId: selected._id || '' }
: { name: formType.name, inventoryId, parentId: formType.parent?._id || undefined },
onSubmit: (values) => {
LOGGER.log('Form values and field info', values);
['family', 'subfamily'].includes(formType)
? dispatch(
WidgetActions.editWidgetRequest({
loader: 'location-request',
slug: API.ADD_WIDGET_FAMILY,
method: 'post',
data: values,
type: 'add'
})
)
: dispatch(
WidgetActions.editWidgetRequest({
loader: 'location-request',
slug: `${API.EDIT_WIDGET_FAMILY}${formType._id}`,
method: 'patch',
data: values,
type: 'edit'
})
);
setFormOpen(false);
}
});
return (
);
}
MaterialForm.propTypes = {
formType: PropTypes.any,
setFormOpen: PropTypes.any,
selected: PropTypes.any,
inventoryId: PropTypes.any
};
function WidgetNestedDataTable({
data,
selected,
setSelected,
setFormOpen,
setFormType,
inventoryId
}) {
const [open, setOpen] = React.useState(false);
const dispatch = useDispatch();
const widgetChildren = useSelector(WidgetSelectors.getWidgetsByParentId(data._id));
return (
<>
{JSON.stringify(selected, null, 4)} */}
{formOpen && (