diff --git a/src/actions/inventory-item-actions.js b/src/actions/inventory-item-actions.js
index 45814f39e..9473cc98c 100644
--- a/src/actions/inventory-item-actions.js
+++ b/src/actions/inventory-item-actions.js
@@ -233,23 +233,20 @@ export const saveInventoryItem = (entity) => async (dispatch) => {
promises.push(saveItemMetaFieldTypes(normalizedEntity)(dispatch));
}
- Promise.all(promises)
- .then(() => {
- dispatch(
- showSuccessMessage(
- T.translate("edit_inventory_item.inventory_item_saved")
- )
- );
- })
- .catch((err) => {
- console.error(err);
- })
- .finally(() => {
- dispatch(stopLoading());
- });
+ return Promise.all(promises).then(() => {
+ dispatch(
+ showSuccessMessage(
+ T.translate("edit_inventory_item.inventory_item_saved")
+ )
+ );
+ });
})
.catch((err) => {
console.error(err);
+ throw err;
+ })
+ .finally(() => {
+ dispatch(stopLoading());
});
}
diff --git a/src/actions/page-template-actions.js b/src/actions/page-template-actions.js
index ecf7ca78b..c03184510 100644
--- a/src/actions/page-template-actions.js
+++ b/src/actions/page-template-actions.js
@@ -174,7 +174,6 @@ export const savePageTemplate = (entity) => async (dispatch) => {
html: T.translate("page_template_list.page_crud.page_saved")
})
);
- getPageTemplates()(dispatch);
})
.catch((err) => {
console.error(err);
@@ -199,7 +198,6 @@ export const savePageTemplate = (entity) => async (dispatch) => {
html: T.translate("page_template_list.page_crud.page_created")
})
);
- getPageTemplates()(dispatch);
})
.catch((err) => {
console.error(err);
diff --git a/src/actions/sponsor-actions.js b/src/actions/sponsor-actions.js
index a955e713b..0e62ba5a2 100644
--- a/src/actions/sponsor-actions.js
+++ b/src/actions/sponsor-actions.js
@@ -1126,7 +1126,7 @@ export const saveSummitSponsorship = (entity) => async (dispatch, getState) => {
const normalizedEntity = normalizeSponsorship(entity);
if (entity.id) {
- putRequest(
+ return putRequest(
createAction(UPDATE_SUMMIT_SPONSORSHIP),
createAction(SUMMIT_SPONSORSHIP_UPDATED),
`${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/sponsorships-types/${entity.id}`,
@@ -1138,14 +1138,14 @@ export const saveSummitSponsorship = (entity) => async (dispatch, getState) => {
showSuccessMessage(T.translate("edit_sponsorship.sponsorship_saved"))
);
});
- } else {
+ }
const success_message = {
title: T.translate("general.done"),
html: T.translate("edit_sponsorship.sponsorship_created"),
type: "success"
};
- postRequest(
+ return postRequest(
createAction(UPDATE_SUMMIT_SPONSORSHIP),
createAction(SUMMIT_SPONSORSHIP_ADDED),
`${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/sponsorships-types`,
@@ -1155,7 +1155,7 @@ export const saveSummitSponsorship = (entity) => async (dispatch, getState) => {
)(params)(dispatch).then(() => {
dispatch(showMessage(success_message));
});
- }
+
};
export const uploadSponsorshipBadgeImage =
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 95e6bcd47..dda570bab 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
@@ -177,7 +177,7 @@ const FormTemplateItemListPage = ({
);
};
- const handleFormTemplateSave = (item) => {
+ const handleFormTemplateSave = (item) =>
saveFormTemplateItem(formTemplateId, item).then(() =>
getFormTemplateItems(
formTemplateId,
@@ -189,8 +189,6 @@ const FormTemplateItemListPage = ({
showArchived
)
);
- setShowInventoryItemModal(false);
- };
const columns = [
{
diff --git a/src/pages/sponsors-global/form-templates/form-template-list-page.js b/src/pages/sponsors-global/form-templates/form-template-list-page.js
index 0d7fef187..8c42901c4 100644
--- a/src/pages/sponsors-global/form-templates/form-template-list-page.js
+++ b/src/pages/sponsors-global/form-templates/form-template-list-page.js
@@ -212,17 +212,17 @@ const FormTemplateListPage = ({
sortDir: orderDir
};
- const handleOnSave = async (values) => {
- await saveFormTemplate(values);
- getFormTemplates(
- "",
- DEFAULT_CURRENT_PAGE,
- perPage,
- order,
- orderDir,
- showArchived
+ const handleOnSave = (values) =>
+ saveFormTemplate(values).then(() =>
+ getFormTemplates(
+ "",
+ DEFAULT_CURRENT_PAGE,
+ perPage,
+ order,
+ orderDir,
+ showArchived
+ )
);
- };
return (
diff --git a/src/pages/sponsors-global/form-templates/form-template-popup.js b/src/pages/sponsors-global/form-templates/form-template-popup.js
index baef4dfdc..ed960e8b0 100644
--- a/src/pages/sponsors-global/form-templates/form-template-popup.js
+++ b/src/pages/sponsors-global/form-templates/form-template-popup.js
@@ -74,9 +74,9 @@ const FormTemplateDialog = ({
if (isSaving) return;
setIsSaving(true);
- Promise.resolve(onSave(finalValues))
+ onSave(finalValues)
.then(() => {
- closePopup();
+ onClose();
})
.catch(() => {
// keep dialog open on save error to preserve user input
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 ed5e0640b..6fc3ce635 100644
--- a/src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js
+++ b/src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js
@@ -45,6 +45,8 @@ const SponsorItemDialog = ({
onMetaFieldTypeValueDeleted,
entity: initialEntity
}) => {
+ const [isSaving, setIsSaving] = useState(false);
+
const formik = useFormik({
initialValues: {
...initialEntity,
@@ -65,7 +67,13 @@ const SponsorItemDialog = ({
quantity_limit_per_show: positiveNumberValidation(),
meta_fields: formMetafieldsValidation()
}),
- onSubmit: (values) => onSave(values)
+ onSubmit: (values) => {
+ if (isSaving) return;
+ setIsSaving(true);
+ onSave(values)
+ .then(() => onClose())
+ .finally(() => setIsSaving(false));
+ }
});
const mediaType = {
@@ -79,6 +87,7 @@ const SponsorItemDialog = ({
useScrollToError(formik);
const handleClose = () => {
+ if (isSaving) return;
formik.resetForm();
onClose();
};
@@ -92,12 +101,18 @@ const SponsorItemDialog = ({
disableEnforceFocus
disableAutoFocus
disableRestoreFocus
+ disableEscapeKeyDown={isSaving}
>
{initialEntity.id
? T.translate("edit_inventory_item.edit_item")
: T.translate("edit_inventory_item.new_item")}
-
+
@@ -227,7 +242,12 @@ const SponsorItemDialog = ({
-
diff --git a/src/pages/sponsors-global/inventory/inventory-list-page.js b/src/pages/sponsors-global/inventory/inventory-list-page.js
index b6e0d072f..be4087413 100644
--- a/src/pages/sponsors-global/inventory/inventory-list-page.js
+++ b/src/pages/sponsors-global/inventory/inventory-list-page.js
@@ -246,20 +246,17 @@ const InventoryListPage = ({
setOpen(true);
};
- const handleInventorySave = (item) => {
- saveInventoryItem(item)
- .then(() =>
- getInventoryItems(
- term,
- currentPage,
- perPage,
- order,
- orderDir,
- showArchived
- )
+ const handleInventorySave = (item) =>
+ saveInventoryItem(item).then(() =>
+ getInventoryItems(
+ term,
+ currentPage,
+ perPage,
+ order,
+ orderDir,
+ showArchived
)
- .finally(() => setOpen(false));
- };
+ );
const handleArchiveItem = (item) =>
item.is_archived
diff --git a/src/pages/sponsors-global/page-templates/page-template-list-page.js b/src/pages/sponsors-global/page-templates/page-template-list-page.js
index 0b4b05d21..c85dc193a 100644
--- a/src/pages/sponsors-global/page-templates/page-template-list-page.js
+++ b/src/pages/sponsors-global/page-templates/page-template-list-page.js
@@ -114,9 +114,17 @@ const PageTemplateListPage = ({
setOpenCloneDialog(true);
};
- const handleSavePageTemplate = (entity) => {
- savePageTemplate(entity).then(() => setOpenPageDialog(false));
- };
+ const handleSavePageTemplate = (entity) =>
+ savePageTemplate(entity).then(() =>
+ getPageTemplates(
+ term,
+ DEFAULT_CURRENT_PAGE,
+ perPage,
+ order,
+ orderDir,
+ showArchived
+ )
+ );
const handleArchive = (item) =>
item.is_archived
diff --git a/src/pages/sponsors-global/page-templates/page-template-popup/index.js b/src/pages/sponsors-global/page-templates/page-template-popup/index.js
index 91a7b2068..82987ca66 100644
--- a/src/pages/sponsors-global/page-templates/page-template-popup/index.js
+++ b/src/pages/sponsors-global/page-templates/page-template-popup/index.js
@@ -1,4 +1,4 @@
-import React from "react";
+import React, { useState } from "react";
import T from "i18n-react/dist/i18n-react";
import PropTypes from "prop-types";
import {
@@ -43,6 +43,7 @@ const PageTemplatePopup = ({
sponsorshipIds,
title
}) => {
+ const [isSaving, setIsSaving] = useState(false);
const popupTitle =
title ??
(pageTemplate?.id
@@ -129,14 +130,17 @@ const PageTemplatePopup = ({
}),
modules: yup.array().of(moduleSchema)
}),
- enableReinitialize: true,
onSubmit: (values) => {
+ if (isSaving) return;
+ setIsSaving(true);
const modulesWithOrder = values.modules.map((m, idx) => ({
...m,
custom_order: idx
}));
- onSave({ ...values, modules: modulesWithOrder });
+ onSave({ ...values, modules: modulesWithOrder })
+ .then(() => onClose())
+ .finally(() => setIsSaving(false));
}
});
@@ -179,11 +183,27 @@ const PageTemplatePopup = ({
});
};
+ const handleClose = () => {
+ if (isSaving) return;
+ onClose();
+ };
+
return (
-
);
};
diff --git a/src/pages/sponsorship-types/__tests__/sponsorship-list-page.test.js b/src/pages/sponsorship-types/__tests__/sponsorship-list-page.test.js
index f13547ca9..d450d7262 100644
--- a/src/pages/sponsorship-types/__tests__/sponsorship-list-page.test.js
+++ b/src/pages/sponsorship-types/__tests__/sponsorship-list-page.test.js
@@ -48,7 +48,7 @@ jest.mock(
onSave({ id: 0, name: "New Tier" })}
+ onClick={() => onSave({ id: 0, name: "New Tier" }).then(onClose)}
>
Save
diff --git a/src/pages/sponsorship-types/components/sponsorship-dialog.js b/src/pages/sponsorship-types/components/sponsorship-dialog.js
index dcb093564..fb60052f3 100644
--- a/src/pages/sponsorship-types/components/sponsorship-dialog.js
+++ b/src/pages/sponsorship-types/components/sponsorship-dialog.js
@@ -1,4 +1,4 @@
-import React from "react";
+import React, { useState } from "react";
import T from "i18n-react/dist/i18n-react";
import PropTypes from "prop-types";
import { FormikProvider, useFormik } from "formik";
@@ -28,12 +28,9 @@ const SIZE_OPTIONS_DDL = [
{ label: "Big", value: "Big" }
];
-const SponsorshipDialog = ({
- entity: initialEntity,
- onClose,
- onSave,
- isSaving = false
-}) => {
+const SponsorshipDialog = ({ entity: initialEntity, onClose, onSave }) => {
+ const [isSaving, setIsSaving] = useState(false);
+
const formik = useFormik({
initialValues: {
id: initialEntity?.id ?? 0,
@@ -45,12 +42,19 @@ const SponsorshipDialog = ({
validationSchema: yup.object().shape({
name: requiredStringValidation()
}),
- onSubmit: (values) => onSave(values)
+ onSubmit: (values) => {
+ if (isSaving) return;
+ setIsSaving(true);
+ onSave(values)
+ .then(() => onClose())
+ .finally(() => setIsSaving(false));
+ }
});
useScrollToError(formik);
const handleClose = () => {
+ if (isSaving) return;
formik.resetForm();
onClose();
};
diff --git a/src/pages/sponsorship-types/sponsorship-list-page.js b/src/pages/sponsorship-types/sponsorship-list-page.js
index 66854a359..0792fddb9 100644
--- a/src/pages/sponsorship-types/sponsorship-list-page.js
+++ b/src/pages/sponsorship-types/sponsorship-list-page.js
@@ -44,7 +44,6 @@ const SponsorshipListPage = ({
resetSponsorshipForm
}) => {
const [open, setOpen] = useState(false);
- const [isSaving, setIsSaving] = useState(false);
useEffect(() => {
getSponsorships();
@@ -76,21 +75,14 @@ const SponsorshipListPage = ({
};
const handleClose = () => {
- if (isSaving) return;
resetSponsorshipForm();
setOpen(false);
};
- const handleSave = (entity) => {
- if (isSaving) return;
- setIsSaving(true);
- saveSponsorship(entity)
- .then(() =>
- getSponsorships(term, DEFAULT_CURRENT_PAGE, perPage, order, orderDir)
- )
- .then(() => setOpen(false))
- .finally(() => setIsSaving(false));
- };
+ const handleSave = (entity) =>
+ saveSponsorship(entity).then(() =>
+ getSponsorships(term, DEFAULT_CURRENT_PAGE, perPage, order, orderDir)
+ );
const handleDelete = (sponsorshipId) => {
deleteSponsorship(sponsorshipId);
@@ -196,7 +188,6 @@ const SponsorshipListPage = ({
entity={currentSponsorship}
onSave={handleSave}
onClose={handleClose}
- isSaving={isSaving}
/>
)}
diff --git a/src/pages/tags/tag-list-page.js b/src/pages/tags/tag-list-page.js
index 498c1bff8..4a4a045b7 100644
--- a/src/pages/tags/tag-list-page.js
+++ b/src/pages/tags/tag-list-page.js
@@ -75,9 +75,9 @@ const TagListPage = ({
};
const handleSaveTag = (entity) =>
- saveTag(entity).then(() => {
- getTags(search, currentPage, perPage, order, orderDir);
- });
+ saveTag(entity).then(() =>
+ getTags(search, currentPage, perPage, order, orderDir)
+ );
const handleDeleteTag = (id) => {
deleteTag(id)