Skip to content

Team pricing#5

Merged
AnthonyRonning merged 1 commit intomasterfrom
team-pricing
Jan 31, 2025
Merged

Team pricing#5
AnthonyRonning merged 1 commit intomasterfrom
team-pricing

Conversation

@AnthonyRonning
Copy link
Contributor

@AnthonyRonning AnthonyRonning commented Jan 29, 2025

Summary by CodeRabbit

  • New Features

    • Added a new method to check team plan availability.
    • Enhanced pricing page with team plan availability checks.
    • Updated pricing page layout to support a four-column grid.
  • Bug Fixes

    • Improved button text and interaction for unavailable team plans.
    • Added redirection for unavailable team plan selection.
  • Documentation

    • Clarified billing details for the team plan, especially for Bitcoin users.

@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

This pull request introduces a new feature to check team plan availability across the billing system. The changes span three files in the frontend: billingApi.ts, billingService.ts, and pricing.tsx. A new asynchronous function is added to fetch team plan availability, integrated into the billing service, and then utilized in the pricing page to dynamically adjust the user interface and button interactions based on the plan's availability.

Changes

File Change Summary
frontend/src/billing/billingApi.ts Added fetchTeamPlanAvailable async function to check team plan availability via API
frontend/src/billing/billingService.ts Added getTeamPlanAvailable method to BillingService class, importing fetchTeamPlanAvailable
frontend/src/routes/pricing.tsx Updated PricingPage with new query to check team plan availability, modified button text and click handling logic

Possibly related PRs

Poem

🐰 A rabbit's tale of billing's might,
Team plans now shine so crystal bright!
With tokens checked and buttons smart,
Our pricing page has found its art.
Hop along, dear user friend! 🌟


🪧 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. (Beta)
  • @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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 29, 2025

Deploying maple with  Cloudflare Pages  Cloudflare Pages

Latest commit: 521a2fa
Status: ✅  Deploy successful!
Preview URL: https://0decc4c5.maple-ca8.pages.dev
Branch Preview URL: https://team-pricing.maple-ca8.pages.dev

View logs

@AnthonyRonning AnthonyRonning force-pushed the team-pricing branch 3 times, most recently from a78fcc0 to 799d55b Compare January 30, 2025 22:35
@AnthonyRonning AnthonyRonning marked this pull request as ready for review January 30, 2025 22:35
Copy link

@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

🧹 Nitpick comments (3)
frontend/src/billing/billingApi.ts (1)

183-210: Enhance error handling specificity.

While the error handling is consistent with other API functions, consider providing more specific error messages for different failure scenarios.

Apply this diff to improve error messages:

   if (!response.ok) {
     const errorText = await response.text();
     console.error("Team plan availability error response:", errorText);
     if (response.status === 401) {
       throw new Error("Unauthorized");
+    } else if (response.status === 404) {
+      throw new Error("Team plan availability endpoint not found");
+    } else if (response.status === 503) {
+      throw new Error("Team plan availability service is temporarily unavailable");
     }
     throw new Error(`Failed to check team plan availability: ${errorText}`);
   }
frontend/src/routes/pricing.tsx (2)

270-270: Extract email address to a constant.

The support email address should be extracted to a constant to maintain consistency and ease updates.

Add this at the top of the file:

+const SUPPORT_EMAIL = "support@opensecret.cloud";

Then update the usage:

-      window.location.href = "mailto:support@opensecret.cloud";
+      window.location.href = `mailto:${SUPPORT_EMAIL}`;

Line range hint 439-474: Extract price calculation logic.

The yearly Bitcoin price calculation logic should be extracted into a separate function for better maintainability.

Consider adding this utility function:

const calculatePrices = (product: BillingProduct, useBitcoin: boolean) => {
  const monthlyOriginalPrice = (product.default_price.unit_amount / 100).toFixed(2);
  const monthlyDiscountedPrice = (
    Math.floor(product.default_price.unit_amount / 2) / 100
  ).toFixed(2);
  
  // Calculate yearly prices for Bitcoin (10% off)
  const yearlyDiscountedPrice = (
    Math.floor(product.default_price.unit_amount * 12 * 0.9) / 100
  ).toFixed(2);
  
  // Calculate monthly equivalent of yearly Bitcoin price
  const monthlyEquivalentPrice = (Number(yearlyDiscountedPrice) / 12).toFixed(2);
  
  return {
    displayOriginalPrice: monthlyOriginalPrice,
    displayDiscountedPrice: useBitcoin ? monthlyEquivalentPrice : monthlyDiscountedPrice,
    yearlyDiscountedPrice
  };
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0d09dc5 and 799d55b.

📒 Files selected for processing (3)
  • frontend/src/billing/billingApi.ts (1 hunks)
  • frontend/src/billing/billingService.ts (2 hunks)
  • frontend/src/routes/pricing.tsx (11 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (4)
frontend/src/billing/billingService.ts (2)

9-10: LGTM: Clean import addition.

The import statement for fetchTeamPlanAvailable is properly added.


95-97: LGTM: Well-implemented service method.

The getTeamPlanAvailable method follows the established pattern of using executeWithToken for authentication and proper error handling.

frontend/src/routes/pricing.tsx (2)

164-178: LGTM: Well-implemented team plan availability check.

The query is properly implemented with error handling and fallback to false on error.


558-565: LGTM: Proper button state handling.

The button state properly handles both loading and Bitcoin payment restrictions for team plans.

Copy link

@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: 1

🧹 Nitpick comments (4)
frontend/src/routes/pricing.tsx (4)

265-273: Extract support email as a constant.

The support email address is duplicated. Consider extracting it to a constant at the top of the file to maintain DRY principles and make updates easier.

+const SUPPORT_EMAIL = "support@opensecret.cloud";
+
 function PricingPage() {
   // ... existing code ...
   
   // For team plan, redirect to email if not available
   if (isTeamPlan && !isTeamPlanAvailable) {
-    window.location.href = "mailto:support@opensecret.cloud";
+    window.location.href = `mailto:${SUPPORT_EMAIL}`;
     return;
   }

360-361: Extract grid layout class for reusability.

The grid layout class is duplicated across loading, error, and main states. Consider extracting it to a constant or CSS class for better maintainability.

+const PRICING_GRID_CLASS = "w-full max-w-7xl mx-auto grid grid-cols-1 md:grid-cols-4 gap-4 md:gap-4 lg:gap-6 px-4 sm:px-6 lg:px-8";
+
 // In loading state
-<div className="pt-8 w-full max-w-7xl mx-auto grid grid-cols-1 md:grid-cols-4 gap-4 md:gap-4 lg:gap-6 px-4 sm:px-6 lg:px-8">
+<div className={`pt-8 ${PRICING_GRID_CLASS}`}>

 // In error state
-<div className="pt-8 w-full grid grid-cols-1 md:grid-cols-4 gap-4 md:gap-4 lg:gap-6 px-4 sm:px-6 lg:px-8">
+<div className={`pt-8 ${PRICING_GRID_CLASS}`}>

 // In main state
-<div className="pt-8 w-full max-w-7xl mx-auto grid grid-cols-1 md:grid-cols-4 gap-4 md:gap-4 lg:gap-6 px-4 sm:px-6 lg:px-8">
+<div className={`pt-8 ${PRICING_GRID_CLASS}`}>

Also applies to: 385-385, 440-440


Line range hint 449-519: Improve readability of pricing display logic.

The pricing display logic uses complex nested ternaries and has magic numbers. Consider these improvements:

  1. Extract discount percentages as constants.
  2. Split the complex conditional rendering into separate components or functions.
+const BITCOIN_DISCOUNT = 0.9; // 10% off
+const REGULAR_DISCOUNT = 0.5; // 50% off
+
+const getPricingDisplay = (product, useBitcoin) => {
+  if (product.name === "Team" && useBitcoin) {
+    return "Team plan is not available with Bitcoin payment.";
+  }
+  return product.description;
+};
+
 // In the component
-{product.name === "Team" && useBitcoin
-  ? "Team plan is not available with Bitcoin payment."
-  : product.description}
+{getPricingDisplay(product, useBitcoin)}

559-570: Simplify button state handling.

The button state logic is complex with multiple conditions. Consider extracting the logic into helper functions for better readability and maintainability.

+const isButtonDisabled = (productId, loadingProductId, isTeamPlan, useBitcoin) => {
+  return loadingProductId === productId || (useBitcoin && isTeamPlan);
+};
+
+const getButtonClassName = (isTeamPlan, isTeamPlanAvailable, baseClassName) => {
+  return `${baseClassName} ${
+    isTeamPlan && !isTeamPlanAvailable
+      ? "!opacity-100 !cursor-pointer hover:!bg-white/70"
+      : ""
+  }`;
+};
+
 <button
   onClick={() => handleButtonClick(product)}
-  disabled={loadingProductId === product.id || (useBitcoin && product.name === "Team")}
-  className={`w-full bg-white/90 backdrop-blur-sm text-black hover:bg-white/70 active:bg-white/80 px-4 sm:px-8 py-3 sm:py-4 rounded-lg text-lg sm:text-xl font-light transition-all duration-200 shadow-[0_0_25px_rgba(255,255,255,0.25)] hover:shadow-[0_0_35px_rgba(255,255,255,0.35)] disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2 group-hover:bg-white ${
-    isTeamPlan && !isTeamPlanAvailable ? "!opacity-100 !cursor-pointer hover:!bg-white/70" : ""
-  }`}
+  disabled={isButtonDisabled(product.id, loadingProductId, isTeamPlan, useBitcoin)}
+  className={getButtonClassName(
+    isTeamPlan,
+    isTeamPlanAvailable,
+    "w-full bg-white/90 backdrop-blur-sm text-black hover:bg-white/70 active:bg-white/80 px-4 sm:px-8 py-3 sm:py-4 rounded-lg text-lg sm:text-xl font-light transition-all duration-200 shadow-[0_0_25px_rgba(255,255,255,0.25)] hover:shadow-[0_0_35px_rgba(255,255,255,0.35)] disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2 group-hover:bg-white"
+  )}
>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 799d55b and dbcee4d.

📒 Files selected for processing (3)
  • frontend/src/billing/billingApi.ts (1 hunks)
  • frontend/src/billing/billingService.ts (2 hunks)
  • frontend/src/routes/pricing.tsx (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/src/billing/billingApi.ts
  • frontend/src/billing/billingService.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (1)
frontend/src/routes/pricing.tsx (1)

214-225: LGTM! Clear and consistent button text logic.

The implementation correctly handles the team plan button text, maintaining consistency with the existing pattern.

Copy link

@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

🧹 Nitpick comments (3)
frontend/src/routes/pricing.tsx (3)

449-449: Refactor price calculations into a separate utility function.

The price calculations are duplicated across the component. Consider extracting them into a reusable utility function.

+const calculatePrices = (product: any, useBitcoin: boolean) => {
+  const monthlyOriginalPrice = (product.default_price.unit_amount / 100).toFixed(2);
+  const monthlyDiscountedPrice = (Math.floor(product.default_price.unit_amount / 2) / 100).toFixed(2);
+  const yearlyDiscountedPrice = (Math.floor(product.default_price.unit_amount * 12 * 0.9) / 100).toFixed(2);
+  const monthlyEquivalentPrice = (Number(yearlyDiscountedPrice) / 12).toFixed(2);
+
+  return {
+    displayOriginalPrice: monthlyOriginalPrice,
+    displayDiscountedPrice: useBitcoin ? monthlyEquivalentPrice : monthlyDiscountedPrice,
+    yearlyDiscountedPrice,
+  };
+};

Also applies to: 451-458


559-566: Add ARIA attributes for better accessibility.

The disabled state and pricing information should be properly conveyed to screen readers.

 <button
   onClick={() => handleButtonClick(product)}
   disabled={loadingProductId === product.id || (useBitcoin && product.name === "Team")}
+  aria-disabled={loadingProductId === product.id || (useBitcoin && product.name === "Team")}
+  aria-label={`${product.name} plan - ${getButtonText(product)}`}
   className={`w-full bg-white/90 backdrop-blur-sm text-black hover:bg-white/70...`}
 >

214-214: Add type safety for product name checks.

Consider using an enum or constant for product names to avoid typos and improve maintainability.

+const PRODUCT_NAMES = {
+  TEAM: 'team',
+  FREE: 'free',
+} as const;
+
-const isTeamPlan = targetPlanName.includes("team");
+const isTeamPlan = targetPlanName.includes(PRODUCT_NAMES.TEAM);

Also applies to: 265-266

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dbcee4d and 521a2fa.

📒 Files selected for processing (3)
  • frontend/src/billing/billingApi.ts (1 hunks)
  • frontend/src/billing/billingService.ts (2 hunks)
  • frontend/src/routes/pricing.tsx (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/src/billing/billingApi.ts
  • frontend/src/billing/billingService.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (1)
frontend/src/routes/pricing.tsx (1)

164-177: Enhance error handling for team plan availability check.

The current implementation silently fails and defaults to false, which might hide actual issues.

@AnthonyRonning AnthonyRonning merged commit 25689d0 into master Jan 31, 2025
2 checks passed
@AnthonyRonning AnthonyRonning deleted the team-pricing branch January 31, 2025 19:39
@coderabbitai coderabbitai bot mentioned this pull request Mar 2, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jul 1, 2025
@coderabbitai coderabbitai bot mentioned this pull request Aug 26, 2025
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.

1 participant