Skip to content

fix: add missing file remove calls from inventory popup - #1002

Open
tomrndom wants to merge 12 commits into
masterfrom
fix/form-image-delete
Open

fix: add missing file remove calls from inventory popup#1002
tomrndom wants to merge 12 commits into
masterfrom
fix/form-image-delete

Conversation

@tomrndom

@tomrndom tomrndom commented Jul 1, 2026

Copy link
Copy Markdown

ref: https://app.clickup.com/t/9014802374/86bakf3mp

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

Summary by CodeRabbit

  • New Features
    • Added image deletion for sponsor form items, customized sponsor form items, inventory items, and form template items.
    • Updated upload and item dialogs to support consistent image removal actions.
  • Bug Fixes
    • Improved customized form item image loading by including expanded image details in results.
    • Ensured image deletion requests finish cleanly and loading indicators stop after completion.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds authenticated sponsor form image deletion thunks, expands customized form item image retrieval, routes image deletion callbacks through upload components and dialogs, and updates Redux state after deletion.

Changes

Image deletion feature

Layer / File(s) Summary
Delete image actions and image retrieval
src/actions/sponsor-forms-actions.js
Adds deletion constants and authenticated thunks for sponsor form and customized sponsor form item images. Customized item retrieval now expands images.
Upload deletion callbacks
src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js, src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-form.js, src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-popup.js
Forwards image IDs from MuiFormikUpload to parent deletion handlers.
Page-level deletion wiring
src/pages/sponsors-global/form-templates/form-template-item-list-page.js, src/pages/sponsors-global/inventory/inventory-list-page.js, src/pages/sponsors/sponsor-form-item-list-page/index.js, src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/manage-items/sponsor-forms-manage-items.js
Adds item-specific handlers and passes them to inventory and form dialogs.
Deleted image state update
src/reducers/sponsors/sponsor-form-items-list-reducer.js
Removes deleted images from the current item and the matching list item.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MuiFormikUpload
  participant SponsorInventoryDialog
  participant Page
  participant SponsorFormsActions
  participant API
  participant ReduxStore

  MuiFormikUpload->>SponsorInventoryDialog: delete image id
  SponsorInventoryDialog->>Page: invoke onImageDeleted with image id
  Page->>SponsorFormsActions: invoke deletion thunk with item context
  SponsorFormsActions->>API: send authenticated DELETE request
  API-->>SponsorFormsActions: return deletion response
  SponsorFormsActions->>ReduxStore: dispatch image-deleted action
Loading

Possibly related PRs

Suggested reviewers: santipalenque, smarcet

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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 primary change: adding missing image removal calls from the inventory popup.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/form-image-delete

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

@tomrndom
tomrndom marked this pull request as ready for review July 9, 2026 12:38

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

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

⚠️ Outside diff range comments (1)
src/actions/sponsor-forms-actions.js (1)

1448-1465: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Call saveItemImages heresaveImages is undefined in this module, so this branch throws a ReferenceError after the POST succeeds and skips the success snackbar/return flow. Pass formId, response.id, and the images array to saveItemImages instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/actions/sponsor-forms-actions.js` around lines 1448 - 1465, The success
branch in the sponsor form item save flow is calling an undefined saveImages
helper, which causes a ReferenceError after the POST succeeds. Update the
promise chain in the action that handles the POST response to use saveItemImages
instead, and pass the formId, response.id, and the images array so the success
snackbar and return flow complete normally.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/actions/sponsor-forms-actions.js`:
- Around line 1627-1649: The removeSponsorCustomizedFormItemImages action is
using the whole-item deletion action for an image-only endpoint, which can cause
the item row to be removed instead of just the image. Update the deleteRequest
callback in removeSponsorCustomizedFormItemImages to dispatch a dedicated
image-delete action (or add one if missing) and ensure
sponsor-customized-form-items-list-reducer.js handles that image-specific action
separately from SPONSOR_CUSTOMIZED_FORM_ITEM_DELETED.

In `@src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js`:
- Around line 87-90: The optional onImageDeleted callback is being invoked
unconditionally in handleIDeleteImage, which can throw when the prop is omitted.
Update handleIDeleteImage in sponsor-inventory-popup.js to guard the callback
before calling it, keeping the image id check but only invoking onImageDeleted
when it is defined.

In
`@src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-form.js`:
- Around line 60-63: `handleDeleteImage` in `SponsorFormItemForm` should
defensively guard the `onImageDeleted` callback before calling it, since it may
be undefined like in the sibling `SponsorItemDialog`. Update the delete handler
to check that `onImageDeleted` exists alongside the `id` check, keeping the same
behavior when the callback is provided.

In
`@src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-popup.js`:
- Around line 55-60: The dialog title in SponsorFormItemPopup includes leftover
debug text after the translated label, so remove the literal string from the
Typography block and keep only the T.translate result in the popup title. Use
the existing SponsorFormItemPopup component and its title rendering logic to
locate and clean up this stray text.

---

Outside diff comments:
In `@src/actions/sponsor-forms-actions.js`:
- Around line 1448-1465: The success branch in the sponsor form item save flow
is calling an undefined saveImages helper, which causes a ReferenceError after
the POST succeeds. Update the promise chain in the action that handles the POST
response to use saveItemImages instead, and pass the formId, response.id, and
the images array so the success snackbar and return flow complete normally.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 57ad779e-180d-41ad-9758-c88bd93dd6d4

📥 Commits

Reviewing files that changed from the base of the PR and between 05f5ba9 and ae76f55.

📒 Files selected for processing (7)
  • src/actions/sponsor-forms-actions.js
  • src/pages/sponsors-global/form-templates/form-template-item-list-page.js
  • src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js
  • src/pages/sponsors-global/inventory/inventory-list-page.js
  • src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-form.js
  • src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-popup.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/manage-items/sponsor-forms-manage-items.js

Comment on lines +1627 to +1649

export const removeSponsorCustomizedFormItemImages =
(formId, formItemId, fileId) => async (dispatch, getState) => {
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const {
entity: { id: sponsorId }
} = currentSponsorState;
const accessToken = await getAccessTokenSafely();
const params = { access_token: accessToken };

dispatch(startLoading());

return deleteRequest(
null,
createAction(SPONSOR_CUSTOMIZED_FORM_ITEM_DELETED),
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsorId}/sponsor-forms/${formId}/items/${formItemId}/images/${fileId}`,
null,
snackbarErrorHandler
)(params)(dispatch).finally(() => {
dispatch(stopLoading());
});
};

@coderabbitai coderabbitai Bot Jul 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n 'SPONSOR_CUSTOMIZED_FORM_ITEM_DELETED' src -g '*.js'
rg -n 'SPONSOR_FORM_ITEM_FILE_DELETED' src -g '*.js'

Repository: fntechgit/summit-admin

Length of output: 881


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,220p' src/reducers/sponsors/sponsor-customized-form-items-list-reducer.js
printf '\n---\n'
sed -n '1160,1215p' src/actions/sponsor-forms-actions.js
printf '\n---\n'
sed -n '1,180p' src/reducers/sponsors/sponsor-form-items-list-reducer.js

Repository: fntechgit/summit-admin

Length of output: 10737


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n 'function deleteRequest|const deleteRequest|export .*deleteRequest' src node_modules -g '*.js'
printf '\n---\n'
rg -n 'SPONSOR_CUSTOMIZED_FORM_ITEM_DELETED|SPONSOR_FORM_ITEM_FILE_DELETED' src/reducers src/actions -g '*.js' -A3 -B3
printf '\n---\n'
rg -n 'removeSponsorCustomizedFormItemImages|removeItemFile' src/actions/sponsor-forms-actions.js -A20 -B5

Repository: fntechgit/summit-admin

Length of output: 6242


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n 'deleteRequest' src -g '*.js'
printf '\n---\n'
rg -n 'createAction\(SPONSOR_CUSTOMIZED_FORM_ITEM_DELETED\)|createAction\(SPONSOR_FORM_ITEM_FILE_DELETED\)' src/actions/sponsor-forms-actions.js -A6 -B6
printf '\n---\n'
rg -n 'itemId' src/actions src/reducers -g '*.js' -A2 -B2 | head -n 200

Repository: fntechgit/summit-admin

Length of output: 31518


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n 'SPONSOR_FORM_ITEM_FILE_DELETED|SPONSOR_CUSTOMIZED_FORM_ITEM_DELETED' src/reducers src/actions -g '*.js' -A3 -B3
printf '\n---\n'
rg -n 'case .*FILE_DELETED|case .*CUSTOMIZED_FORM_ITEM_DELETED' src/reducers -g '*.js' -A4 -B4

Repository: fntechgit/summit-admin

Length of output: 7406


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n 'export .*createAction|const createAction|function createAction' src node_modules openstack-uicore-foundation -g '*.js' -g '*.ts'
printf '\n---\n'
rg -n 'deleteRequest\(' src/actions -g '*.js' -A8 -B4 | head -n 120

Repository: fntechgit/summit-admin

Length of output: 228


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n 'deleteRequest\(\s*null,\s*createAction\([A-Z0-9_]+\)(\s*\{|\s*\()|deleteRequest\(\s*null,\s*createAction\([A-Z0-9_]+\)\s*,' src/actions -g '*.js' -A4 -B2
printf '\n---\n'
rg -n 'createAction\([A-Z0-9_]+\)\s*\(\{[^}]*itemId[^}]*\}\)' src/actions -g '*.js' -A2 -B2

Repository: fntechgit/summit-admin

Length of output: 160


🌐 Web query:

openstack-uicore-foundation deleteRequest createAction payload itemId

💡 Result:

In the openstack-uicore-foundation library, createAction and deleteRequest are components of a standard Redux-based pattern used for handling asynchronous API operations [1][2]. 1. createAction: This is a factory function used to create Redux action objects. It takes a type and returns a function that accepts a payload, resulting in an action object with the structure: { type, payload } [2]. javascript export const createAction = type => payload => ({ type, payload }); 2. deleteRequest: This is a helper function defined in src/utils/actions.js that facilitates HTTP DELETE requests [1][3]. It is typically used within an asynchronous thunk action to handle the API call lifecycle [2]. When implementing a delete action, the payload parameter often contains specific data required for the request, such as an itemId or other identifiers needed to construct the API endpoint or request body [1][2]. While the exact implementation of the payload depends on the specific consumer, it is typically passed through the thunk to the deleteRequest helper, which then executes the request and dispatches the corresponding Redux actions [1][2].

Citations:


🌐 Web query:

openstack-uicore-foundation deleteRequest implementation createAction payload action creator

💡 Result:

In the openstack-uicore-foundation library, the createAction factory and the deleteRequest helper are components of a standardized Redux pattern used for handling asynchronous API operations [1][2]. createAction Implementation The createAction function is a simple factory that generates a standard Redux action creator [2][3]. It takes an action type as its argument and returns a function that accepts a payload, producing an object with the structure { type, payload } [2][3]. Implementation: export const createAction = type => payload => ({ type, payload }); deleteRequest Implementation The deleteRequest function is a utility helper located in utils/actions.js [1]. It is designed to work within an asynchronous Redux thunk pattern to handle DELETE HTTP requests [1][2]. It typically takes the request action creator and the success/receive action creator (both created via createAction) as arguments, along with the API URL and an error handler [2]. Typical Usage Pattern: When used in a thunk, deleteRequest is invoked with the necessary action creators to dispatch the appropriate lifecycle events (e.g., initiating the request and handling the response) [1][2]. Example structure of an async thunk: export const myAction = (params) => async (dispatch, getState) => { dispatch(startLoading); return deleteRequest( createAction(REQUEST_TYPE), createAction(RECEIVE_TYPE), buildAPIBaseUrl('/api/v1/endpoint'), authErrorHandler)(params)(dispatch, getState); }; This pattern ensures consistent action dispatching and error handling, specifically integrating with authErrorHandler to manage authentication errors such as 401 redirects [1][2].

Citations:


🌐 Web query:

site:unpkg.com openstack-uicore-foundation deleteRequest src/utils/actions.js

💡 Result:

In the openstack-uicore-foundation library, deleteRequest is a utility function located in src/utils/actions.js [1]. It serves as an HTTP request helper designed to facilitate DELETE operations within the application's architecture [1]. This function is typically used as part of a set of API utilities, which include other standard HTTP request helpers like getRequest, putRequest, and postRequest [1]. These utilities are generally utilized in conjunction with Redux action creators to manage API interactions, often incorporating error handling mechanisms such as authErrorHandler to manage session states or authentication issues (e.g., handling 401 errors) [1].

Citations:


Use a dedicated image-delete action here. SPONSOR_CUSTOMIZED_FORM_ITEM_DELETED is handled by sponsor-customized-form-items-list-reducer.js as a whole-item removal, so using it for /images/${fileId} can drop the item row instead of just removing one image. src/actions/sponsor-forms-actions.js:1628

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/actions/sponsor-forms-actions.js` around lines 1627 - 1649, The
removeSponsorCustomizedFormItemImages action is using the whole-item deletion
action for an image-only endpoint, which can cause the item row to be removed
instead of just the image. Update the deleteRequest callback in
removeSponsorCustomizedFormItemImages to dispatch a dedicated image-delete
action (or add one if missing) and ensure
sponsor-customized-form-items-list-reducer.js handles that image-specific action
separately from SPONSOR_CUSTOMIZED_FORM_ITEM_DELETED.

✅ Addressed in commit 39221f4

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tomrndom Reopening this — it was marked resolved but only half of the ask landed.

The thread asked for two things: dispatch a dedicated image-delete action, and have sponsor-customized-form-items-list-reducer.js handle it separately. On the current tip (bd8aa78):

  • The dedicated constant SPONSOR_CUSTOMIZED_FORM_ITEM_IMAGE_DELETED exists, but it is dispatched unappliedcreateAction(TYPE) instead of createAction(TYPE)({ fileId }) — so what reaches the store is { type, payload: { response } }, not { fileId }.
  • git grep SPONSOR_CUSTOMIZED_FORM_ITEM_IMAGE_DELETED src returns only the constant declaration and that single dispatch. The reducer has zero references to it.

Net effect: the DELETE succeeds server-side and no state updates. Details, the user-visible symptom, and a suggested patch are in my comment on line 1793.

Worth noting the sibling thread on line 1285 makes the same "pass an applied creator carrying the payload" point — that one was applied to removeItemFile but not to removeSponsorCustomizedFormItemImages.

Comment thread src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-popup.js (1)

74-81: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

removeItemFile missing from propTypes.

The prop is destructured and used at Line 29/46 but not declared in propTypes, unlike the other injected action props.

🐛 Proposed fix
 SponsorFormItemPopup.propTypes = {
   open: PropTypes.bool.isRequired,
   onClose: PropTypes.func.isRequired,
   formId: PropTypes.string.isRequired,
   resetSponsorFormItem: PropTypes.func.isRequired,
   saveSponsorFormItem: PropTypes.func.isRequired,
-  updateSponsorFormItem: PropTypes.func.isRequired
+  updateSponsorFormItem: PropTypes.func.isRequired,
+  removeItemFile: PropTypes.func.isRequired
 };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-popup.js`
around lines 74 - 81, The SponsorFormItemPopup component is using the
removeItemFile prop but it is missing from its propTypes declaration. Update
SponsorFormItemPopup.propTypes to include removeItemFile alongside the other
injected action props so the component’s expected props match the destructuring
and usage in SponsorFormItemPopup.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-popup.js`:
- Around line 74-81: The SponsorFormItemPopup component is using the
removeItemFile prop but it is missing from its propTypes declaration. Update
SponsorFormItemPopup.propTypes to include removeItemFile alongside the other
injected action props so the component’s expected props match the destructuring
and usage in SponsorFormItemPopup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9041e12b-b634-4ccf-855c-df050b4cb506

📥 Commits

Reviewing files that changed from the base of the PR and between 39221f4 and d27136e.

📒 Files selected for processing (1)
  • src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-popup.js

@smarcet
smarcet requested a review from Copilot July 28, 2026 16:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@smarcet
smarcet requested a review from santipalenque July 28, 2026 16:13
Comment thread src/actions/sponsor-forms-actions.js Outdated
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom
tomrndom force-pushed the fix/form-image-delete branch from d27136e to 564071b Compare August 1, 2026 05:45

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/actions/sponsor-forms-actions.js`:
- Around line 1277-1285: Update the image-delete flow using
SPONSOR_FORM_ITEM_FILE_DELETED so deleteRequest receives an action payload
containing fileId rather than an unbound action creator. Add handling for this
action in both relevant reducers, removing the deleted image by fileId from
currentItem.images while preserving the remaining images.

In `@src/pages/sponsors/sponsor-form-item-list-page/index.js`:
- Around line 134-136: Update handleRemoveItemImage to pass the current form
item’s ID, rather than the currentItem object, as removeItemFile’s second
argument so the generated item URL contains the actual identifier.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b9f71fad-e979-4706-be14-026d85894e15

📥 Commits

Reviewing files that changed from the base of the PR and between d27136e and 564071b.

📒 Files selected for processing (8)
  • src/actions/sponsor-forms-actions.js
  • src/pages/sponsors-global/form-templates/form-template-item-list-page.js
  • src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js
  • src/pages/sponsors-global/inventory/inventory-list-page.js
  • src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-form.js
  • src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-popup.js
  • src/pages/sponsors/sponsor-form-item-list-page/index.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/manage-items/sponsor-forms-manage-items.js
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/pages/sponsors-global/form-templates/form-template-item-list-page.js
  • src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-form.js
  • src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/manage-items/sponsor-forms-manage-items.js
  • src/pages/sponsors-global/inventory/inventory-list-page.js

Comment thread src/actions/sponsor-forms-actions.js Outdated
Comment thread src/pages/sponsors/sponsor-form-item-list-page/index.js
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/reducers/sponsors/sponsor-form-items-list-reducer.js`:
- Around line 120-134: Update the SPONSOR_FORM_ITEM_FILE_DELETED flow and its
removeItemFile dispatch to include itemId: formItemId in the payload. In the
reducer, match state.items by itemId and only remove the image from currentItem
when currentItem.id matches itemId; otherwise preserve currentItem unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 361dafbf-da5f-4a22-b851-b8ca9427a8d1

📥 Commits

Reviewing files that changed from the base of the PR and between 564071b and bd8aa78.

📒 Files selected for processing (3)
  • src/actions/sponsor-forms-actions.js
  • src/pages/sponsors/sponsor-form-item-list-page/index.js
  • src/reducers/sponsors/sponsor-form-items-list-reducer.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/pages/sponsors/sponsor-form-item-list-page/index.js
  • src/actions/sponsor-forms-actions.js

Comment thread src/reducers/sponsors/sponsor-form-items-list-reducer.js
Comment thread src/actions/sponsor-forms-actions.js Outdated
Comment thread src/reducers/sponsors/sponsor-form-items-list-reducer.js
@smarcet
smarcet requested a review from santipalenque August 3, 2026 15:58

@smarcet smarcet left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tomrndom please re review

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

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

const handleRemoveItemImage = (imageId) =>
removeItemFile(formId, currentItem?.id, imageId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tomrndom This needs a guard for unsaved items. The new-item flows reset to a non-persisted entity but still pass onImageDeleted, so removing an uploaded image before saving calls the backend with an invalid item id.

Examples:

  • src/pages/sponsors/sponsor-form-item-list-page/index.js:134 can call removeItemFile(formId, undefined, imageId).
  • src/pages/sponsors-global/inventory/inventory-list-page.js:152 can call deleteInventoryItemImage(0, imageId) from the default entity.

Repro: Add item -> upload image -> click the image trash button before saving. The request becomes /items/undefined/images/{id} or /inventory-items/0/images/{id}.

Please only call the backend delete for persisted item images. For unsaved uploads, the upload component/Formik state should remove the image locally without issuing an item-image DELETE.

})
);
});
dispatch(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tomrndom This simplification now relies entirely on the update body to persist images, but RECEIVE_SPONSOR_FORM_ITEM (src/reducers/sponsors/sponsor-form-items-list-reducer.js) stores fetched images without mapping file_url to file_path — so saving any existing item wipes all of its images server-side.

ShowFormItemImageSerializer in purchases-api marks file_path write_only=True — a GET response only ever contains file_url. normalizeItem keeps only images with a truthy file_path before sending them here. Since currentItem.images never has file_path, editing any existing item (even just the name) sends images: [] in this PUT, and ShowFormItemService.update() treats 'images' in payload as True — deleting every attached image before repopulating from the (empty) list. No error is shown; the save reports success.

This is the same class of bug the sibling reducer already fixed — see sponsor-customized-form-items-list-reducer.js's RECEIVE_SPONSOR_CUSTOMIZED_FORM_ITEM case, which maps file_path: img.file_url on each image specifically for this reason (its own test is titled "the edit-form image fix"). This reducer never got the same fix.

Suggested fix — mirror it in sponsor-form-items-list-reducer.js's RECEIVE_SPONSOR_FORM_ITEM case:

case RECEIVE_SPONSOR_FORM_ITEM: {
  const item = payload.response;
  const currentItem = {
    ...item,
    images: (item.images || []).map((img) => ({
      ...img,
      file_path: img.file_url
    })),
    meta_fields: item.meta_fields.length > 0 ? item.meta_fields : []
  };
  return { ...state, currentItem };
}

…e_path on images

Mirrors the customized-item reducer's existing file_url -> file_path
mapping. Currently red: RECEIVE_SPONSOR_FORM_ITEM stores fetched images
as-is, so normalizeItem strips them from the update body and
ShowFormItemService.update() deletes all images on save.

@smarcet smarcet left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tomrndom please re review

… from item without id

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
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.

4 participants