-
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 1 commit
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 |
|---|---|---|
|
|
@@ -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 dialog still takes an
openprop (line 30 /<Dialog open={open}>) and its parent (form-template-list-page.js) still renders it unconditionally withopen={formTemplatePopupOpen}, instead of the conditional-mount pattern ({formTemplatePopupOpen && <FormTemplateDialog .../>}, noopenprop) that every other dialog in this PR was migrated to. Per the doc (https://github.com/fntechgit/ftn-docsnsklz/blob/main/patterns/show-admin/summit-admin-popup-dialog-pattern.md), always-render is explicitly called out as the anti-pattern to avoid, since it requires manually resetting internal state instead of getting it for free from unmount/remount. Not an active bug today (the catch/finally here is complete andenableReinitializecovers reopening for a different entity), but it's now the one outlier relative to the rest of the PR's own convention.