Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions src/actions/form-template-item-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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());
Expand All @@ -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());
});
Expand All @@ -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());
});
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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) => {
Expand All @@ -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 }) => {
Expand All @@ -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"
)
})
);
})
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
import { DECIMAL_DIGITS, DEFAULT_CURRENT_PAGE } from "../../../utils/constants";

const AddFormTemplateItemDialog = ({
open,
onClose,
onAddItems,
clearAllSelectedInventoryItems,
Expand Down Expand Up @@ -176,7 +175,7 @@ const AddFormTemplateItemDialog = ({
];

return (
<Dialog open={open} onClose={handleClose} maxWidth="md" fullWidth>
<Dialog open onClose={handleClose} maxWidth="md" fullWidth>
<DialogTitle sx={{ display: "flex", justifyContent: "space-between" }}>
<Typography fontSize="1.5rem">
{T.translate("inventory_items_list_modal.select_items")}
Expand Down Expand Up @@ -271,7 +270,6 @@ const AddFormTemplateItemDialog = ({
};

AddFormTemplateItemDialog.propTypes = {
open: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
onAddItems: PropTypes.func.isRequired
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
Comment on lines 116 to 125
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Handle prefetch failures before opening modals.

If either fetch rejects, the UI silently does nothing. Add a rejection path to surface the failure (or at least log it) so users aren’t left without feedback.

🔧 Suggested minimal error handling
 const handleRowEdit = (row) => {
-  getFormTemplateItem(formTemplateId, row.id).then(() =>
-    setShowInventoryItemModal(true)
-  );
+  getFormTemplateItem(formTemplateId, row.id)
+    .then(() => setShowInventoryItemModal(true))
+    .catch((error) => {
+      console.error(error);
+    });
 };

 const handleNewInventoryItem = () => {
-  getInventoryItems().then(() => setShowAddInventoryItemsModal(true));
+  getInventoryItems()
+    .then(() => setShowAddInventoryItemsModal(true))
+    .catch((error) => {
+      console.error(error);
+    });
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleRowEdit = (row) => {
if (row) getFormTemplateItem(formTemplateId, row.id);
setShowInventoryItemModal(true);
getFormTemplateItem(formTemplateId, row.id).then(() =>
setShowInventoryItemModal(true)
);
};
const handleNewInventoryItem = () => {
getInventoryItems();
setShowAddInventoryItemsModal(true);
getInventoryItems().then(() => setShowAddInventoryItemsModal(true));
};
const handleRowEdit = (row) => {
getFormTemplateItem(formTemplateId, row.id)
.then(() => setShowInventoryItemModal(true))
.catch((error) => {
console.error(error);
});
};
const handleNewInventoryItem = () => {
getInventoryItems()
.then(() => setShowAddInventoryItemsModal(true))
.catch((error) => {
console.error(error);
});
};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/sponsors-global/form-templates/form-template-item-list-page.js`
around lines 116 - 124, The handlers handleRowEdit and handleNewInventoryItem
currently open modals only on successful promises and swallow rejections; update
their promise chains for getFormTemplateItem(formTemplateId, row.id) and
getInventoryItems() to add .catch handlers that log the error (using
console.error or the app logger) and surface feedback to the user (e.g., set an
error toast/state) before returning, while keeping the existing .then calls that
call setShowInventoryItemModal(true) and setShowAddInventoryItemsModal(true) on
success.


const handleAddSelectedItems = (items) => {
Expand Down Expand Up @@ -300,21 +301,23 @@ const FormTemplateItemListPage = ({
/>
</div>
)}
<AddFormTemplateItemDialog
open={showAddInventoryItemsModal}
onClose={() => setShowAddInventoryItemsModal(false)}
onAddItems={handleAddSelectedItems}
/>
<SponsorItemDialog
entity={currentFormTemplateItem}
errors={currentFormTemplateItemErrors}
open={showInventoryItemModal}
onSave={handleFormTemplateSave}
onClose={() => setShowInventoryItemModal(false)}
onMetaFieldTypeDeleted={deleteItemMetaFieldType}
onMetaFieldTypeValueDeleted={deleteItemMetaFieldTypeValue}
onImageDeleted={deleteItemImage}
/>
{showAddInventoryItemsModal && (
<AddFormTemplateItemDialog
onClose={() => setShowAddInventoryItemsModal(false)}
onAddItems={handleAddSelectedItems}
/>
)}
{showInventoryItemModal && (
<SponsorItemDialog
entity={currentFormTemplateItem}
errors={currentFormTemplateItemErrors}
onSave={handleFormTemplateSave}
onClose={() => setShowInventoryItemModal(false)}
onMetaFieldTypeDeleted={deleteItemMetaFieldType}
onMetaFieldTypeValueDeleted={deleteItemMetaFieldTypeValue}
onImageDeleted={deleteItemImage}
/>
)}
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -120,7 +119,7 @@ const SponsorItemDialog = ({

return (
<Dialog
open={open}
open
onClose={handleClose}
maxWidth="md"
fullWidth
Expand Down Expand Up @@ -313,7 +312,6 @@ const SponsorItemDialog = ({
};

SponsorItemDialog.propTypes = {
open: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
onSave: PropTypes.func.isRequired,
entity: PropTypes.object
Expand Down