Skip to content

Upgrading from Hobby to Pro displays a dialog to confirm #1545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 13, 2024

Conversation

samejr
Copy link
Member

@samejr samejr commented Dec 10, 2024

If you click on the Upgrade to Pro button while on the Hobby tier, you will see this Dialog

CleanShot 2024-12-10 at 16 34 42@2x

This dialog doesn't appear if you click on "Upgrade to Pro" if you're on the Free tier.

Downgrading from any tier still functions the same.

Summary by CodeRabbit

  • New Features

    • Introduced dialogs for confirming upgrades and downgrades between subscription plans.
    • Enhanced user interface with interactive elements for subscription management.
    • Added a new Story component to showcase various spinner configurations.
  • Bug Fixes

    • Improved error handling for invalid plans and organization not found scenarios.
  • Style

    • Updated the visual representation of the Spinner component with new RGBA color configurations.
  • Chores

    • Added a new story entry for "Spinners" in the storybook.

Copy link

changeset-bot bot commented Dec 10, 2024

⚠️ No Changeset found

Latest commit: 34932c0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Dec 10, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/webapp/app/components/primitives/Spinner.tsx

Oops! Something went wrong! :(

ESLint: 8.45.0

ESLint couldn't find the config "custom" to extend from. Please check that the name of the config is correct.

The config "custom" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

Walkthrough

The changes in this pull request focus on enhancing the user interface and interaction logic within the select-plan.tsx file. Key modifications include the addition of the ArrowUpCircleIcon, the implementation of confirmation dialogs for upgrading and downgrading subscription plans, and conditional rendering of buttons based on the user's current subscription status. Error handling improvements are also noted, ensuring users receive appropriate feedback for invalid plans or organizations. Overall, these updates aim to improve the user experience related to subscription management.

Changes

File Path Change Summary
apps/webapp/app/routes/resources.orgs.$organizationSlug.select-plan.tsx - Added ArrowUpCircleIcon to imports.
- Updated TierPro, TierFree, and TierHobby components to include dialog handling for plan changes.
- Adjusted button rendering logic based on user subscription status.
- Refined error handling for invalid plans and organization not found scenarios.
apps/webapp/app/components/primitives/Spinner.tsx - Updated dark color configuration in Spinner component to use RGBA values instead of hex.
apps/webapp/app/routes/storybook.spinner/route.tsx - Introduced new Story component to render various spinner elements with different color configurations.
apps/webapp/app/routes/storybook/route.tsx - Added new story entry for "Spinners" in the stories array.

Possibly related PRs

  • New onboarding question #1404: The changes in this PR involve modifications to the feedback submission process, which is relevant to the user feedback handling improvements made in the main PR's select-plan.tsx file. Both PRs focus on enhancing user interactions and feedback mechanisms within the application.

Suggested reviewers

  • matt-aitken

Poem

In a world of plans both grand and small,
A dialog now greets you, one and all.
With arrows pointing up, your choice is clear,
Upgrade or downgrade, no need to fear!
So hop along, dear user, take your stand,
For managing subscriptions is now quite grand! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Experiment)
  • @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
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
apps/webapp/app/routes/resources.orgs.$organizationSlug.select-plan.tsx (1)

668-671: Consider enhancing the upgrade messaging with more details

The current message about pro-rata billing could be more specific to help users make an informed decision.

Consider adding:

  • Actual pro-rata calculation example
  • Specific billing date
  • Current vs. new plan feature comparison
-                    Are you sure you want to upgrade to the Pro plan? You will be charged the new
-                    plan price for the remainder of this month on a pro rata basis.
+                    Are you sure you want to upgrade to the Pro plan? You will be charged:
+                    • The new plan price (${plan.tierPrice}) prorated for the remaining days this month
+                    • Your next full billing cycle starts on [billing_date]
+                    
+                    You'll get immediate access to:
+                    • [List key Pro features not in Hobby]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 30ea5eb and 34085bf.

📒 Files selected for processing (1)
  • apps/webapp/app/routes/resources.orgs.$organizationSlug.select-plan.tsx (3 hunks)
🔇 Additional comments (3)
apps/webapp/app/routes/resources.orgs.$organizationSlug.select-plan.tsx (3)

8-8: LGTM!

The new icon import is consistent with the existing icon import pattern and is appropriately used in the upgrade dialog.


636-640: LGTM!

The dialog state management follows React best practices and maintains consistency with other tier components.


653-688: LGTM!

The upgrade dialog implementation is well-structured with:

  • Clear conditional rendering logic
  • Consistent dialog pattern usage
  • Appropriate loading states
  • Informative messaging about billing implications

: `Upgrade to ${plan.title}`}
</Button>
{subscription?.plan !== undefined &&
subscription?.plan?.title === "Hobby" &&
Copy link
Member

Choose a reason for hiding this comment

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

Instead of this, I'd do:
subscription?.plan?.type === "paid" &&

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
apps/webapp/app/routes/storybook/route.tsx (1)

Line range hint 1-1: ⚠️ Potential PR Scope Mismatch

While all the code changes related to the Spinner component are well-implemented, there appears to be a significant mismatch between:

  1. PR Objective: "Upgrading from Hobby to Pro displays a dialog to confirm"
  2. Actual Changes: Spinner component styling and Storybook documentation

Please verify if:

  • These changes were committed to the wrong PR
  • The PR description needs updating
  • The dialog-related changes are missing from the PR
apps/webapp/app/routes/resources.orgs.$organizationSlug.select-plan.tsx (3)

653-688: Consider extracting the plan comparison logic

The condition for showing the upgrade dialog is complex. Consider extracting it into a helper function for better readability.

+const shouldShowUpgradeDialog = (subscription: SubscriptionResult | undefined, planCode: string) => 
+  subscription?.plan !== undefined &&
+  subscription?.plan?.type === "paid" &&
+  subscription?.plan?.code !== planCode &&
+  subscription.canceledAt === undefined;

-{subscription?.plan !== undefined &&
-subscription?.plan?.type === "paid" &&
-subscription?.plan?.code !== plan.code &&
-subscription.canceledAt === undefined ? (
+{shouldShowUpgradeDialog(subscription, plan.code) ? (

669-672: Consider adding specific pricing information

The dialog message could be more helpful by including the specific price difference and pro-rata calculation.

-Are you sure you want to upgrade to the Pro plan? You will be charged the new
-plan price for the remainder of this month on a pro rata basis.
+Are you sure you want to upgrade to the Pro plan? You will be charged ${plan.tierPrice} 
+for the remainder of this month (pro-rated from your current ${subscription?.plan?.price}).

690-712: Enhance button accessibility and maintainability

Consider these improvements:

  1. Extract the button text logic to a helper function
  2. Add aria-label for better accessibility
+const getButtonText = (subscription: SubscriptionResult | undefined, planTitle: string) => {
+  if (!subscription?.plan) return "Select plan";
+  if (subscription.plan.type === "free" || subscription.canceledAt !== undefined)
+    return `Upgrade to ${planTitle}`;
+  return subscription.plan.code === plan.code ? "Current plan" : `Upgrade to ${planTitle}`;
+};

 <Button
   variant="tertiary/large"
   fullWidth
   form="subscribe-pro"
   className="text-md font-medium"
+  aria-label={`${getButtonText(subscription, plan.title)} button`}
   disabled={
     isLoading ||
     (subscription?.plan?.code === plan.code && subscription.canceledAt === undefined)
   }
   LeadingIcon={
     isLoading && navigation.formData?.get("planCode") === plan.code
       ? Spinner
       : undefined
   }
 >
-  {subscription?.plan === undefined
-    ? "Select plan"
-    : subscription.plan.type === "free" || subscription.canceledAt !== undefined
-    ? `Upgrade to ${plan.title}`
-    : subscription.plan.code === plan.code
-    ? "Current plan"
-    : `Upgrade to ${plan.title}`}
+  {getButtonText(subscription, plan.title)}
 </Button>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 34085bf and 34932c0.

📒 Files selected for processing (4)
  • apps/webapp/app/components/primitives/Spinner.tsx (1 hunks)
  • apps/webapp/app/routes/resources.orgs.$organizationSlug.select-plan.tsx (3 hunks)
  • apps/webapp/app/routes/storybook.spinner/route.tsx (1 hunks)
  • apps/webapp/app/routes/storybook/route.tsx (1 hunks)
🔇 Additional comments (5)
apps/webapp/app/routes/storybook.spinner/route.tsx (1)

1-28: LGTM! Well-structured Storybook story for Spinner component.

The implementation provides clear examples of all Spinner variants with appropriate styling and backgrounds. However, this change appears unrelated to the PR's objective of adding a confirmation dialog for Hobby to Pro tier upgrades.

Let's verify if these files are intended for this PR:

apps/webapp/app/components/primitives/Spinner.tsx (1)

29-30: LGTM! Color adjustments improve visibility.

The updated RGBA values for the dark variant provide better contrast while maintaining the component's aesthetic. However, like the previous file, this change appears unrelated to the PR's objective.

apps/webapp/app/routes/storybook/route.tsx (1)

87-90: LGTM! New Storybook entry follows established pattern.

The addition of the Spinners story is well-structured. However, I have concerns about the scope of this PR:

  1. The PR description indicates adding a confirmation dialog for Hobby to Pro tier upgrades
  2. The actual changes are related to Spinner component styling and documentation
  3. This suggests these changes might belong to a different PR

Let's verify the PR description and files:

apps/webapp/app/routes/resources.orgs.$organizationSlug.select-plan.tsx (2)

636-640: LGTM: Clean state management implementation

The dialog state management follows React best practices with proper state reset on subscription changes.


653-713: Verify the upgrade flow matches the requirements

The implementation successfully adds the confirmation dialog for upgrading from Hobby to Pro plan. Please verify:

  1. Dialog only appears when upgrading from Hobby to Pro
  2. Pro-rata pricing message is accurate
  3. Dialog doesn't appear for Free to Pro upgrades
✅ Verification successful

Implementation correctly handles plan upgrade scenarios

The verification confirms the implementation meets the requirements:

  1. The upgrade dialog appears only when:
    • Current plan is paid (Hobby)
    • Target plan code is different
    • Subscription is not canceled
  2. Pro-rata pricing message is unique to this dialog and consistent
  3. Dialog correctly doesn't appear for Free to Pro upgrades (handled in the else branch with direct button)
  4. All edge cases are properly handled:
    • Free plan upgrades
    • Canceled subscriptions
    • Current plan selection
    • Loading states
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the upgrade dialog implementation is consistent across the codebase

# Check if there are any other upgrade dialogs that might conflict
rg -A 5 "Upgrade plan\?" --type tsx

# Check for any other pro-rata pricing messages to ensure consistency
rg -A 5 "pro rata basis" --type tsx

Length of output: 131


Script:

#!/bin/bash
# Description: Verify the upgrade dialog implementation is consistent across the codebase

# Check if there are any other upgrade dialogs that might conflict
rg -A 5 "Upgrade plan\?"

# Check for any other pro-rata pricing messages to ensure consistency
rg -A 5 "pro rata basis"

# Check for other plan upgrade related code
rg -A 5 "Upgrade to.*plan"

Length of output: 5536


Script:

#!/bin/bash
# Let's verify the conditional logic for showing the dialog

# Check the conditions for when dialog appears
ast-grep --pattern 'subscription?.plan?.type === "paid"'

# Check for free plan type conditions
ast-grep --pattern 'subscription.plan.type === "free"'

# Look for canceledAt checks
ast-grep --pattern 'subscription.canceledAt'

Length of output: 3952

@matt-aitken matt-aitken merged commit c58f6f7 into main Dec 13, 2024
7 of 8 checks passed
@matt-aitken matt-aitken deleted the confirm-upgrade-to-pro branch December 13, 2024 11:14
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