* fix trpc session circle dep * fixes trpc session cirlce dep * fix relative imports * fix more imports to use types and not trpc * fix exports * Fixed types --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com>
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { getWorkflowActionOptions } from "@calcom/features/ee/workflows/lib/getOptions";
|
|
import { IS_SELF_HOSTED } from "@calcom/lib/constants";
|
|
import hasKeyInMetadata from "@calcom/lib/hasKeyInMetadata";
|
|
import { getTranslation } from "@calcom/lib/server/i18n";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
|
|
|
import hasActiveTeamPlanHandler from "../teams/hasActiveTeamPlan.handler";
|
|
|
|
type GetWorkflowActionOptionsOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser> & {
|
|
locale: string;
|
|
};
|
|
};
|
|
};
|
|
|
|
export const getWorkflowActionOptionsHandler = async ({ ctx }: GetWorkflowActionOptionsOptions) => {
|
|
const { user } = ctx;
|
|
|
|
const isCurrentUsernamePremium =
|
|
user && hasKeyInMetadata(user, "isPremium") ? !!user.metadata.isPremium : false;
|
|
|
|
let teamsPlan = { isActive: false, isTrial: false };
|
|
if (!isCurrentUsernamePremium) {
|
|
teamsPlan = await hasActiveTeamPlanHandler({ ctx });
|
|
}
|
|
|
|
const hasOrgsPlan = !!user.profile?.organizationId;
|
|
|
|
const t = await getTranslation(ctx.user.locale, "common");
|
|
return getWorkflowActionOptions(
|
|
t,
|
|
IS_SELF_HOSTED || isCurrentUsernamePremium || teamsPlan.isActive,
|
|
IS_SELF_HOSTED || hasOrgsPlan
|
|
);
|
|
};
|