Skip to content

Commit

Permalink
Fixes SMS actions and cal.com branding for premium plan (#7306)
Browse files Browse the repository at this point in the history
* enable sms actions with premium user name

* allow hide branding when user has premium user name

---------

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
  • Loading branch information
CarinaWolli and CarinaWolli authored Feb 23, 2023
1 parent 3206e4e commit ba86e7f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions apps/web/lib/isBrandingHidden.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isBrandingHidden(hideBrandingSetting: boolean, belongsToActiveTeam: boolean) {
return belongsToActiveTeam && hideBrandingSetting;
export function isBrandingHidden(hideBrandingSetting: boolean, hasPaidPlan: boolean) {
return hasPaidPlan && hideBrandingSetting;
}
8 changes: 6 additions & 2 deletions apps/web/pages/[user]/[type].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from "zod";

import type { LocationObject } from "@calcom/app-store/locations";
import { IS_TEAM_BILLING_ENABLED, WEBAPP_URL } from "@calcom/lib/constants";
import hasKeyInMetadata from "@calcom/lib/hasKeyInMetadata";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import type { User } from "@calcom/prisma/client";

Expand Down Expand Up @@ -82,6 +83,7 @@ async function getUserPageProps(context: GetStaticPropsContext) {
weekStart: true,
brandColor: true,
darkBrandColor: true,
metadata: true,
eventTypes: {
where: {
// Many-to-many relationship causes inclusion of the team events - cool -
Expand Down Expand Up @@ -157,7 +159,7 @@ async function getUserPageProps(context: GetStaticPropsContext) {
locations: privacyFilteredLocations(locations),
descriptionAsSafeHTML: eventType.description ? md.render(eventType.description) : null,
});
// Check if the user you are logging into has any active teams
// Check if the user you are logging into has any active teams or premium user name
const hasActiveTeam =
user.teams.filter((m) => {
if (!IS_TEAM_BILLING_ENABLED) return true;
Expand All @@ -166,6 +168,8 @@ async function getUserPageProps(context: GetStaticPropsContext) {
return false;
}).length > 0;

const hasPremiumUserName = hasKeyInMetadata(user, "isPremium");

return {
props: {
eventType: eventTypeObject,
Expand All @@ -182,7 +186,7 @@ async function getUserPageProps(context: GetStaticPropsContext) {
away: user?.away,
isDynamic: false,
trpcState: ssg.dehydrate(),
isBrandingHidden: isBrandingHidden(user.hideBranding, hasActiveTeam),
isBrandingHidden: isBrandingHidden(user.hideBranding, hasActiveTeam || hasPremiumUserName),
},
revalidate: 10, // seconds
};
Expand Down
18 changes: 13 additions & 5 deletions packages/trpc/server/routers/viewer/workflows.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { PrismaPromise } from "@prisma/client";
import {
PrismaPromise,
WorkflowTemplates,
WorkflowActions,
WorkflowTriggerEvents,
BookingStatus,
WorkflowMethods,
TimeUnit,
Prisma
} from "@prisma/client";
import { z } from "zod";

Expand All @@ -33,6 +32,7 @@ import {
} from "@calcom/features/ee/workflows/lib/reminders/verifyPhoneNumber";
import { IS_SELF_HOSTED, SENDER_ID } from "@calcom/lib/constants";
import { SENDER_NAME } from "@calcom/lib/constants";
import hasKeyInMetadata from "@calcom/lib/hasKeyInMetadata";
// import { getErrorFromUnknown } from "@calcom/lib/errors";
import { getTranslation } from "@calcom/lib/server/i18n";
import type { WorkflowStep } from "@calcom/prisma/client";
Expand Down Expand Up @@ -947,7 +947,7 @@ evt = {
attendees: [{ name: "John Doe", email: "john.doe@example.com", timeZone: "Europe/London" }],
organizer: {
language: {
locale: ctx.user.locale,
locale: ctx.user.locale,
},
name: ctx.user.name || "",
email: ctx.user.email,
Expand Down Expand Up @@ -1102,8 +1102,16 @@ action === WorkflowActions.EMAIL_ADDRESS*/
return verifiedNumbers;
}),
getWorkflowActionOptions: authedProcedure.query(async ({ ctx }) => {
const { hasTeamPlan } = await viewerTeamsRouter.createCaller(ctx).hasTeamPlan();
const { user } = ctx;

const isCurrentUsernamePremium = user && user.metadata && hasKeyInMetadata(user, "isPremium");

let isTeamsPlan = false;
if (!isCurrentUsernamePremium) {
const { hasTeamPlan } = await viewerTeamsRouter.createCaller(ctx).hasTeamPlan();
isTeamsPlan = !!hasTeamPlan;
}
const t = await getTranslation(ctx.user.locale, "common");
return getWorkflowActionOptions(t, IS_SELF_HOSTED || !!hasTeamPlan);
return getWorkflowActionOptions(t, IS_SELF_HOSTED || isCurrentUsernamePremium || isTeamsPlan);
}),
});

0 comments on commit ba86e7f

Please sign in to comment.