Skip to content

Conversation

sagzy
Copy link
Contributor

@sagzy sagzy commented Jul 31, 2025

ref https://linear.app/ghost/issue/BAE-494

  • Previously: given a Ghost site with e.g. a limit of 3 max. newsletters, a popup to upgrade would appear in the middle of creating newsletter 3
  • Now: the popup to upgrade only appears when attempting to add newsletter 4

ref https://linear.app/ghost/issue/BAE-494

- Previously: given a Ghost site with e.g. a limit of 3 max. newsletters, a popup to upgrade would appear in the middle of creating newsletter 3
- Now: the popup to upgrade only appears when attempting to add newsletter 4
@sagzy sagzy requested a review from aileen July 31, 2025 16:53
Copy link
Contributor

coderabbitai bot commented Jul 31, 2025

Walkthrough

The code modifies the newsletter creation modal component by introducing two new state variables: isCheckingLimit to track the loading state during the newsletter limit check, and limitError to store any errors related to exceeding the newsletter creation limit. The process for handling limit errors is refactored: error detection is separated from the UI response. The component now conditionally renders null while checking limits or when a limit error is present. Additionally, a new effect is added to handle the display of the limit modal and navigation updates when a limit error is detected.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 77433cc and 8da0623.

📒 Files selected for processing (1)
  • apps/admin-x-settings/src/components/settings/email/newsletters/AddNewsletterModal.tsx (3 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: kevinansfield
PR: TryGhost/Ghost#23770
File: apps/admin-x-settings/src/components/settings/email/newsletters/NewsletterDetailModalLabs.tsx:435-450
Timestamp: 2025-06-10T11:07:10.800Z
Learning: In Ghost's newsletter customization features, when promoting a feature from alpha to beta status, the feature flag guards are updated to make the feature available under both the `emailCustomization` (beta) and `emailCustomizationAlpha` (alpha) flags. This is done by either removing conditional guards entirely when the component is already behind both flags, or by updating conditionals to check for either flag.
📚 Learning: in ghost's newsletter customization features, when promoting a feature from alpha to beta status, th...
Learnt from: kevinansfield
PR: TryGhost/Ghost#23770
File: apps/admin-x-settings/src/components/settings/email/newsletters/NewsletterDetailModalLabs.tsx:435-450
Timestamp: 2025-06-10T11:07:10.800Z
Learning: In Ghost's newsletter customization features, when promoting a feature from alpha to beta status, the feature flag guards are updated to make the feature available under both the `emailCustomization` (beta) and `emailCustomizationAlpha` (alpha) flags. This is done by either removing conditional guards entirely when the component is already behind both flags, or by updating conditionals to check for either flag.

Applied to files:

  • apps/admin-x-settings/src/components/settings/email/newsletters/AddNewsletterModal.tsx
📚 Learning: the network component toggle in `apps/admin-x-settings/src/components/settings/growth/network.tsx` i...
Learnt from: sagzy
PR: TryGhost/Ghost#24346
File: apps/admin-x-settings/src/components/settings/growth/Network.tsx:8-12
Timestamp: 2025-07-14T12:20:35.268Z
Learning: The Network component toggle in `apps/admin-x-settings/src/components/settings/growth/Network.tsx` is intentionally implemented as static UI with a no-op onChange handler, as part of a UI-first development approach before connecting actual ActivityPub functionality.

Applied to files:

  • apps/admin-x-settings/src/components/settings/email/newsletters/AddNewsletterModal.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Setup
🔇 Additional comments (4)
apps/admin-x-settings/src/components/settings/email/newsletters/AddNewsletterModal.tsx (4)

2-2: LGTM! Proper state management setup.

The import of useState and initialization of the new state variables are correctly implemented. The isCheckingLimit starts as true to prevent premature modal display, and limitError is properly typed with HostLimitError | null.

Also applies to: 15-16


53-68: Excellent refactoring of limit checking logic.

The separation of limit detection from UI response is well-implemented:

  • Proper error type checking for HostLimitError
  • Appropriate re-throwing of unexpected errors
  • Loading state management prevents race conditions
  • Clean dependency array with only necessary dependencies

This approach ensures the limit check completes before any UI decisions are made.


72-81: Well-structured error handling effect.

The separation of UI response logic into its own effect is a good design choice:

  • Only executes when there's an actual limit error
  • Proper cleanup by removing modal and updating route
  • Complete dependency array prevents stale closures

This ensures the upgrade popup appears at the correct time - when the limit is actually exceeded rather than during the check.


83-85: Perfect fix for the premature popup issue.

The early return condition directly addresses the PR objective by preventing the modal from rendering:

  • While the limit check is in progress (isCheckingLimit)
  • When a limit error has been detected (limitError)

This ensures users only see the upgrade popup when they actually exceed the newsletter limit, not during the creation of the limit-approaching newsletter.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/upgrade-popup-on-newsletters

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Member

@aileen aileen left a comment

Choose a reason for hiding this comment

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

Looks good! Just needs the tests to pass now.

@sagzy sagzy merged commit bee785d into main Aug 4, 2025
22 checks passed
@sagzy sagzy deleted the fix/upgrade-popup-on-newsletters branch August 4, 2025 10:11
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