Newsletter: hide Comp action when the site has no paid plans#49531
Newsletter: hide Comp action when the site has no paid plans#49531CGastrell wants to merge 1 commit into
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
There was a problem hiding this comment.
Pull request overview
This PR improves the Newsletter Subscribers UI by preventing users from hitting a dead-end “Comp a subscription” flow on sites that have no paid newsletter plans configured.
Changes:
- Hoists the membership products fetch to the Subscribers table level and uses it to gate whether the “Comp a subscription” action is offered.
- Updates the memberships-products hook docblock to reflect the new shared/cached usage between table + modal.
- Removes the “no paid plans configured” notice from the Comp modal since the modal should no longer be reachable in that state.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| projects/packages/newsletter/changelog/change-newsletter-comp-gate-paid-plans | Adds a changelog entry documenting the UI behavior change. |
| projects/packages/newsletter/_inc/subscribers/data/use-memberships-products.ts | Updates hook documentation to reflect table-level usage and cache reuse. |
| projects/packages/newsletter/_inc/subscribers/components/subscribers-data-views.tsx | Fetches products once at table level and gates the Comp action on “paid products exist”. |
| projects/packages/newsletter/_inc/subscribers/components/modals/comp-modal.tsx | Removes the “no paid plans configured” notice that should now be unreachable. |
The "Comp a subscription" Subscribers action previously appeared for any subscriber with a wpcom user id, then opened a modal that only reported "no paid plans" when the site had none — a dead end. Fetch the site's membership products once at the table level and gate the action's availability on whether any paid product exists, so the action is only offered when there's something to comp onto. The per-row eligibility check reuses that single result, adding no per-row network requests. Remove the now-unreachable "no paid plans" notice from the Comp modal.
890e606 to
cbcf644
Compare
|
Thanks @copilot — good catch on the error-state behavior. Addressed in the latest push. The valid issue: gating Fix: derive a dedicated gate that fails open on error: const { data: membershipsProducts, isError: membershipsProductsError } =
useMembershipsProducts( true );
const hasPaidProducts = ( membershipsProducts?.length ?? 0 ) > 0;
// Show when products exist OR when we couldn't determine them (fetch error); stay hidden only
// while loading and on a genuinely empty site.
const canShowCompAction = hasPaidProducts || membershipsProductsError;
On the memo-dependency note: the previous dep list already included eslint + tsgo + the newsletter Jest suite pass. |
Part of #49485 - NL06
Proposed changes
On a site with no paid newsletter plans, the Subscribers tab no longer offers the "Comp a subscription" action. Previously the action appeared for any subscriber with a WordPress.com user id and then opened a modal that only reported "you don't have any paid plans" — a dead end.
useMembershipsProductshook, hoisted out of the Comp modal) and the action'sisEligibleis gated on whether any paid product exists. The per-row check reuses that single result, so no per-row network requests are introduced.Related product discussion/links
Does this pull request change what data or activity we track or use?
No. No new tracking. The same
useMembershipsProductsrequest that the Comp modal already made now also runs when the Subscribers table mounts (one extra fetch per page load on a connection-gated tab, deduped via the shared React Query cache the modal already used).Testing instructions
This change is on the modernized Subscribers dashboard, which is behind a feature flag and requires a WordPress.com connection (the membership-products request is proxied to WordPress.com), so it needs a connected newsletter site to verify the two states.
No paid plans (the fix):
With paid plans (unchanged):
No extra per-row requests:
memberships/productsrequest fires for the page (not one per row).