From a22c3fcf42bcedf53e2b94db688fd0ecd58e709d Mon Sep 17 00:00:00 2001 From: Llewellyn Dsouza Date: Fri, 4 Mar 2022 18:28:41 +0530 Subject: [PATCH] Added: delete inventory --- src/pages/inventory/index.js | 79 +++++++++++++++++++++++++++++++++--- src/redux/InventoryRedux.js | 19 +++++++++ src/sagas/Inventory.js | 28 +++++++++++++ src/sagas/Item.js | 2 +- 4 files changed, 121 insertions(+), 7 deletions(-) diff --git a/src/pages/inventory/index.js b/src/pages/inventory/index.js index 9ede374..1d12b7b 100644 --- a/src/pages/inventory/index.js +++ b/src/pages/inventory/index.js @@ -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 ( @@ -294,17 +307,71 @@ function InventoryScreen() { - + + + Delete Inventory + + + Confirm Inventory Delete + + + Are you sure you want to delete this inventory? + + + + + + + + + Inventory Icon + + Choose the icon to represent the inventory + + ] }); +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, diff --git a/src/sagas/Inventory.js b/src/sagas/Inventory.js index 1f369b6..0bfd29d 100644 --- a/src/sagas/Inventory.js +++ b/src/sagas/Inventory.js @@ -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) ]; diff --git a/src/sagas/Item.js b/src/sagas/Item.js index bdbd82b..19fa701 100644 --- a/src/sagas/Item.js +++ b/src/sagas/Item.js @@ -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();