fix: Disable custom templates for trialing teams (#18748)

* Create `checkIfTeamHasActivePlan` method on `stripe-billing-service`

* Add `checkIfTeamPlanIsActive` to `InternalTeamBilling`

* Create `hasActiveTeamPlan` trpc endpoint

* Check for active team plan when updating workflows

* Create `useHasActiveTeamPlan` hook

* Use `useHasActiveTeamPlan` on workflow edit page

* Type fixes

* Type fix

* Add `accepted` to team query
This commit is contained in:
Joe Au-Yeung authored and GitHub committed 2025-01-20 14:48:33 +00:00
1 parent 7131a1f015
commit d6306dcd22
9 files changed
+88 -9

No files matched your search

@@ -7,4 +7,5 @@ export interface BillingService {
subscriptionItemId: string;
membershipCount: number;
}): Promise<void>;
checkIfTeamHasActivePlan(subscriptionId: string): Promise<boolean>;
}
@@ -30,4 +30,10 @@ export class StripeBillingService implements BillingService {
const checkoutSession = await this.stripe.checkout.sessions.retrieve(paymentId);
return checkoutSession.payment_status === "paid";
}
async checkIfTeamHasActivePlan(subscriptionId: string) {
const subscription = await this.stripe.subscriptions.retrieve(subscriptionId);
if (!subscription || !subscription.status) return false;
return subscription.status === "active";
}
}
@@ -161,4 +161,10 @@ export class InternalTeamBilling implements TeamBilling {
paymentRequired: false,
};
}
/** Used to check if the current team plan is active */
async checkIfTeamHasActivePlan() {
const { subscriptionId } = this.team.metadata;
if (!subscriptionId) return false;
return billing.checkIfTeamHasActivePlan(subscriptionId);
}
}
@@ -8,7 +8,7 @@ import "react-phone-number-input/style.css";
import { classNames } from "@calcom/lib";
import { SENDER_ID, SENDER_NAME } from "@calcom/lib/constants";
import useHasPaidPlan from "@calcom/lib/hooks/useHasPaidPlan";
import { useHasActiveTeamPlan } from "@calcom/lib/hooks/useHasPaidPlan";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { HttpError } from "@calcom/lib/http-error";
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
@@ -85,14 +85,14 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
const { t, i18n } = useLocale();
const utils = trpc.useUtils();
const { hasPaidPlan } = useHasPaidPlan();
const { step, form, reload, setReload, teamId } = props;
const { data: _verifiedNumbers } = trpc.viewer.workflows.getVerifiedNumbers.useQuery(
{ teamId },
{ enabled: !!teamId }
);
const { hasActiveTeamPlan } = useHasActiveTeamPlan(teamId);
const { data: _verifiedEmails } = trpc.viewer.workflows.getVerifiedEmails.useQuery({ teamId });
const timeFormat = getTimeFormatStringFromUserTimeFormat(props.user.timeFormat);
@@ -132,7 +132,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
const { data: actionOptions } = trpc.viewer.workflows.getWorkflowActionOptions.useQuery();
const triggerOptions = getWorkflowTriggerOptions(t);
const templateOptions = getWorkflowTemplateOptions(t, step?.action, hasPaidPlan);
const templateOptions = getWorkflowTemplateOptions(t, step?.action, hasActiveTeamPlan);
if (step && form.getValues(`steps.${step.stepNumber - 1}.template`) === WorkflowTemplates.REMINDER) {
if (!form.getValues(`steps.${step.stepNumber - 1}.reminderBody`)) {
@@ -918,7 +918,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
refEmailSubject.current = e;
}}
rows={1}
disabled={props.readOnly || !hasPaidPlan}
disabled={props.readOnly || !hasActiveTeamPlan}
className="my-0 focus:ring-transparent"
required
{...restEmailSubjectForm}
@@ -951,7 +951,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
updateTemplate={updateTemplate}
firstRender={firstRender}
setFirstRender={setFirstRender}
editable={!props.readOnly && !isWhatsappAction(step.action) && hasPaidPlan}
editable={!props.readOnly && !isWhatsappAction(step.action) && hasActiveTeamPlan}
excludedToolbarItems={
!isSMSAction(step.action) ? [] : ["blockType", "bold", "italic", "link"]
}