diff --git a/src/actions/form-template-item-actions.js b/src/actions/form-template-item-actions.js index a7578fd2b..419f96fa2 100644 --- a/src/actions/form-template-item-actions.js +++ b/src/actions/form-template-item-actions.js @@ -20,13 +20,10 @@ import { createAction, stopLoading, startLoading, - showMessage, - showSuccessMessage, - authErrorHandler, escapeFilterValue } from "openstack-uicore-foundation/lib/utils/actions"; import { amountToCents } from "openstack-uicore-foundation/lib/utils/money"; -import history from "../history"; +import { snackbarErrorHandler, snackbarSuccessHandler } from "./base-actions"; import { getAccessTokenSafely } from "../utils/methods"; import { DEFAULT_CURRENT_PAGE, @@ -117,7 +114,7 @@ export const getFormTemplateItems = createAction(REQUEST_FORM_TEMPLATE_ITEMS), createAction(RECEIVE_FORM_TEMPLATE_ITEMS), `${window.INVENTORY_API_BASE_URL}/api/v1/form-templates/${formTemplateId}/items`, - authErrorHandler, + snackbarErrorHandler, { order, orderDir, page, term, hideArchived } )(params)(dispatch).then(() => { dispatch(stopLoading()); @@ -139,7 +136,7 @@ export const getFormTemplateItem = null, createAction(RECEIVE_FORM_TEMPLATE_ITEM), `${window.INVENTORY_API_BASE_URL}/api/v1/form-templates/${formTemplateId}/items/${formTemplateItemId}`, - authErrorHandler + snackbarErrorHandler )(params)(dispatch).then(() => { dispatch(stopLoading()); }); @@ -163,7 +160,7 @@ export const deleteFormTemplateItem = }), `${window.INVENTORY_API_BASE_URL}/api/v1/form-templates/${formTemplateId}/items/${formTemplateItemId}`, null, - authErrorHandler + snackbarErrorHandler )(params)(dispatch).then(() => { dispatch(stopLoading()); }); @@ -209,7 +206,7 @@ export const saveFormTemplateItem = createAction(FORM_TEMPLATE_ITEM_UPDATED), `${window.INVENTORY_API_BASE_URL}/api/v1/form-templates/${formTemplateId}/items/${entity.id}`, normalizedEntity, - authErrorHandler, + snackbarErrorHandler, entity )(params)(dispatch) .then(() => { @@ -230,11 +227,12 @@ export const saveFormTemplateItem = return Promise.all(promises) .then(() => { dispatch( - showSuccessMessage( - T.translate( + snackbarSuccessHandler({ + title: T.translate("general.success"), + html: T.translate( "edit_form_template_item.form_template_item_saved" ) - ) + }) ); }) .catch((err) => { @@ -249,18 +247,12 @@ export const saveFormTemplateItem = }); } - const success_message = { - title: T.translate("general.done"), - html: T.translate("edit_form_template_item.form_template_item_created"), - type: "success" - }; - return postRequest( createAction(ADD_FORM_TEMPLATE_ITEM), createAction(FORM_TEMPLATE_ITEM_ADDED), `${window.INVENTORY_API_BASE_URL}/api/v1/form-templates/${formTemplateId}/items`, normalizedEntity, - authErrorHandler, + snackbarErrorHandler, entity )(params)(dispatch) .then(({ response }) => { @@ -282,8 +274,11 @@ export const saveFormTemplateItem = return Promise.all(promises) .then(() => { dispatch( - showMessage(success_message, () => { - history.push("/app/form-templates"); + snackbarSuccessHandler({ + title: T.translate("general.done"), + html: T.translate( + "edit_form_template_item.form_template_item_created" + ) }) ); }) @@ -318,7 +313,7 @@ export const cloneFromInventoryItem = createAction(FORM_TEMPLATE_ITEM_ADDED), `${window.INVENTORY_API_BASE_URL}/api/v1/form-templates/${formTemplateId}/items/clone`, payload, - authErrorHandler, + snackbarErrorHandler, payload )(params)(dispatch).then(() => { dispatch(stopLoading()); diff --git a/src/pages/sponsors-global/form-templates/add-form-template-item-popup.js b/src/pages/sponsors-global/form-templates/add-form-template-item-popup.js index 8fc0ad02a..12ae8f10c 100644 --- a/src/pages/sponsors-global/form-templates/add-form-template-item-popup.js +++ b/src/pages/sponsors-global/form-templates/add-form-template-item-popup.js @@ -33,7 +33,6 @@ import { import { DECIMAL_DIGITS, DEFAULT_CURRENT_PAGE } from "../../../utils/constants"; const AddFormTemplateItemDialog = ({ - open, onClose, onAddItems, clearAllSelectedInventoryItems, @@ -176,7 +175,7 @@ const AddFormTemplateItemDialog = ({ ]; return ( - + {T.translate("inventory_items_list_modal.select_items")} @@ -271,7 +270,6 @@ const AddFormTemplateItemDialog = ({ }; AddFormTemplateItemDialog.propTypes = { - open: PropTypes.bool.isRequired, onClose: PropTypes.func.isRequired, onAddItems: PropTypes.func.isRequired }; diff --git a/src/pages/sponsors-global/form-templates/form-template-item-list-page.js b/src/pages/sponsors-global/form-templates/form-template-item-list-page.js index 16b6acf04..7ad31be74 100644 --- a/src/pages/sponsors-global/form-templates/form-template-item-list-page.js +++ b/src/pages/sponsors-global/form-templates/form-template-item-list-page.js @@ -114,13 +114,14 @@ const FormTemplateItemListPage = ({ }; const handleRowEdit = (row) => { - if (row) getFormTemplateItem(formTemplateId, row.id); - setShowInventoryItemModal(true); + if (!row) return; + getFormTemplateItem(formTemplateId, row.id).then(() => + setShowInventoryItemModal(true) + ); }; const handleNewInventoryItem = () => { - getInventoryItems(); - setShowAddInventoryItemsModal(true); + getInventoryItems().then(() => setShowAddInventoryItemsModal(true)); }; const handleAddSelectedItems = (items) => { @@ -300,21 +301,23 @@ const FormTemplateItemListPage = ({ /> )} - setShowAddInventoryItemsModal(false)} - onAddItems={handleAddSelectedItems} - /> - setShowInventoryItemModal(false)} - onMetaFieldTypeDeleted={deleteItemMetaFieldType} - onMetaFieldTypeValueDeleted={deleteItemMetaFieldTypeValue} - onImageDeleted={deleteItemImage} - /> + {showAddInventoryItemsModal && ( + setShowAddInventoryItemsModal(false)} + onAddItems={handleAddSelectedItems} + /> + )} + {showInventoryItemModal && ( + setShowInventoryItemModal(false)} + onMetaFieldTypeDeleted={deleteItemMetaFieldType} + onMetaFieldTypeValueDeleted={deleteItemMetaFieldTypeValue} + onImageDeleted={deleteItemImage} + /> + )} ); }; diff --git a/src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js b/src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js index 3fd4a141b..de3a5a8b7 100644 --- a/src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js +++ b/src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js @@ -39,7 +39,6 @@ import AdditionalInputList from "../../../components/mui/formik-inputs/additiona import MuiFormikQuantityField from "../../../components/mui/formik-inputs/mui-formik-quantity-field"; const SponsorItemDialog = ({ - open, onClose, onSave, onImageDeleted, @@ -120,7 +119,7 @@ const SponsorItemDialog = ({ return (