Skip to content

fix(emails): count the voters the blast will actually go to - #1532

Open
masiarek wants to merge 1 commit into
Equal-Vote:mainfrom
masiarek:fix/1287-blast-count-stale
Open

masiarek wants to merge 1 commit into
Equal-Vote:mainfrom
masiarek:fix/1287-blast-count-stale

Conversation

@masiarek

Copy link
Copy Markdown
Collaborator

Description

Closes #1287"The button said 'Send 3 emails' even though 2 of the 3 voters had already voted … only 1 email was sent (which is correct)".

Both sides apply the same filter. They apply it to different snapshots.

Where the number comes from
The button electionRoll, an array fetched once when the Voters page mounts — useGetRolls in a useEffect with an empty dependency list, refetched only after editing a voter or clearing the list
The send sendEmailController re-queries the roll at send time and filters again

So any ballot cast between page load and pressing the button makes the number wrong. That is exactly the reported scenario, and it needs no SendGrid access to see — it is two snapshots of one table.

Two changes

  • Opening "Draft Email Blast" refetches the roll, so the count is of the same rows the backend is about to select.
  • The button is disabled at zero. Previously a stale positive count could be pressed against an empty target, and the backend answered with a 400 — "All voters have voted" — an error for a situation the UI should not have offered.

The reporter suggested dropping the number instead; @ArendPeter's reply says the count is worth keeping "to give myself confidence that I'm filtering it properly". This keeps it and makes it true.

Not in scope

A roll whose email is blank or undeliverable is still counted and still queued. That is a delivery concern rather than a count mismatch, and the issue does not ask about it.

There is no test coverage of recipient selection at all — no backend test touches sendEmails, and no Playwright spec opens this dialog. Worth adding, but it needs a fixture with a partly-voted roll, which is more than this fix.

Related Issues

Closes #1287

"Send 3 Emails" then one email sent, which is what Equal-Vote#1287 reports. Both
sides apply the same filter; they apply it to different snapshots.

The dialog counts `electionRoll`, an array fetched once when the Voters page
mounts (`useGetRolls` in a `useEffect` with an empty dependency list, so it
is refetched only after editing a voter or clearing the list). The backend
re-queries the roll at send time and filters again
(`sendEmailController.ts`). Any ballot cast between page load and pressing
the button makes the number on the button wrong.

Two changes:

- Opening "Draft Email Blast" refetches the roll, so the count is of the
  same rows the backend is about to select.
- The button is disabled when the count is zero. Previously "Send N Emails"
  with a stale N could be pressed against an empty target, and the backend
  answered with a 400 ("All voters have voted") — an error message for a
  situation the UI should not have offered in the first place.

The reporter suggested dropping the number instead; @ArendPeter's reply
says the count is worth keeping for confidence that the filter is right, so
this keeps it and makes it true.

Not covered here: a roll whose email is blank or undeliverable is still
counted and still queued — that is a SendGrid delivery matter rather than a
count mismatch, and the issue does not ask about it.
@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@masiarek, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f774cc6f-1f9b-432a-8d05-87b4e139b783

📥 Commits

Reviewing files that changed from the base of the PR and between 7bc75a8 and 7c43b33.

📒 Files selected for processing (2)
  • packages/frontend/src/components/Election/Admin/SendEmailDialog.tsx
  • packages/frontend/src/components/Election/Admin/ViewElectionRolls.tsx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@netlify

netlify Bot commented Aug 15, 2026

Copy link
Copy Markdown

Deploy Preview for bettervoting ready!

Name Link
🔨 Latest commit 7c43b33
🔍 Latest deploy log https://app.netlify.com/projects/bettervoting/deploys/6a80abe979bd2d000812ae2b
😎 Deploy Preview https://deploy-preview-1532--bettervoting.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

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.

Make sure the count for sending email blasts is accurate

1 participant