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,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