feat: add upgrade banners for teams and organizations (#27650)
This commit is contained in:
1 parent
c197de147a
commit
b7340f7151
74 files changed
+1834
-500
No files matched your search
@@ -1,8 +1,3 @@
|
||||
import { LRUCache } from "lru-cache";
|
||||
import type { GetServerSidePropsContext, NextApiRequest } from "next";
|
||||
import type { AuthOptions, Session } from "next-auth";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
|
||||
import { LicenseKeySingleton } from "@calcom/ee/common/server/LicenseKeyService";
|
||||
import { DeploymentRepository } from "@calcom/features/ee/deployment/repositories/DeploymentRepository";
|
||||
import { UserRepository } from "@calcom/features/users/repositories/UserRepository";
|
||||
@@ -10,6 +5,10 @@ import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { LRUCache } from "lru-cache";
|
||||
import type { GetServerSidePropsContext, NextApiRequest } from "next";
|
||||
import type { AuthOptions, Session } from "next-auth";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["getServerSession"] });
|
||||
/**
|
||||
@@ -142,3 +141,7 @@ export async function getServerSession(options: {
|
||||
log.debug("Returned session", safeStringify(session));
|
||||
return session;
|
||||
}
|
||||
|
||||
export function clearSessionCache() {
|
||||
CACHE.clear();
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
import { randomBytes, createHash } from "node:crypto";
|
||||
import { totp } from "otplib";
|
||||
|
||||
import { createHash, randomBytes } from "node:crypto";
|
||||
import process from "node:process";
|
||||
import {
|
||||
sendChangeOfEmailVerificationLink,
|
||||
sendEmailVerificationCode,
|
||||
sendEmailVerificationLink,
|
||||
sendChangeOfEmailVerificationLink,
|
||||
} from "@calcom/emails/auth-email-service";
|
||||
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
|
||||
import { sentrySpan } from "@calcom/features/watchlist/lib/telemetry";
|
||||
@@ -12,9 +11,10 @@ import { checkIfEmailIsBlockedInWatchlistController } from "@calcom/features/wat
|
||||
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { hashEmail } from "@calcom/lib/server/PiiHasher";
|
||||
import { getTranslation } from "@calcom/i18n/server";
|
||||
import { hashEmail } from "@calcom/lib/server/PiiHasher";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { totp } from "otplib";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: [`[[Auth] `] });
|
||||
|
||||
@@ -25,6 +25,7 @@ interface VerifyEmailType {
|
||||
secondaryEmailId?: number;
|
||||
isVerifyingEmail?: boolean;
|
||||
isPlatform?: boolean;
|
||||
extraParams?: Record<string, string>;
|
||||
hideBranding?: boolean;
|
||||
}
|
||||
|
||||
@@ -34,6 +35,7 @@ export const sendEmailVerification = async ({
|
||||
username,
|
||||
secondaryEmailId,
|
||||
isPlatform = false,
|
||||
extraParams,
|
||||
}: VerifyEmailType) => {
|
||||
const token = randomBytes(32).toString("hex");
|
||||
const translation = await getTranslation(language ?? "en", "common");
|
||||
@@ -71,6 +73,7 @@ export const sendEmailVerification = async ({
|
||||
|
||||
const params = new URLSearchParams({
|
||||
token,
|
||||
...extraParams,
|
||||
});
|
||||
|
||||
await sendEmailVerificationLink({
|
||||
|
||||
@@ -33,3 +33,8 @@ export const PLATFORM_PLANS_MAP: Record<string, BillingPlan> = {
|
||||
|
||||
export const PLATFORM_ENTERPRISE_SLUGS = process.env.PLATFORM_ENTERPRISE_SLUGS?.split(",") ?? [];
|
||||
export const ENTERPRISE_SLUGS = process.env.ENTERPRISE_SLUGS?.split(",") ?? [];
|
||||
|
||||
export const BILLING_PRICING = {
|
||||
[BILLING_PLANS.TEAMS]: { monthly: 1600, annual: 1200 },
|
||||
[BILLING_PLANS.ORGANIZATIONS]: { monthly: 3700, annual: 2800 },
|
||||
} as const;
|
||||
@@ -0,0 +1,12 @@
|
||||
import { createContainer } from "@calcom/features/di/di";
|
||||
import type { BillingPeriodRepository } from "@calcom/features/ee/billing/repository/billingPeriod/BillingPeriodRepository";
|
||||
|
||||
import { billingPeriodRepositoryModuleLoader } from "../modules/BillingPeriodRepository";
|
||||
import { DI_TOKENS } from "../tokens";
|
||||
|
||||
const container = createContainer();
|
||||
|
||||
export function getBillingPeriodRepository(): BillingPeriodRepository {
|
||||
billingPeriodRepositoryModuleLoader.loadModule(container);
|
||||
return container.get<BillingPeriodRepository>(DI_TOKENS.BILLING_PERIOD_REPOSITORY);
|
||||
}
|
||||
@@ -87,6 +87,14 @@ export class BillingPeriodRepository {
|
||||
});
|
||||
}
|
||||
|
||||
async findBillingPeriodByTeamId(teamId: number): Promise<BillingPeriod | null> {
|
||||
const billing = await this.prisma.teamBilling.findFirst({
|
||||
where: { teamId },
|
||||
select: { billingPeriod: true },
|
||||
});
|
||||
return billing?.billingPeriod ?? null;
|
||||
}
|
||||
|
||||
async getTeamForBillingUpdate(teamId: number) {
|
||||
return await this.prisma.team.findUnique({
|
||||
where: { id: teamId },
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import process from "node:process";
|
||||
import { getBillingProviderService } from "@calcom/features/ee/billing/di/containers/Billing";
|
||||
import type { StripeBillingService } from "@calcom/features/ee/billing/service/billingProvider/StripeBillingService";
|
||||
import { getOrgPriceId } from "@calcom/features/ee/teams/lib/payments";
|
||||
import { OrganizationOnboardingRepository } from "@calcom/features/organizations/repositories/OrganizationOnboardingRepository";
|
||||
import { UserRepository } from "@calcom/features/users/repositories/UserRepository";
|
||||
import { ORGANIZATION_SELF_SERVE_PRICE, WEBAPP_URL, ORG_TRIAL_DAYS } from "@calcom/lib/constants";
|
||||
import { ORG_TRIAL_DAYS, ORGANIZATION_SELF_SERVE_PRICE, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { ErrorWithCode } from "@calcom/lib/errors";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { OrganizationOnboarding } from "@calcom/prisma/client";
|
||||
import { UserPermissionRole, type BillingPeriod } from "@calcom/prisma/enums";
|
||||
import { type BillingPeriod, UserPermissionRole } from "@calcom/prisma/enums";
|
||||
import { userMetadata } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import { OrganizationPermissionService } from "./OrganizationPermissionService";
|
||||
import type { OnboardingUser } from "./service/onboarding/types";
|
||||
|
||||
@@ -223,16 +224,7 @@ export class OrganizationPaymentService {
|
||||
throw new Error("STRIPE_ORG_PRODUCT_ID is not set");
|
||||
}
|
||||
|
||||
const fixedPriceId =
|
||||
config.billingPeriod === "ANNUALLY"
|
||||
? process.env.STRIPE_ORG_ANNUAL_PRICE_ID
|
||||
: process.env.STRIPE_ORG_MONTHLY_PRICE_ID;
|
||||
|
||||
if (!fixedPriceId) {
|
||||
const envVar =
|
||||
config.billingPeriod === "ANNUALLY" ? "STRIPE_ORG_ANNUAL_PRICE_ID" : "STRIPE_ORG_MONTHLY_PRICE_ID";
|
||||
throw new Error(`${envVar} is not set`);
|
||||
}
|
||||
const fixedPriceId = getOrgPriceId(config.billingPeriod);
|
||||
|
||||
if (!shouldCreateCustomPrice) {
|
||||
return {
|
||||
|
||||
@@ -58,19 +58,13 @@ export class OrganizationPermissionService {
|
||||
}
|
||||
|
||||
hasModifiedDefaultPayment(data: SeatsPrice & { billingPeriod?: string }): boolean {
|
||||
const isBillingPeriodModified =
|
||||
data.billingPeriod !== undefined && data.billingPeriod !== null && data.billingPeriod !== "MONTHLY";
|
||||
|
||||
const isPricePerSeatModified =
|
||||
data.pricePerSeat !== undefined &&
|
||||
data.pricePerSeat !== null &&
|
||||
data.pricePerSeat !== ORGANIZATION_SELF_SERVE_PRICE;
|
||||
|
||||
log.debug(
|
||||
"hasModifiedDefaultPayment",
|
||||
safeStringify({ isBillingPeriodModified, isPricePerSeatModified })
|
||||
);
|
||||
return isBillingPeriodModified || isPricePerSeatModified;
|
||||
log.debug("hasModifiedDefaultPayment", safeStringify({ isPricePerSeatModified }));
|
||||
return isPricePerSeatModified;
|
||||
}
|
||||
|
||||
async hasPermissionToMigrateTeams(teamIds: number[]): Promise<boolean> {
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
import type Stripe from "stripe";
|
||||
import { z } from "zod";
|
||||
|
||||
import process from "node:process";
|
||||
import { getStripeCustomerIdFromUserId } from "@calcom/app-store/stripepayment/lib/customer";
|
||||
import { getDubCustomer } from "@calcom/features/auth/lib/dub";
|
||||
import stripe from "@calcom/features/ee/payments/server/stripe";
|
||||
import { CHECKOUT_SESSION_TYPES } from "@calcom/features/ee/billing/constants";
|
||||
import stripe from "@calcom/features/ee/payments/server/stripe";
|
||||
import {
|
||||
IS_PRODUCTION,
|
||||
ORG_TRIAL_DAYS,
|
||||
ORGANIZATION_SELF_SERVE_PRICE,
|
||||
WEBAPP_URL,
|
||||
ORG_TRIAL_DAYS,
|
||||
} from "@calcom/lib/constants";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import type { TrackingData } from "@calcom/lib/tracking";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BillingPeriod } from "@calcom/prisma/zod-utils";
|
||||
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import { TrackingData } from "@calcom/lib/tracking";
|
||||
import { BillingPeriod, teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type Stripe from "stripe";
|
||||
import { z } from "zod";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["teams/lib/payments"] });
|
||||
const teamPaymentMetadataSchema = z.object({
|
||||
@@ -27,6 +26,21 @@ const teamPaymentMetadataSchema = z.object({
|
||||
orgSeats: teamMetadataSchema.unwrap().shape.orgSeats,
|
||||
});
|
||||
|
||||
export function getOrgPriceId(billingPeriod: "MONTHLY" | "ANNUALLY"): string {
|
||||
const priceId =
|
||||
billingPeriod === "ANNUALLY"
|
||||
? process.env.STRIPE_ORG_ANNUAL_PRICE_ID
|
||||
: process.env.STRIPE_ORG_MONTHLY_PRICE_ID;
|
||||
|
||||
if (!priceId) {
|
||||
const envVar =
|
||||
billingPeriod === "ANNUALLY" ? "STRIPE_ORG_ANNUAL_PRICE_ID" : "STRIPE_ORG_MONTHLY_PRICE_ID";
|
||||
throw new Error(`${envVar} is not set`);
|
||||
}
|
||||
|
||||
return priceId;
|
||||
}
|
||||
|
||||
/** Used to prevent double charges for the same team */
|
||||
export const checkIfTeamPaymentRequired = async ({ teamId = -1 }) => {
|
||||
const team = await prisma.team.findUniqueOrThrow({
|
||||
@@ -288,27 +302,20 @@ export const purchaseTeamOrOrgSubscription = async (input: {
|
||||
* If the organization has a custom price per seat, it will create a new price in stripe and return its ID.
|
||||
*/
|
||||
async function getFixedPrice() {
|
||||
const isAnnual = billingPeriod === "ANNUALLY";
|
||||
const fixedPriceId = isOrg
|
||||
? isAnnual
|
||||
? process.env.STRIPE_ORG_ANNUAL_PRICE_ID
|
||||
: process.env.STRIPE_ORG_MONTHLY_PRICE_ID
|
||||
: isAnnual
|
||||
? process.env.STRIPE_TEAM_ANNUAL_PRICE_ID
|
||||
: process.env.STRIPE_TEAM_MONTHLY_PRICE_ID;
|
||||
|
||||
if (!fixedPriceId) {
|
||||
const envVar = isOrg
|
||||
? isAnnual
|
||||
? "STRIPE_ORG_ANNUAL_PRICE_ID"
|
||||
: "STRIPE_ORG_MONTHLY_PRICE_ID"
|
||||
: isAnnual
|
||||
? "STRIPE_TEAM_ANNUAL_PRICE_ID"
|
||||
: "STRIPE_TEAM_MONTHLY_PRICE_ID";
|
||||
throw new Error(`Missing env var: ${envVar}`);
|
||||
if (isOrg) {
|
||||
const fixedPriceId = getOrgPriceId(billingPeriod);
|
||||
log.debug(
|
||||
"Getting price ID",
|
||||
safeStringify({ fixedPriceId, isOrg, teamId, pricePerSeat, billingPeriod })
|
||||
);
|
||||
return fixedPriceId;
|
||||
}
|
||||
|
||||
log.debug("Getting price ID", safeStringify({ fixedPriceId, isOrg, teamId, pricePerSeat, billingPeriod }));
|
||||
const fixedPriceId = getTeamPriceId(billingPeriod);
|
||||
log.debug(
|
||||
"Getting price ID",
|
||||
safeStringify({ fixedPriceId, isOrg, teamId, pricePerSeat, billingPeriod })
|
||||
);
|
||||
|
||||
return fixedPriceId;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import { Memoize, Unmemoize } from "@calcom/features/cache";
|
||||
import type { FeatureId } from "@calcom/features/flags/config";
|
||||
import type { FeatureDto } from "@calcom/lib/dto/FeatureDto";
|
||||
import { FeatureDtoArraySchema, FeatureDtoSchema } from "@calcom/lib/dto/FeatureDto";
|
||||
|
||||
import type { IFeatureRepository } from "./PrismaFeatureRepository";
|
||||
|
||||
const CACHE_PREFIX = "features:global";
|
||||
@@ -47,4 +46,20 @@ export class CachedFeatureRepository implements IFeatureRepository {
|
||||
const feature = await this.findBySlug(slug);
|
||||
return Boolean(feature && feature.enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a map of all feature flags and their enabled status.
|
||||
* Uses caching to avoid hitting the database on every request.
|
||||
* @returns Promise<AppFlags> - A map of feature flags to their enabled status
|
||||
*/
|
||||
public async getFeatureFlagMap() {
|
||||
const flags = await this.findAll();
|
||||
return flags.reduce(
|
||||
(acc, flag) => {
|
||||
acc[flag.slug as FeatureId] = flag.enabled;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, boolean>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ export interface IFeatureRepository {
|
||||
findBySlug(slug: string): Promise<FeatureDto | null>;
|
||||
update(input: { featureId: FeatureId; enabled: boolean; updatedBy?: number }): Promise<FeatureDto>;
|
||||
checkIfFeatureIsEnabledGlobally(slug: string): Promise<boolean>;
|
||||
getFeatureFlagMap(): Promise<Record<string, boolean>>;
|
||||
}
|
||||
|
||||
export class PrismaFeatureRepository implements IFeatureRepository {
|
||||
@@ -76,4 +77,15 @@ export class PrismaFeatureRepository implements IFeatureRepository {
|
||||
});
|
||||
return Boolean(feature?.enabled);
|
||||
}
|
||||
|
||||
async getFeatureFlagMap(): Promise<Record<string, boolean>> {
|
||||
const flags = await this.findAll();
|
||||
return flags.reduce(
|
||||
(acc, flag) => {
|
||||
acc[flag.slug as FeatureId] = flag.enabled;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, boolean>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -131,8 +131,8 @@ export class MembershipRepository {
|
||||
});
|
||||
}
|
||||
|
||||
static async findFirstAcceptedMembershipByUserId(userId: number) {
|
||||
return await prisma.membership.findFirst({
|
||||
static async hasAnyAcceptedMembershipByUserId(userId: number) {
|
||||
const membership = await prisma.membership.findFirst({
|
||||
where: {
|
||||
accepted: true,
|
||||
userId,
|
||||
@@ -142,7 +142,9 @@ export class MembershipRepository {
|
||||
},
|
||||
},
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
return Boolean(membership);
|
||||
}
|
||||
|
||||
static async findAcceptedMembershipsByUserIdsInTeam({
|
||||
|
||||
@@ -1173,6 +1173,11 @@
|
||||
"create_first_team_and_invite_others": "Create your first team and invite other users to work together.",
|
||||
"create_team_to_get_started": "Create a team to get started",
|
||||
"teams": "Teams",
|
||||
"upgrade_feature_round_robin": "Round-robin, fixed round-robin",
|
||||
"upgrade_feature_collective_events": "Collective events",
|
||||
"upgrade_feature_workflows": "Teams workflows",
|
||||
"upgrade_feature_insights": "Insights - analyze your booking data",
|
||||
"upgrade_feature_remove_branding": "Remove branding",
|
||||
"team": "Team",
|
||||
"organization": "Organization",
|
||||
"org": "Org",
|
||||
@@ -3341,6 +3346,7 @@
|
||||
"skip_contact_creation": "Skip creating contacts if they do not exist in {{appName}} ",
|
||||
"skip_writing_to_calendar_note": "If your ICS link is read-only (e.g., Proton Calendar), check the box above to avoid errors. You'll also need to manually update your calendar for changes.",
|
||||
"attributes": "Attributes",
|
||||
"attributes_description": "Manage attributes for your team members",
|
||||
"new_attribute": "New attribute",
|
||||
"add_attributes": "Add attributes",
|
||||
"add_attributes_description": "Add attributes to your team members",
|
||||
@@ -3875,6 +3881,10 @@
|
||||
"reschedule_cta_short": "Reschedule here.",
|
||||
"hide_organizer_email": "Hide organizer's email",
|
||||
"platform_customer_cant_create_organization": "You are already part of a platform organization which is why you can't create a new organization. Each user can only belong to one organization. Please, create a new cal.com account with a different email and use that account to subscribe to the organizations plan.",
|
||||
"org_requires_company_email": "Creating an organization requires a company email. Add your company email below to continue.",
|
||||
"org_company_email_verification_sent": "We sent a verification email to {{email}}. Click the link in the email to verify and continue setting up your organization.",
|
||||
"company_email": "Company email",
|
||||
"company_email_placeholder": "[email protected]",
|
||||
"organization_customer_cant_create_platform": "You are already part of an organization which is why you can't create a platform organization. Each user can only belong to one organization. Please, create a new cal.com account with a different email and use that account to subscribe to the platform plan.",
|
||||
"hide_organizer_email_description": "Hide organizer's email address from the booking screen, email notifications, and calendar events. <0>Learn more</0>",
|
||||
"you_and_conjunction": "You &",
|
||||
@@ -4660,6 +4670,55 @@
|
||||
"last_6_months": "Last 6 months",
|
||||
"last_12_months": "Last 12 months",
|
||||
"calendar_events_disabled_video_limitation": "When calendar events are disabled, meeting links cannot be generated for apps whose link generation is tied to calendar event creation, for example, Google Meet and Microsoft Teams. Other video apps like Cal Video will continue to work.",
|
||||
"upgrade_dialog_title_short": "Upgrade",
|
||||
"upgrade_dialog_title": "Upgrade plan",
|
||||
"upgrade_price_per_month_user": "per month/user",
|
||||
"upgrade_feature_everything_in_team": "Everything in Team",
|
||||
"upgrade_feature_verified_domain": "Verified domain",
|
||||
"upgrade_feature_directory_sync": "Directory sync (SCIM)",
|
||||
"upgrade_feature_sso": "SAML SSO",
|
||||
"upgrade_feature_admin_panel": "Admin panel",
|
||||
"upgrade_feature_everything_in_org": "Everything in Organization",
|
||||
"upgrade_feature_dedicated_support": "Dedicated support",
|
||||
"upgrade_feature_custom_sla": "Custom SLA",
|
||||
"upgrade_feature_custom_integrations": "Custom integrations",
|
||||
"upgrade_feature_compliance": "SOC2 & HIPAA compliance",
|
||||
"upgrade_badge_current_plan": "Current plan",
|
||||
"upgrade_billing_annual": "Annual",
|
||||
"upgrade_badge_free_trial": "14 day free trial",
|
||||
"upgrade_plan_team_tagline": "For growing teams",
|
||||
"upgrade_plan_org_tagline": "For scaling organizations",
|
||||
"upgrade_plan_enterprise_tagline": "For large enterprises",
|
||||
"upgrade_cta_teams": "Upgrade to Teams",
|
||||
"upgrade_cta_orgs": "Upgrade to Orgs",
|
||||
"upgrade_cta_enterprise": "Get in touch",
|
||||
"upgrade_info_team_insights_description": "Upgrade to surface all activity across your bookings pages",
|
||||
"orgs": "Orgs",
|
||||
"available_on": "Available on",
|
||||
"available_on_plan": "Available on {{plan}} plan",
|
||||
"upgrade_banner_roles_name": "Roles and Permissions",
|
||||
"upgrade_banner_roles_title": "Manage team access with roles and permissions",
|
||||
"upgrade_banner_roles_subtitle": "Give teammates the right level of access to events, settings, and scheduling.",
|
||||
"upgrade_banner_teams_name": "Teams",
|
||||
"upgrade_banner_teams_title": "Automatically route meetings to your team",
|
||||
"upgrade_banner_teams_subtitle": "Turn individual scheduling into a system that assigns, distributes, and manages meetings for our team.",
|
||||
"upgrade_banner_teams_feature1": "Route inbound requests to the right person",
|
||||
"upgrade_banner_teams_feature2": "Distribute meetings fairly with round-robin",
|
||||
"upgrade_banner_teams_feature3": "See what's getting booked (and what's not)",
|
||||
"upgrade_banner_teams_feature4": "Remove Cal.com branding",
|
||||
"upgrade_banner_insights_name": "Insights",
|
||||
"upgrade_banner_insights_title": "See what's getting booked, and what's not",
|
||||
"upgrade_banner_insights_subtitle": "Turn booking data into clarity for you and your team so you can spot gaps, balance workload, and make better scheduling decisions.",
|
||||
"upgrade_banner_insights_feature1": "Understand booking volume and cancellations",
|
||||
"upgrade_banner_insights_feature2": "See how meetings are distributed across team members",
|
||||
"upgrade_banner_insights_feature3": "Spot trends that help you improve availability and routing",
|
||||
"upgrade_banner_routing_form_name": "Routing",
|
||||
"upgrade_banner_routing_form_title": "Route bookings to the right team member automatically",
|
||||
"upgrade_banner_routing_form_subtitle": "Use routing rules to qualify bookers and assign meetings to the best team member.",
|
||||
"upgrade_banner_team_attributes_title": "Route meetings based on team member attributes",
|
||||
"upgrade_banner_team_attributes_subtitle": "Define attributes like role, region, or specialty and use them to route bookings to the right people automatically.",
|
||||
"play_video": "Play Video",
|
||||
"connected_accounts": "Connected accounts",
|
||||
"paypal": "PayPal",
|
||||
"paypal_getting_started": "Getting started with Paypal APP",
|
||||
"important_requirements": "Important requirements:",
|
||||
@@ -4681,5 +4740,6 @@
|
||||
"paypal_step_7": "You should be all set up after this.",
|
||||
"dashboard": "dashboard",
|
||||
"paypal_webhook_reminder": "Our integration creates a specific webhook on your PayPal account that we use to report back transactions to our system. If you delete this webhook, we will not be able to report back and you should uninstall and install the app again for this to work properly. Uninstalling the app won't delete your current event type price/currency configuration but you will not be able to receive bookings.",
|
||||
"discount_25": "-25%",
|
||||
"ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useEffect } from "react";
|
||||
|
||||
/**
|
||||
* Runs a callback once after hydration, on the client only.
|
||||
* Use this to defer browser-only logic (e.g. reading localStorage)
|
||||
* and avoid SSR hydration mismatches.
|
||||
*/
|
||||
export function useClientOnly(callback: () => void) {
|
||||
useEffect(callback, []);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { useLayoutEffect, useRef } from "react";
|
||||
|
||||
export function useFillRemainingHeight<T extends HTMLElement = HTMLDivElement>(offset = 0) {
|
||||
const ref = useRef<T>(null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const el = ref.current;
|
||||
if (!el) return;
|
||||
|
||||
const update = () => {
|
||||
const top = Math.round(el.getBoundingClientRect().top + offset);
|
||||
const newHeight = `calc(100dvh - ${top}px)`;
|
||||
if (el.style.height !== newHeight) {
|
||||
el.style.height = newHeight;
|
||||
}
|
||||
};
|
||||
|
||||
update();
|
||||
|
||||
const observer = new ResizeObserver(update);
|
||||
observer.observe(document.body);
|
||||
|
||||
return () => observer.disconnect();
|
||||
}, [offset]);
|
||||
|
||||
return ref;
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { getFeatureRepository } from "@calcom/features/di/containers/FeatureRepository";
|
||||
import publicProcedure from "@calcom/trpc/server/procedures/publicProcedure";
|
||||
|
||||
/**
|
||||
* TRPC procedure that returns a map of all feature flags and their enabled status.
|
||||
* Uses the FeaturesRepository to handle caching and database access.
|
||||
* Uses the CachedFeatureRepository to handle caching and database access.
|
||||
*/
|
||||
export const map = publicProcedure.query(async () => {
|
||||
const featuresRepository = new FeaturesRepository(prisma);
|
||||
const featuresRepository = getFeatureRepository();
|
||||
return featuresRepository.getFeatureFlagMap();
|
||||
});
|
||||
@@ -1,12 +1,9 @@
|
||||
import type { GetServerSidePropsContext, NextApiResponse } from "next";
|
||||
|
||||
import { sendEmailVerification } from "@calcom/features/auth/lib/verifyEmail";
|
||||
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { GetServerSidePropsContext, NextApiResponse } from "next";
|
||||
import type { TAddSecondaryEmailInputSchema } from "./addSecondaryEmail.schema";
|
||||
|
||||
type AddSecondaryEmailOptions = {
|
||||
@@ -46,14 +43,25 @@ export const addSecondaryEmailHandler = async ({ ctx, input }: AddSecondaryEmail
|
||||
}
|
||||
|
||||
const updatedData = await prisma.secondaryEmail.create({
|
||||
data: { ...input, userId: user.id },
|
||||
data: { email: input.email, userId: user.id },
|
||||
});
|
||||
|
||||
const extraParams: Record<string, string> = {};
|
||||
if (input.makePrimary) {
|
||||
extraParams.makePrimary = "true";
|
||||
}
|
||||
if (input.redirectTo) {
|
||||
extraParams.redirectTo = input.redirectTo;
|
||||
}
|
||||
|
||||
const hasExtraParams = Object.keys(extraParams).length > 0;
|
||||
|
||||
await sendEmailVerification({
|
||||
email: updatedData.email,
|
||||
username: user?.username ?? undefined,
|
||||
language: user.locale,
|
||||
secondaryEmailId: updatedData.id,
|
||||
...(hasExtraParams && { extraParams }),
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -2,8 +2,12 @@ import { z } from "zod";
|
||||
|
||||
export type TAddSecondaryEmailInputSchema = {
|
||||
email: string;
|
||||
makePrimary?: boolean;
|
||||
redirectTo?: string;
|
||||
};
|
||||
|
||||
export const ZAddSecondaryEmailInputSchema: z.ZodType<TAddSecondaryEmailInputSchema> = z.object({
|
||||
email: z.string(),
|
||||
makePrimary: z.boolean().optional(),
|
||||
redirectTo: z.string().optional(),
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import { getTeamBillingServiceFactory } from "@calcom/ee/billing/di/containers/Billing";
|
||||
import { SubscriptionStatus } from "@calcom/ee/billing/repository/billing/IBillingRepository";
|
||||
import { getBillingPeriodRepository } from "@calcom/features/ee/billing/di/containers/BillingPeriodRepository";
|
||||
import { MembershipRepository } from "@calcom/features/membership/repositories/MembershipRepository";
|
||||
import { IS_SELF_HOSTED } from "@calcom/lib/constants";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
@@ -16,7 +17,8 @@ type HasActiveTeamPlanOptions = {
|
||||
};
|
||||
|
||||
export const hasActiveTeamPlanHandler = async ({ ctx, input }: HasActiveTeamPlanOptions) => {
|
||||
if (IS_SELF_HOSTED) return { isActive: true, isTrial: false };
|
||||
const billingPeriodRepository = getBillingPeriodRepository();
|
||||
if (IS_SELF_HOSTED) return { isActive: true, isTrial: false, billingPeriod: null };
|
||||
|
||||
const whereClause: Prisma.MembershipWhereInput = { userId: ctx.user.id, accepted: true };
|
||||
|
||||
@@ -26,15 +28,16 @@ export const hasActiveTeamPlanHandler = async ({ ctx, input }: HasActiveTeamPlan
|
||||
|
||||
const teams = await MembershipRepository.findAllAcceptedTeamMemberships(ctx.user.id, whereClause);
|
||||
|
||||
if (!teams.length) return { isActive: false, isTrial: false };
|
||||
if (!teams.length) return { isActive: false, isTrial: false, billingPeriod: null };
|
||||
|
||||
let isTrial = false;
|
||||
// check if user has at least on membership with an active plan
|
||||
let relevantTeamId: number | null = null;
|
||||
// check if user has at least one membership with an active plan
|
||||
for (const team of teams) {
|
||||
if (team.isPlatform && team.isOrganization) {
|
||||
const platformBilling = await prisma.platformBilling.findUnique({ where: { id: team.id } });
|
||||
if (platformBilling && platformBilling.plan !== "none" && platformBilling.plan !== "FREE") {
|
||||
return { isActive: true, isTrial: false };
|
||||
return { isActive: true, isTrial: false, billingPeriod: await billingPeriodRepository.findBillingPeriodByTeamId(team.id) };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,14 +50,19 @@ export const hasActiveTeamPlanHandler = async ({ ctx, input }: HasActiveTeamPlan
|
||||
subscriptionStatus === SubscriptionStatus.ACTIVE ||
|
||||
subscriptionStatus === SubscriptionStatus.PAST_DUE
|
||||
) {
|
||||
return { isActive: true, isTrial: false };
|
||||
return { isActive: true, isTrial: false, billingPeriod: await billingPeriodRepository.findBillingPeriodByTeamId(team.id) };
|
||||
}
|
||||
if (subscriptionStatus === SubscriptionStatus.TRIALING) {
|
||||
isTrial = true;
|
||||
relevantTeamId = team.id;
|
||||
}
|
||||
}
|
||||
|
||||
return { isActive: false, isTrial };
|
||||
const billingPeriod = relevantTeamId
|
||||
? await billingPeriodRepository.findBillingPeriodByTeamId(relevantTeamId)
|
||||
: null;
|
||||
|
||||
return { isActive: false, isTrial, billingPeriod };
|
||||
};
|
||||
|
||||
export default hasActiveTeamPlanHandler;
|
||||
Reference in new issue
Block a user