-
Notifications
You must be signed in to change notification settings - Fork 4
fix: adjust popup pattern, add isSaving on popups, return promises #994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,9 +74,9 @@ const FormTemplateDialog = ({ | |
| if (isSaving) return; | ||
|
|
||
| setIsSaving(true); | ||
| Promise.resolve(onSave(finalValues)) | ||
| onSave(finalValues) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tomrndom This dialog still takes an |
||
| .then(() => { | ||
| closePopup(); | ||
| onClose(); | ||
| }) | ||
| .catch(() => { | ||
| // keep dialog open on save error to preserve user input | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tomrndom This dialog (and |
||
| .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} | ||
| > | ||
| <DialogTitle sx={{ display: "flex", justifyContent: "space-between" }}> | ||
| {initialEntity.id | ||
| ? T.translate("edit_inventory_item.edit_item") | ||
| : T.translate("edit_inventory_item.new_item")} | ||
| <IconButton size="small" onClick={handleClose} sx={{ mr: 1 }}> | ||
| <IconButton | ||
| size="small" | ||
| onClick={handleClose} | ||
| sx={{ mr: 1 }} | ||
| disabled={isSaving} | ||
| > | ||
| <CloseIcon fontSize="small" /> | ||
| </IconButton> | ||
| </DialogTitle> | ||
|
|
@@ -227,7 +242,12 @@ const SponsorItemDialog = ({ | |
| </DialogContent> | ||
| <Divider /> | ||
| <DialogActions> | ||
| <Button type="submit" fullWidth variant="contained"> | ||
| <Button | ||
| type="submit" | ||
| fullWidth | ||
| variant="contained" | ||
| disabled={isSaving} | ||
| > | ||
| {T.translate("edit_inventory_item.save_changes")} | ||
| </Button> | ||
| </DialogActions> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,20 +246,17 @@ const InventoryListPage = ({ | |
| setOpen(true); | ||
| }; | ||
|
|
||
| const handleInventorySave = (item) => { | ||
| saveInventoryItem(item) | ||
| .then(() => | ||
| getInventoryItems( | ||
| term, | ||
| currentPage, | ||
| perPage, | ||
| order, | ||
| orderDir, | ||
| showArchived | ||
| ) | ||
| const handleInventorySave = (item) => | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tomrndom Per the popup pattern doc's Responsibility Split section (https://github.com/fntechgit/ftn-docsnsklz/blob/main/patterns/show-admin/summit-admin-popup-dialog-pattern.md), the list refresh inside the parent's save handler should be fire-and-forget ( |
||
| saveInventoryItem(item).then(() => | ||
| getInventoryItems( | ||
| term, | ||
| currentPage, | ||
| perPage, | ||
| order, | ||
| orderDir, | ||
| showArchived | ||
| ) | ||
| .finally(() => setOpen(false)); | ||
| }; | ||
| ); | ||
|
Comment on lines
+249
to
+259
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure the returned save promise reflects real completion/failure.
Suggested fix in
|
||
|
|
||
| const handleArchiveItem = (item) => | ||
| item.is_archived | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomrndom This PR fixes the update branch here to
return/rethrow on failure, but the sibling create branch below (postRequest(...), ~line 259) still has the same bug this fix addresses: the innerPromise.all(promises)...catch(err => console.error(err))is never returned, and the outer.catch((err) => { console.error(err); })doesn't rethrow - sosaveInventoryItemfor a new item always resolves, even when the POST fails. Combined with the new self-close contract insponsor-inventory-popup.js(onSave(values).then(() => onClose())), a failed "Add Item" now silently closes the dialog as if it succeeded. Worth applying the same fix to the create branch.