fix: disable custom templates for free plan (#18635)
* add upgrade badge * adjust update handler * code clean up * clean up template code * only handle email templates * fixes * code clean up * fix workflow template zod type --------- Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
7 files changed
+114
-17
No files matched your search
@@ -12,7 +12,7 @@ import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
import type { MultiSelectCheckboxesOptionType as Option } from "@calcom/ui";
|
||||
import { Button, Icon, Label, MultiSelectCheckboxes, TextField, CheckboxField, InfoBadge } from "@calcom/ui";
|
||||
|
||||
import { isSMSAction, isWhatsappAction } from "../lib/actionHelperFunctions";
|
||||
import { isSMSAction } from "../lib/actionHelperFunctions";
|
||||
import type { FormValues } from "../pages/workflow";
|
||||
import { AddActionDialog } from "./AddActionDialog";
|
||||
import { DeleteDialog } from "./DeleteDialog";
|
||||
@@ -83,7 +83,7 @@ export default function WorkflowDetailsPage(props: Props) {
|
||||
workflowId: workflowId,
|
||||
reminderBody: null,
|
||||
emailSubject: null,
|
||||
template: isWhatsappAction(action) ? WorkflowTemplates.REMINDER : WorkflowTemplates.CUSTOM,
|
||||
template: WorkflowTemplates.REMINDER,
|
||||
numberRequired: numberRequired || false,
|
||||
sender: isSMSAction(action) ? sender || SENDER_ID : SENDER_ID,
|
||||
senderName: !isSMSAction(action) ? senderName || SENDER_NAME : SENDER_NAME,
|
||||
|
||||
@@ -8,6 +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 { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
||||
@@ -84,6 +85,8 @@ 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 },
|
||||
@@ -129,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);
|
||||
const templateOptions = getWorkflowTemplateOptions(t, step?.action, hasPaidPlan);
|
||||
|
||||
if (step && form.getValues(`steps.${step.stepNumber - 1}.template`) === WorkflowTemplates.REMINDER) {
|
||||
if (!form.getValues(`steps.${step.stepNumber - 1}.reminderBody`)) {
|
||||
@@ -370,7 +373,11 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
needsTeamsUpgrade: false,
|
||||
};
|
||||
|
||||
const selectedTemplate = { label: t(`${step.template.toLowerCase()}`), value: step.template };
|
||||
const selectedTemplate = {
|
||||
label: t(`${step.template.toLowerCase()}`),
|
||||
value: step.template,
|
||||
needsTeamsUpgrade: false,
|
||||
};
|
||||
|
||||
const canRequirePhoneNumber = (workflowStep: string) => {
|
||||
return (
|
||||
@@ -879,6 +886,11 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
defaultValue={selectedTemplate}
|
||||
value={selectedTemplate}
|
||||
options={templateOptions}
|
||||
isOptionDisabled={(option: {
|
||||
label: string;
|
||||
value: any;
|
||||
needsTeamsUpgrade: boolean;
|
||||
}) => option.needsTeamsUpgrade}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
@@ -906,7 +918,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
refEmailSubject.current = e;
|
||||
}}
|
||||
rows={1}
|
||||
disabled={props.readOnly}
|
||||
disabled={props.readOnly || !hasPaidPlan}
|
||||
className="my-0 focus:ring-transparent"
|
||||
required
|
||||
{...restEmailSubjectForm}
|
||||
@@ -939,7 +951,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
updateTemplate={updateTemplate}
|
||||
firstRender={firstRender}
|
||||
setFirstRender={setFirstRender}
|
||||
editable={!props.readOnly && !isWhatsappAction(step.action)}
|
||||
editable={!props.readOnly && !isWhatsappAction(step.action) && hasPaidPlan}
|
||||
excludedToolbarItems={
|
||||
!isSMSAction(step.action) ? [] : ["blockType", "bold", "italic", "link"]
|
||||
}
|
||||
|
||||
@@ -30,6 +30,14 @@ export function isSMSOrWhatsappAction(action: WorkflowActions) {
|
||||
return isSMSAction(action) || isWhatsappAction(action);
|
||||
}
|
||||
|
||||
export function isEmailAction(action: WorkflowActions) {
|
||||
return (
|
||||
action === WorkflowActions.EMAIL_ADDRESS ||
|
||||
action === WorkflowActions.EMAIL_ATTENDEE ||
|
||||
action === WorkflowActions.EMAIL_HOST
|
||||
);
|
||||
}
|
||||
|
||||
export function isAttendeeAction(action: WorkflowActions) {
|
||||
return (
|
||||
action === WorkflowActions.SMS_ATTENDEE ||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { TFunction } from "next-i18next";
|
||||
|
||||
import type { WorkflowActions } from "@calcom/prisma/enums";
|
||||
import { WorkflowTriggerEvents } from "@calcom/prisma/enums";
|
||||
import { WorkflowTemplates, WorkflowTriggerEvents } from "@calcom/prisma/enums";
|
||||
|
||||
import { isSMSOrWhatsappAction, isWhatsappAction, isEmailToAttendeeAction } from "./actionHelperFunctions";
|
||||
import {
|
||||
@@ -39,7 +39,11 @@ export function getWorkflowTriggerOptions(t: TFunction) {
|
||||
});
|
||||
}
|
||||
|
||||
export function getWorkflowTemplateOptions(t: TFunction, action: WorkflowActions | undefined) {
|
||||
export function getWorkflowTemplateOptions(
|
||||
t: TFunction,
|
||||
action: WorkflowActions | undefined,
|
||||
hasPaidPlan: boolean
|
||||
) {
|
||||
const TEMPLATES =
|
||||
action && isWhatsappAction(action)
|
||||
? WHATSAPP_WORKFLOW_TEMPLATES
|
||||
@@ -47,6 +51,10 @@ export function getWorkflowTemplateOptions(t: TFunction, action: WorkflowActions
|
||||
? ATTENDEE_WORKFLOW_TEMPLATES
|
||||
: BASIC_WORKFLOW_TEMPLATES;
|
||||
return TEMPLATES.map((template) => {
|
||||
return { label: t(`${template.toLowerCase()}`), value: template };
|
||||
}) as { label: string; value: any }[];
|
||||
return {
|
||||
label: t(`${template.toLowerCase()}`),
|
||||
value: template,
|
||||
needsTeamsUpgrade: !hasPaidPlan && template == WorkflowTemplates.CUSTOM,
|
||||
};
|
||||
}) as { label: string; value: any; needsTeamsUpgrade: boolean }[];
|
||||
}
|
||||
Reference in new issue
Block a user