Skip to content

fix: change managed form endpoint, rename actions, clean dead code#966

Merged
smarcet merged 4 commits into
masterfrom
fix/sponsor-managed-forms-endpoint
Jun 9, 2026
Merged

fix: change managed form endpoint, rename actions, clean dead code#966
smarcet merged 4 commits into
masterfrom
fix/sponsor-managed-forms-endpoint

Conversation

@tomrndom

@tomrndom tomrndom commented Jun 8, 2026

Copy link
Copy Markdown

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

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

Summary by CodeRabbit

  • Refactor

    • Consolidated sponsorship fetching into a single sponsorships listing flow and removed the separate sponsorship add‑ons fetch.
    • Pages and components now use a flattened sponsorships array and request managed forms via sponsor‑scoped endpoints.
    • Removed unused add‑ons wiring and props across sponsor pages.
  • Tests

    • Updated mocks and fixtures to match the new sponsorship state shape and action names.

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

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6353bcfe-bc0d-4a78-bb35-f36ca1955c41

📥 Commits

Reviewing files that changed from the base of the PR and between a66e658 and e5cfdd8.

📒 Files selected for processing (1)
  • src/reducers/sponsors/sponsor-reducer.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/reducers/sponsors/sponsor-reducer.js

📝 Walkthrough

Walkthrough

This PR renames getSponsorTiers to getSponsorSponsorships, removes sponsorship add-ons actions/thunks, updates managed-form requests to sponsor-scoped endpoints, and flattens sponsor state from sponsorships_collection.sponsorships to sponsorships, with corresponding wiring and test updates.

Changes

Sponsor actions and data structure refactor

Layer / File(s) Summary
Action layer refactoring
src/actions/sponsor-actions.js
Renamed exported thunk getSponsorTiers to getSponsorSponsorships, removed action type constants REQUEST_SPONSOR_SPONSORSHIPS_ADDONS and RECEIVE_SPONSOR_SPONSORSHIPS_ADDONS, and removed exported getSponsorshipAddons thunk while keeping the sponsorship endpoint and pagination structure intact.
Sponsor-scoped managed-form endpoint
src/actions/sponsor-forms-actions.js
Updated getSponsorManagedForm to read sponsorId from Redux currentSponsorState and route requests to the sponsor-scoped /sponsors/{sponsorId}/managed-forms/{formId} endpoint instead of the generic show-forms/{formId} path.
Flatten sponsor sponsorships data structure
src/pages/sponsors/sponsor-page/tabs/sponsor-pages-tab/__tests__/sponsor-pages-tab.test.js, src/pages/sponsors/sponsor-page/tabs/sponsor-pages-tab/index.js, src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/customized-form/customized-form.js, src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/customized-form/__tests__/customized-form-popup.test.js, src/reducers/sponsors/sponsor-reducer.js
Changed sponsor state shape from nested sponsorships_collection: { sponsorships: [] } to flat sponsorships: [] in test fixtures, reducer default entity, page-template ID derivations, and form add-ons queries; tests updated to assert the new query-params payload.
Wire renamed action into sponsor pages
src/pages/sponsors/sponsor-page/index.js
Updated imports, props destructuring, useEffect fetch sequence, and Redux dispatch mapping to use getSponsorSponsorships instead of getSponsorTiers.
Wire renamed action into sponsor general form
src/pages/sponsors/sponsor-page/tabs/sponsor-general-form/index.js, src/pages/sponsors/sponsor-page/tabs/sponsor-general-form/sponsorship.js
Updated action imports and dispatch mapping to use getSponsorSponsorships and removed getSponsorTiers and getSponsorshipAddons from the form wiring; removed getSponsorshipAddons prop from child Sponsorship component.
Update test mocks
src/pages/sponsors/__tests__/edit-sponsor-page.test.js
Added mocked getSponsorSponsorships action creator to the sponsor-actions Jest mock factory.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly Related PRs

  • fntechgit/summit-admin#805: Also touches sponsorshipIds derivation and sponsor page add-ons flow; may overlap with the flattened sponsorships shape change.

Suggested Reviewers

  • smarcet
  • romanetar

"🐰 I hopped through code with a twitchy nose,
I flattened nests where nested data grows,
Actions renamed, add-ons unbound,
Sponsor forms now scoped and sound,
A little carrot for cleaner rows!"

🚥 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 accurately summarizes the three main changes: managed form endpoint modification, action renaming (getSponsorTiers → getSponsorSponsorships), and removal of dead code (getSponsorshipAddons and related constants).
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.

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

✨ 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/sponsor-managed-forms-endpoint

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

@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

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-actions.js (1)

383-388: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Update the reducer contract before switching consumers to entity.sponsorships.

Line 383 still emits RECEIVE_SPONSOR_SPONSORSHIPS, and src/reducers/sponsors/sponsor-reducer.js:503-525 currently stores that payload in entity.sponsorships_collection.sponsorships. The rest of this PR stack now reads entity.sponsorships, so the fetch will succeed but the new callers will still render an empty sponsorship list until the reducer migration lands with this rename.

🤖 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-actions.js` around lines 383 - 388, The reducer contract
must be updated so the existing RECEIVE_SPONSOR_SPONSORSHIPS action continues to
populate the new location expected by consumers (entity.sponsorships) before you
switch callers to that path; modify the sponsor reducer handling of
RECEIVE_SPONSOR_SPONSORSHIPS in sponsor-reducer.js (the code that currently
writes into entity.sponsorships_collection.sponsorships) to instead set
entity.sponsorships (and for safety keep the old
sponsorships_collection.sponsorships until all callers are migrated), leaving
the getRequest/createAction call and action constant
(RECEIVE_SPONSOR_SPONSORSHIPS) unchanged.
🤖 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/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/customized-form/customized-form.js`:
- Line 57: sponsor.sponsorships may be undefined so the map call can throw;
update the calculation of sponsorshipIds to safely handle that by using optional
chaining and a fallback (e.g., compute sponsorshipIds from
sponsor.sponsorships?.map(...) ?? [] or an equivalent null-safe expression) so
that sponsorshipIds becomes an empty array when sponsor.sponsorships is missing;
adjust the code where sponsorshipIds is referenced if it assumes non-empty
values.

In `@src/pages/sponsors/sponsor-page/tabs/sponsor-pages-tab/index.js`:
- Line 384: sponsor.sponsorships may be undefined and calling .map on it can
throw; update the computation of sponsorshipIds to guard against null/undefined
by using optional chaining or a fallback array (e.g., use
sponsor.sponsorships?.map(...) with a fallback to [] or (sponsor.sponsorships ||
[]).map(...)) so the code that computes sponsorshipIds (the line referencing
sponsor.sponsorships.map and the variable sponsorshipIds) never invokes .map on
undefined.

---

Outside diff comments:
In `@src/actions/sponsor-actions.js`:
- Around line 383-388: The reducer contract must be updated so the existing
RECEIVE_SPONSOR_SPONSORSHIPS action continues to populate the new location
expected by consumers (entity.sponsorships) before you switch callers to that
path; modify the sponsor reducer handling of RECEIVE_SPONSOR_SPONSORSHIPS in
sponsor-reducer.js (the code that currently writes into
entity.sponsorships_collection.sponsorships) to instead set entity.sponsorships
(and for safety keep the old sponsorships_collection.sponsorships until all
callers are migrated), leaving the getRequest/createAction call and action
constant (RECEIVE_SPONSOR_SPONSORSHIPS) 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: 8f6658fc-87f5-4cce-ae1c-c5b83b546479

📥 Commits

Reviewing files that changed from the base of the PR and between 8243964 and f23f066.

📒 Files selected for processing (9)
  • src/actions/sponsor-actions.js
  • src/actions/sponsor-forms-actions.js
  • src/pages/sponsors/__tests__/edit-sponsor-page.test.js
  • src/pages/sponsors/sponsor-page/index.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/customized-form/customized-form.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-general-form/index.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-general-form/sponsorship.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-pages-tab/__tests__/sponsor-pages-tab.test.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-pages-tab/index.js
💤 Files with no reviewable changes (1)
  • src/pages/sponsors/sponsor-page/tabs/sponsor-general-form/sponsorship.js

Comment thread src/pages/sponsors/sponsor-page/tabs/sponsor-pages-tab/index.js Outdated
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
const sponsorships = sponsor.sponsorships_collection.sponsorships.map(
(e) => e.id
);
const sponsorshipIds = sponsor.sponsorships?.map((e) => e.id) || [];

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 define sponsorships: [] at DEFAULT_ENTITY in sponsor-reducer.js

@@ -54,9 +54,7 @@ const CustomizedForm = ({
isSaving = false,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The entity mock in customized-form-popup.test.js still uses the old shape (sponsorships_collection: { sponsorships: [] }), so sponsor.sponsorships is undefined in every test and sponsorshipIds is always []. The non-empty filtering path is never exercised.

Consider updating the mock to the new shape and adding an assertion that the sponsorship ID reaches the queryParams prop on the MuiFormikSelectGroup that loads add-ons:

// customized-form-popup.test.js
const createSponsor = (overrides = {}) => ({
  id: 1,
  sponsorships: [{ id: 42 }],
  ...overrides
});

@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 review

… check sponsorships

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-reducer.js`:
- Around line 132-133: The reducer normalizes API sponsor data in the
RECEIVE_SPONSOR handling but coerces null sponsorships to an empty string which
can break consumers expecting an array; update the normalization in the
RECEIVE_SPONSOR branch so that any null/undefined sponsorships field is
converted to an empty array (or DEFAULT_SPONSORHIPS_STATE) instead of "", and
ensure the state key sponsorships remains an array (refer to the sponsorships
state, RECEIVE_SPONSOR handling, and DEFAULT_SPONSORHIPS_STATE to locate and
change the coercion).
🪄 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: 5238a92a-fa74-4817-93c5-a61a7fba0b1b

📥 Commits

Reviewing files that changed from the base of the PR and between 558f03d and a66e658.

📒 Files selected for processing (2)
  • src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/customized-form/__tests__/customized-form-popup.test.js
  • src/reducers/sponsors/sponsor-reducer.js

Comment thread src/reducers/sponsors/sponsor-reducer.js
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom tomrndom requested a review from smarcet June 9, 2026 13:43

@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.

LGTM

@smarcet smarcet merged commit 415be12 into master Jun 9, 2026
9 checks passed
smarcet pushed a commit that referenced this pull request Jun 11, 2026
)

* fix: change managed form endpoint, rename actions, clean dead code

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

* fix: add conditional chaining for array of sponsorships

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

* fix: add sponsorship array to reducer, update customized form test to check sponsorships

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

* fix: preserve sponsorship array type on RECEIVE_SPONSOR

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

---------

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.

2 participants