Skip to content

The open alternative to Salesforce, designed for AI.

684 B
Raw Blame
import { findOrThrow } from 'twenty-shared/utils';
import { usePlans } from './usePlans';

export const usePlanByPriceId = () => {
  const { listPlans } = usePlans();

  const getPlanByPriceId = (priceId: string) =>
    findOrThrow(
      listPlans(),
      (plan) =>
        plan.baseProducts.some((p) =>
          p.prices?.some((price) => price.stripePriceId === priceId),
        ) ||
        plan.resourceCreditProducts.some((p) =>
          p.prices?.some((price) => price.stripePriceId === priceId),
        ) ||
        plan.meteredProducts.some((p) =>
          p.prices?.some((price) => price.stripePriceId === priceId),
        ),
    );

  return { getPlanByPriceId };
};