Added: delete inventory

This commit is contained in:
Llewellyn Dsouza
2022-03-04 18:28:41 +05:30
parent 8cccf1f034
commit a22c3fcf42
4 changed files with 121 additions and 7 deletions

View File

@@ -10,7 +10,13 @@ import {
Radio,
RadioGroup,
useRadioGroup,
Select
Select,
Dialog,
DialogTitle,
DialogContent,
DialogContentText,
DialogActions,
Button
} from '@mui/material';
import { styled } from '@mui/material/styles';
import MDInput from 'components/MDInput';
@@ -114,7 +120,7 @@ function InventoryScreen() {
};
const currentInventoryData = useSelector(InventorySelectors.getInventoryDetailById(inventoryId));
LOGGER.log({ currentInventoryData });
// LOGGER.log({ currentInventoryData });
// const [inventoryAllData, setInventoryAllData] = useState([]);
// const initialInventoryName='';
@@ -185,7 +191,14 @@ function InventoryScreen() {
}
});
LOGGER.log('Form values', formik.values);
const [deleteAlertOpen, setDeleteAlertOpen] = React.useState(null);
const handleDeleteAlertClose = () => {
setDeleteAlertOpen(false);
};
const handleDeleteAlertOpen = () => {
setDeleteAlertOpen(true);
};
return (
<DashboardLayout>
<DashboardNavbar />
@@ -294,17 +307,71 @@ function InventoryScreen() {
</div>
</MDBox>
</Grid>
<Grid item xs={12} sm={6} md={6}>
<Grid item sx={{ textAlign: 'right' }} xs={12} sm={6} md={6}>
<MDButton
size="large"
color="error"
variant="outlined"
sx={{
marginTop: '20px'
}}
onClick={handleDeleteAlertOpen}
>
Delete Inventory
</MDButton>
<Dialog
open={deleteAlertOpen}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
onClose={handleDeleteAlertClose}
>
<DialogTitle id="alert-dialog-title">Confirm Inventory Delete</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
Are you sure you want to delete this inventory?
</DialogContentText>
</DialogContent>
<DialogActions>
<Button autoFocus onClick={handleDeleteAlertClose}>
No
</Button>
<Button
onClick={() => {
dispatch(
InventoryActions.deleteInventoryAction({
loader: 'loading-request',
slug: '/inventory/' + inventoryId,
method: 'delete',
inventoryId,
navigateTo
})
);
handleDeleteAlertClose();
}}
>
Yes
</Button>
</DialogActions>
</Dialog>
<Box
sx={{
width: 400,
height: 300,
padding: '20px',
border: '1px solid #D2D6DA'
marginTop: '80px',
textAlign: 'left'
}}
>
<MDBox sx={{ my: 4 }}>
<MDTypography variant="h5">Inventory Icon</MDTypography>
<MDTypography sx={customStyles.textSize}>
Choose the icon to represent the inventory
</MDTypography>
</MDBox>
<RadioGroup
row
sx={{
marginTop: '15px'
}}
aria-labelledby="demo-error-radios"
name="icon_slug"
value={formik.values.icon_slug}

View File

@@ -13,6 +13,8 @@ const { Types, Creators } = createActions({
addInventoryFailure: ['error'],
updateInventoryAction: ['payload'],
updateInventorySuccess: ['data'],
deleteInventoryAction: ['payload'],
deleteInventorySuccess: ['data'],
updateInventoryFailure: ['error'],
getInventoryTypesAction: ['payload'],
getInventoryTypesSuccess: ['data'],
@@ -98,6 +100,21 @@ export const onUpdateInventorySuccess = (state, { data }) =>
]
});
export const onDeleteInventoryAction = (state, { payload }) =>
state.merge({
fetching: _.uniq([state.fetching, payload?.loader]),
error: getErrorValue(state?.error, payload?.loader)
});
export const onDeleteInventorySuccess = (state, { data }) =>
state.merge({
fetching: getFetchingValue(state.fetching, data?.loader),
error: getErrorValue(state?.error, data?.loader),
getInventoryDetail: data.deletedInventoryID
? [...state.getInventoryDetail.filter((x) => x._id !== data.deletedInventoryID)]
: state.getInventoryDetail
});
export const onUpdateInventoryFailure = (state, { error }) =>
state.merge({
fetching: _.without(state.fetching, error?.loader),
@@ -133,6 +150,8 @@ export const inventoryReducer = createReducer(INITIAL_STATE, {
[Types.ADD_INVENTORY_FAILURE]: onAddInventoryFailure,
[Types.UPDATE_INVENTORY_ACTION]: onUpdateInventoryAction,
[Types.UPDATE_INVENTORY_SUCCESS]: onUpdateInventorySuccess,
[Types.DELETE_INVENTORY_ACTION]: onDeleteInventoryAction,
[Types.DELETE_INVENTORY_SUCCESS]: onDeleteInventorySuccess,
[Types.UPDATE_INVENTORY_FAILURE]: onUpdateInventoryFailure,
[Types.GET_INVENTORY_TYPES_ACTION]: onGetInventoryTypesAction,
[Types.GET_INVENTORY_TYPES_SUCCESS]: onGetInventoryTypesSuccess,

View File

@@ -117,9 +117,37 @@ export function* onRequestUpdateInventoryData({ payload }) {
);
}
}
export function* onRequestDeleteInventoryData({ payload }) {
const response = yield call(ApiServices[payload?.method], AuthorizedAPI, payload?.slug);
if (response?.status === 200) {
toast.success('Deleted inventory successfully', {
theme: 'colored'
});
payload.navigateTo();
yield put(
InventoryActions.deleteInventorySuccess({
loader: payload?.loader,
deletedInventoryID: payload?.inventoryId
})
);
} else {
toast.error('Failed to delete inventory', {
theme: 'colored'
});
yield put(
InventoryActions.updateInventoryFailure({
loader: payload?.loader,
error: response?.data
})
);
}
}
export default [
takeEvery(InventoryTypes.GET_INVENTORY_ACTION, onRequestGetInventoryData),
takeEvery(InventoryTypes.ADD_INVENTORY_ACTION, onRequestAddInventoryData),
takeEvery(InventoryTypes.DELETE_INVENTORY_ACTION, onRequestDeleteInventoryData),
takeEvery(InventoryTypes.UPDATE_INVENTORY_ACTION, onRequestUpdateInventoryData),
takeEvery(InventoryTypes.GET_INVENTORY_TYPES_ACTION, onRequestGetInventoryTypesData)
];

View File

@@ -166,7 +166,7 @@ export function* onDeleteRequestItem({ payload }) {
payload?.slug + payload?.itemId
);
if (response?.status === 200) {
toast.success(`Successfully deleted item`, {
toast.success('Successfully deleted item', {
theme: 'colored'
});
payload.refreshDispatch();