Skip to content

Comments

fix: adjust popup conditions to open, fetch data before open popup#802

Open
tomrndom wants to merge 4 commits intomasterfrom
fix/form-template-item-popup-cache
Open

fix: adjust popup conditions to open, fetch data before open popup#802
tomrndom wants to merge 4 commits intomasterfrom
fix/form-template-item-popup-cache

Conversation

@tomrndom
Copy link

@tomrndom tomrndom commented Feb 23, 2026

ref: https://app.clickup.com/t/86b8m74u3

Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com

Summary by CodeRabbit

  • Refactor
    • Dialog rendering updated: some modals now mount only when data is ready; others simplified to always render.
  • Bug Fixes
    • Modal flows adjusted so inventory and item modals open at the correct time, reducing flicker and premature dialogs.
  • Chores
    • Error and success messaging switched to snackbar-style notifications for consistent, on-screen feedback.

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom tomrndom requested a review from smarcet February 23, 2026 22:11
@coderabbitai
Copy link

coderabbitai bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

Removed external open props from dialog components, switched dialogs to be always-open or conditionally mounted, and changed page handlers to await async data (getFormTemplateItem / getInventoryItems) before rendering modals; action creators now use snackbar-based success/error handlers.

Changes

Cohort / File(s) Summary
Dialog components
src/pages/sponsors-global/form-templates/add-form-template-item-popup.js, src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js
Removed open from function parameters and PropTypes; Dialog usage changed from open={open} to always-open/uncontrolled rendering (dialogs no longer depend on external open prop).
Form template list page
src/pages/sponsors-global/form-templates/form-template-item-list-page.js
Updated handlers to await getFormTemplateItem / getInventoryItems before showing modals; dialogs are now conditionally rendered based on state and are no longer passed an open prop.
Actions — form-template-item
src/actions/form-template-item-actions.js
Replaced authErrorHandler/showMessage/showSuccessMessage with snackbarErrorHandler/snackbarSuccessHandler; removed history navigation in success flows and standardized snackbar-based notifications for API calls.

Sequence Diagram(s)

mermaid
sequenceDiagram
actor User
participant ListPage as List Page (UI)
participant Actions as form-template-item-actions
participant Dialog as Modal Dialog
participant Snackbar as Snackbar
User->>ListPage: click "Edit" / "New"
ListPage->>Actions: call getFormTemplateItem / getInventoryItems
Actions-->>ListPage: data (promise resolves)
ListPage->>Dialog: render/show modal (conditional)
ListPage->>Actions: save/delete actions
Actions-->>Snackbar: snackbarSuccessHandler / snackbarErrorHandler
Snackbar-->>User: show notification

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • smarcet
  • gcutrini

Poem

🐰
I hopped through code with nimble paws,
Removed a prop and fixed the flaws.
Await the fetch, then curtains rise,
Snackbars cheer with tiny sighs.
A rabbit beams — the UI flies! 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main changes: removing the open prop from dialogs to make them conditionally rendered, and ensuring data fetches complete before dialogs open.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/form-template-item-popup-cache

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/pages/sponsors-global/form-templates/form-template-item-list-page.js`:
- Around line 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.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6557b6 and c8c4f96.

📒 Files selected for processing (3)
  • src/pages/sponsors-global/form-templates/add-form-template-item-popup.js
  • src/pages/sponsors-global/form-templates/form-template-item-list-page.js
  • src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js

Comment on lines 116 to 124
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));
};
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.

Copy link

@smarcet smarcet left a comment

Choose a reason for hiding this comment

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

@tomrndom please review

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/actions/form-template-item-actions.js (1)

203-237: ⚠️ Potential issue | 🟡 Minor

Remove double-dispatch around snackbarSuccessHandler.

Line 230 wraps snackbarSuccessHandler in dispatch(dispatch(...)), which will dispatch the same action twice and can show duplicate snackbars.

🐛 Proposed fix
-              dispatch(
-                dispatch(
-                  snackbarSuccessHandler({
-                    title: T.translate("general.success"),
-                    html: T.translate(
-                      "edit_form_template_item.form_template_item_saved"
-                    )
-                  })
-                )
-              );
+              dispatch(
+                snackbarSuccessHandler({
+                  title: T.translate("general.success"),
+                  html: T.translate(
+                    "edit_form_template_item.form_template_item_saved"
+                  )
+                })
+              );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/actions/form-template-item-actions.js` around lines 203 - 237, The
success snackbar is being dispatched twice because the code calls
dispatch(dispatch(snackbarSuccessHandler(...))) inside the Promise.all . Replace
the double-dispatch with a single dispatch call: invoke
snackbarSuccessHandler(...) and pass its result once to dispatch (i.e.,
dispatch(snackbarSuccessHandler({...}))) so the action is only dispatched a
single time; update the code path that currently references
snackbarSuccessHandler within the .then of Promise.all in
form-template-item-actions.js accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/actions/form-template-item-actions.js`:
- Around line 203-237: The success snackbar is being dispatched twice because
the code calls dispatch(dispatch(snackbarSuccessHandler(...))) inside the
Promise.all . Replace the double-dispatch with a single dispatch call: invoke
snackbarSuccessHandler(...) and pass its result once to dispatch (i.e.,
dispatch(snackbarSuccessHandler({...}))) so the action is only dispatched a
single time; update the code path that currently references
snackbarSuccessHandler within the .then of Promise.all in
form-template-item-actions.js accordingly.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8c4f96 and 5c87f75.

📒 Files selected for processing (1)
  • src/actions/form-template-item-actions.js

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/actions/form-template-item-actions.js (1)

113-119: ⚠️ Potential issue | 🔴 Critical

Move stopLoading() into .finally() blocks to ensure loading state clears on request failures.

startLoading() is dispatched, but stopLoading() only runs in .then(). Since snackbarErrorHandler doesn't clear loading state (it only displays an error message), failed requests leave the UI stuck with loading active. Move stopLoading() to .finally() to guarantee cleanup in both success and error cases.

🛠️ Suggested pattern (apply similarly to other requests)
-    )(params)(dispatch).then(() => {
-      dispatch(stopLoading());
-    });
+    )(params)(dispatch)
+      .finally(() => {
+        dispatch(stopLoading());
+      });

Applies to lines: 113–119, 135–140, 155–164, 203–210, 250–256, 311–317. For lines 203–210 and 250–256, also add .finally() to the outer promise chain, not just the nested Promise.all.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/actions/form-template-item-actions.js` around lines 113 - 119, The action
dispatches call startLoading() but only invoke stopLoading() inside .then()
handlers (e.g., the getRequest call that creates
REQUEST_FORM_TEMPLATE_ITEMS/RECEIVE_FORM_TEMPLATE_ITEMS using getRequest,
createAction and snackbarErrorHandler), so failed requests leave loading stuck;
move stopLoading() into a .finally() on the promise returned by getRequest (and
similarly for other occurrences listed) so stopLoading() always runs, and for
cases with nested Promise.all ensure you attach .finally() to the outer promise
chain (not only the inner Promise.all) to guarantee cleanup even on failures.
♻️ Duplicate comments (1)
src/pages/sponsors-global/form-templates/form-template-item-list-page.js (1)

116-125: ⚠️ Potential issue | 🟡 Minor

Add rejection handling before opening modals.

Guarding a missing row is good, but fetch failures still leave the UI silent. Add a .catch to surface errors before returning.

🤖 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 - 125, Both handleRowEdit and handleNewInventoryItem currently
open modals after async fetches but lack rejection handling; update the chains
that call getFormTemplateItem(formTemplateId, row.id) in handleRowEdit and
getInventoryItems() in handleNewInventoryItem to add .catch(...) so failures
surface before opening the modal (log or surface the error via process/UI error
handler, then do not call setShowInventoryItemModal or
setShowAddInventoryItemsModal). Ensure the .catch references the same promise
chain that currently calls setShowInventoryItemModal and
setShowAddInventoryItemsModal so errors block modal opening and are reported.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/actions/form-template-item-actions.js`:
- Around line 113-119: The action dispatches call startLoading() but only invoke
stopLoading() inside .then() handlers (e.g., the getRequest call that creates
REQUEST_FORM_TEMPLATE_ITEMS/RECEIVE_FORM_TEMPLATE_ITEMS using getRequest,
createAction and snackbarErrorHandler), so failed requests leave loading stuck;
move stopLoading() into a .finally() on the promise returned by getRequest (and
similarly for other occurrences listed) so stopLoading() always runs, and for
cases with nested Promise.all ensure you attach .finally() to the outer promise
chain (not only the inner Promise.all) to guarantee cleanup even on failures.

---

Duplicate comments:
In `@src/pages/sponsors-global/form-templates/form-template-item-list-page.js`:
- Around line 116-125: Both handleRowEdit and handleNewInventoryItem currently
open modals after async fetches but lack rejection handling; update the chains
that call getFormTemplateItem(formTemplateId, row.id) in handleRowEdit and
getInventoryItems() in handleNewInventoryItem to add .catch(...) so failures
surface before opening the modal (log or surface the error via process/UI error
handler, then do not call setShowInventoryItemModal or
setShowAddInventoryItemsModal). Ensure the .catch references the same promise
chain that currently calls setShowInventoryItemModal and
setShowAddInventoryItemsModal so errors block modal opening and are reported.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c87f75 and 502201f.

📒 Files selected for processing (2)
  • src/actions/form-template-item-actions.js
  • src/pages/sponsors-global/form-templates/form-template-item-list-page.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants