-
Notifications
You must be signed in to change notification settings - Fork 11.6k
feat: adds user plan info in useHasPaidPlan for intercom
#23790
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
Changes from all commits
b8ac087
334776a
fd3c728
80bbb8a
c5deba2
2e22d69
58e511f
af95218
0fd6370
ae1ff8f
06ebb5c
e8f1316
1970c05
36072d6
7d6f050
7e224a2
4f950f2
3184309
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,79 @@ | ||||||||||||
| import { | ||||||||||||
| BillingPlan, | ||||||||||||
| ENTERPRISE_SLUGS, | ||||||||||||
| PLATFORM_ENTERPRISE_SLUGS, | ||||||||||||
| PLATFORM_PLANS_MAP, | ||||||||||||
| } from "@calcom/features/ee/billing/constants"; | ||||||||||||
| import { teamMetadataStrictSchema } from "@calcom/prisma/zod-utils"; | ||||||||||||
| import type { JsonValue } from "@calcom/types/Json"; | ||||||||||||
|
|
||||||||||||
| export class BillingPlanService { | ||||||||||||
| async getUserPlanByMemberships( | ||||||||||||
| memberships: { | ||||||||||||
| team: { | ||||||||||||
| isOrganization: boolean; | ||||||||||||
| isPlatform: boolean; | ||||||||||||
| slug: string | null; | ||||||||||||
| metadata: JsonValue; | ||||||||||||
| parent: { | ||||||||||||
| isOrganization: boolean; | ||||||||||||
| slug: string | null; | ||||||||||||
| isPlatform: boolean; | ||||||||||||
| metadata: JsonValue; | ||||||||||||
| } | null; | ||||||||||||
| platformBilling: { | ||||||||||||
| plan: string; | ||||||||||||
| } | null; | ||||||||||||
| }; | ||||||||||||
| user: { | ||||||||||||
| isPlatformManaged: boolean; | ||||||||||||
| }; | ||||||||||||
| }[] | ||||||||||||
| ) { | ||||||||||||
| if (memberships.length === 0) return BillingPlan.INDIVIDUALS; | ||||||||||||
|
|
||||||||||||
| for (const { team, user } of memberships) { | ||||||||||||
| if (team.isPlatform || user.isPlatformManaged) { | ||||||||||||
| if (PLATFORM_ENTERPRISE_SLUGS.includes(team.slug ?? "")) return BillingPlan.PLATFORM_ENTERPRISE; | ||||||||||||
| if (!team.platformBilling) continue; | ||||||||||||
|
|
||||||||||||
| return PLATFORM_PLANS_MAP[team.platformBilling.plan] ?? team.platformBilling.plan; | ||||||||||||
| } else { | ||||||||||||
|
Comment on lines
+40
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep return type strictly BillingPlan (don’t return raw strings) Fallback currently returns a string which breaks type guarantees and can leak unknown values downstream. Apply this diff: - return PLATFORM_PLANS_MAP[team.platformBilling.plan] ?? team.platformBilling.plan;
+ const planKey = team.platformBilling.plan?.toUpperCase?.() ?? "";
+ return PLATFORM_PLANS_MAP[planKey] ?? BillingPlan.UNKNOWN;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| let teamMetadata; | ||||||||||||
| try { | ||||||||||||
| teamMetadata = teamMetadataStrictSchema.parse(team.metadata ?? {}); | ||||||||||||
| } catch { | ||||||||||||
| teamMetadata = null; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| let parentTeamMetadata; | ||||||||||||
| try { | ||||||||||||
| parentTeamMetadata = teamMetadataStrictSchema.parse(team.parent?.metadata ?? {}); | ||||||||||||
| } catch { | ||||||||||||
| parentTeamMetadata = null; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if ( | ||||||||||||
| team.parent && | ||||||||||||
| team.parent.isOrganization && | ||||||||||||
| parentTeamMetadata?.subscriptionId && | ||||||||||||
| !team.parent.isPlatform | ||||||||||||
| ) { | ||||||||||||
| return ENTERPRISE_SLUGS.includes(team.parent.slug ?? "") | ||||||||||||
| ? BillingPlan.ENTERPRISE | ||||||||||||
| : BillingPlan.ORGANIZATIONS; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (!teamMetadata?.subscriptionId) continue; | ||||||||||||
| if (team.isOrganization) { | ||||||||||||
| return ENTERPRISE_SLUGS.includes(team.slug ?? "") | ||||||||||||
| ? BillingPlan.ENTERPRISE | ||||||||||||
| : BillingPlan.ORGANIZATIONS; | ||||||||||||
| } else { | ||||||||||||
| return BillingPlan.TEAMS; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| return BillingPlan.UNKNOWN; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
Uh oh!
There was an error while loading. Please reload this page.