add-on-codes.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import { PaidSubscription } from '../../../../../types/subscription/dashboard/subscription'
  2. import { PendingPaymentProviderPlan } from '../../../../../types/subscription/plan'
  3. export const AI_ASSIST_STANDALONE_MONTHLY_PLAN_CODE = 'assistant'
  4. export const AI_ADD_ON_CODE = 'assistant'
  5. // we dont want translations on plan or add-on names
  6. export const ADD_ON_NAME = 'AI Assist'
  7. export const AI_ASSIST_STANDALONE_ANNUAL_PLAN_CODE = 'assistant-annual'
  8. export function isStandaloneAiPlanCode(planCode?: string) {
  9. return (
  10. planCode === AI_ASSIST_STANDALONE_MONTHLY_PLAN_CODE ||
  11. planCode === AI_ASSIST_STANDALONE_ANNUAL_PLAN_CODE
  12. )
  13. }
  14. export function hasPendingAiAddonCancellation(subscription: PaidSubscription) {
  15. const pendingPlan = subscription.pendingPlan as PendingPaymentProviderPlan
  16. const hasAiAddon = subscription.addOns?.some(
  17. addOn => addOn.addOnCode === AI_ADD_ON_CODE
  18. )
  19. // cancellation of entire plan counts as removing the add-on
  20. if (hasAiAddon && !pendingPlan) {
  21. return true
  22. }
  23. return (
  24. hasAiAddon &&
  25. !pendingPlan.addOns?.some(addOn => addOn.code === AI_ADD_ON_CODE)
  26. )
  27. }