fix: add badge for disabled workflow actions and templates in trial mode (#19675)

* add badge for trial mode

* fix tooltip issue

* fix typo

* add inactive team plan badge

* change to one salesforce request

* clean up

* fix type error

---------

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: Bailey Pumfleet <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-03-10 15:34:29 +01:00
1 parent bb36807689
commit f2ca2bdc83
10 files changed
+61 -33

No files matched your search

@@ -10,7 +10,8 @@ type HasActiveTeamPlanOptions = {
};
export const hasActiveTeamPlanHandler = async ({ ctx }: HasActiveTeamPlanOptions) => {
if (IS_SELF_HOSTED) return true;
if (IS_SELF_HOSTED) return { isActive: true, isTrial: false };
const teams = await prisma.team.findMany({
where: {
members: {
@@ -22,18 +23,23 @@ export const hasActiveTeamPlanHandler = async ({ ctx }: HasActiveTeamPlanOptions
},
});
if (!teams.length) return false;
if (!teams.length) return { isActive: false, isTrial: false };
let isTrial = false;
// check if user has at least on membership with an active plan
for (const team of teams) {
const teamBillingService = new InternalTeamBilling(team);
const isPlanActive = await teamBillingService.checkIfTeamHasActivePlan();
if (isPlanActive) {
return true;
const subscriptionStatus = await teamBillingService.getSubscriptionStatus();
if (subscriptionStatus === "active" || subscriptionStatus === "past_due") {
return { isActive: true, isTrial: false };
}
if (subscriptionStatus === "trialing") {
isTrial = true;
}
}
return false;
return { isActive: false, isTrial };
};
export default hasActiveTeamPlanHandler;
@@ -20,9 +20,9 @@ export const getWorkflowActionOptionsHandler = async ({ ctx }: GetWorkflowAction
const isCurrentUsernamePremium =
user && hasKeyInMetadata(user, "isPremium") ? !!user.metadata.isPremium : false;
let isTeamsPlan = false;
let teamsPlan = { isActive: false, isTrial: false };
if (!isCurrentUsernamePremium) {
isTeamsPlan = await hasActiveTeamPlanHandler({ ctx });
teamsPlan = await hasActiveTeamPlanHandler({ ctx });
}
const hasOrgsPlan = !!user.profile?.organizationId;
@@ -30,7 +30,7 @@ export const getWorkflowActionOptionsHandler = async ({ ctx }: GetWorkflowAction
const t = await getTranslation(ctx.user.locale, "common");
return getWorkflowActionOptions(
t,
IS_SELF_HOSTED || isCurrentUsernamePremium || isTeamsPlan,
IS_SELF_HOSTED || isCurrentUsernamePremium || teamsPlan.isActive,
IS_SELF_HOSTED || hasOrgsPlan
);
};
@@ -80,14 +80,11 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
const isCurrentUsernamePremium = hasKeyInMetadata(user, "isPremium") ? !!user.metadata.isPremium : false;
let isTeamsPlan = false;
let teamsPlan = { isActive: false, isTrial: false };
if (!isCurrentUsernamePremium) {
isTeamsPlan = await hasActiveTeamPlanHandler({
ctx,
});
teamsPlan = await hasActiveTeamPlanHandler({ ctx });
}
const hasPaidPlan = IS_SELF_HOSTED || isCurrentUsernamePremium || isTeamsPlan;
const hasPaidPlan = IS_SELF_HOSTED || isCurrentUsernamePremium || teamsPlan.isActive;
let newActiveOn: number[] = [];
let removedActiveOnIds: number[] = [];