Skip to content

refactor: extract pricing calculation into shared utility #42

@coderabbitai

Description

@coderabbitai

Context

Currently, pricing calculation logic is implemented directly in the PricingCards component. This logic should be shared between the web and mkt packages to ensure consistency.

Current Implementation

const basePrice = 49;
const discount = isYearly ? 0.8 : 1;
const pricePerExtraContributor = 7 * discount;
const discountedPrice = Math.floor(basePrice * discount);
const extraContributors = Math.max(contributors - 5, 0);
const totalPrice = discountedPrice + extraContributors * pricePerExtraContributor;

Proposed Solution

Extract the pricing calculation into a shared utility that can be consumed by both packages:

interface PricingOptions {
  contributors: number;
  isYearly: boolean;
}

export function calculatePrice({ contributors, isYearly }: PricingOptions) {
  const basePrice = 49;
  const discount = isYearly ? 0.8 : 1;
  const pricePerExtraContributor = 7 * discount;
  const discountedPrice = Math.floor(basePrice * discount);
  const extraContributors = Math.max(contributors - 5, 0);
  return discountedPrice + extraContributors * pricePerExtraContributor;
}

References

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions