Skip to content

Fix: prevent duplicate donation amount levels from selecting together#8236

Open
pramodjodhani wants to merge 8 commits into
developfrom
SMTNC-294-same-donation-amount-selection-bug
Open

Fix: prevent duplicate donation amount levels from selecting together#8236
pramodjodhani wants to merge 8 commits into
developfrom
SMTNC-294-same-donation-amount-selection-bug

Conversation

@pramodjodhani

@pramodjodhani pramodjodhani commented Jun 1, 2026

Copy link
Copy Markdown
Member

Resolves #SMTNC-294

Description

When two or more amount levels shared the same value, selection was derived directly from level.value === amount, so clicking one level highlighted every level with that value. This made it impossible to distinguish which duplicate level the donor actually chose.

To solve this problem:

  1. Added checked key to the levels array returned by ConvertDonationAmountBlockToFieldsApi::prepareLevelsArray().
  2. In DonationAmountLevels, use the checked flag to determine the selected level index.
  3. In DonationAmountLevels, use a getSelectedLevelIndex helper that resolves the active level. It prefers the level flagged as checked in the form builder (the configured default) only when that level's value matches the current amount, and otherwise selects a level only when exactly one matches — avoiding an ambiguous highlight across duplicates.

Visuals

https://www.loom.com/share/27722b6ba37142d0b1683497e3655e7e

Testing Instructions

  1. Edit a form's Donation amount block.
  2. Set multiple levels with the same amount
  3. On the frontend notice that when you select one of the levels, another level with the same amount also get selected.
  4. Switch to this branch and confirm that this problem doesn't happen.

Pre-review Checklist

  • Acceptance criteria satisfied and marked in related issue
  • Relevant @unreleased tags included in DocBlocks
  • Includes unit tests
  • Reviewed by the designer (if follows a design)
  • Self Review of code and UX completed

When two or more amount levels shared the same value, selection was
derived directly from `level.value === amount`, so clicking one level
highlighted every level with that value. This made it impossible to
distinguish which duplicate level the donor actually chose.

To solve this problem:

1. Added `checked` key to the `levels` array returned by
   ConvertDonationAmountBlockToFieldsApi::prepareLevelsArray().
2. In DonationAmountLevels, use the `checked` flag to determine the
   selected level index.
3. In DonationAmountLevels, use a `getSelectedLevelIndex` helper that
   resolves the active level. It prefers the level flagged as `checked`
   in the form builder (the configured default) only when that level's
   value matches the current amount, and otherwise selects a level only
   when exactly one matches — avoiding an ambiguous highlight across
   duplicates.
@kadondibetty

Copy link
Copy Markdown

Great and thanks for your help

@pramodjodhani pramodjodhani requested review from glaubersilva and jonwaldstein and removed request for jonwaldstein June 1, 2026 10:22
@pramodjodhani pramodjodhani self-assigned this Jun 1, 2026

@glaubersilva glaubersilva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@pramodjodhani In general, the code looks good and is working well, but there is a file in this PR that seems to have been added by accident, so please remove it before we move forward to QA.

Comment thread bun.lock Outdated
@pramodjodhani pramodjodhani changed the base branch from develop to release/M26.haunter June 1, 2026 17:39

@glaubersilva glaubersilva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@pramodjodhani Nice work! Ready for QA.

@pramodjodhani pramodjodhani changed the base branch from release/M26.haunter to develop June 12, 2026 05:19
@jonwaldstein

Copy link
Copy Markdown
Contributor

@pramodjodhani @glaubersilva FYI we're moving to @since TBD instead of @unreleased now since this PR 😄

@kadondibetty

Copy link
Copy Markdown

Thank you so much for your great service

@linear-code

linear-code Bot commented Jun 12, 2026

Copy link
Copy Markdown

SMTNC-294

…unts in V3 forms

- Add a hidden 'levelId' field to the 'donationAmount' Fields API group
- Set and update the 'levelId' form value in index.tsx when preset options are selected or custom amounts are entered
- Add a $levelId property to DonateControllerData and map it to Donation models during V3 form checkout
- Correct the array search logic in UpdateDonationLevelId.php listener to properly handle the associative levels schema
- Update give_get_donation_form_title to look up option values by level ID (price_id) first before falling back to amount-based matching
- Add unit tests for the UpdateDonationLevelId listener
@pramodjodhani

Copy link
Copy Markdown
Member Author

@glaubersilva Victor found a issue during QA (correct label not showing in the email).

https://linear.app/nexcess/issue/SMTNC-294/donation-amounts-with-the-same-amount-should-not-be-selected-together#comment-d96b6800

I fixed it in the latest commit. Can you please review that?

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

Great service

@glaubersilva

Copy link
Copy Markdown
Contributor

@pramodjodhani The code looks good. Just remember to add the @since TBD tags on the files you changed before send it back to QA.

@pramodjodhani

Copy link
Copy Markdown
Member Author

@glaubersilva My bad! This is corrected now 24d0f63 (this PR)

@glaubersilva

Copy link
Copy Markdown
Contributor

@pramodjodhani Sorry, I think my last comment wasn't clear. I was talking more about the changes made on this commit: Fix: prevent duplicate donation amount levels from selecting together by pramodjodhani · Pull Request #8236 · impress-org/givewp

For example, there are no @since TBD tags for the changes made to the src/DonationForms/Actions/ConvertDonationAmountBlockToFieldsApi.php file.

@pramodjodhani

Copy link
Copy Markdown
Member Author

Thanks for clarification @glaubersilva. I have added the @since comments now. I hope its all good now.

@glaubersilva

Copy link
Copy Markdown
Contributor

@pramodjodhani Thanks for the changes! It's all good. Ready for another QA round.

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