make SMS available for all users again (#5656)

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
Co-authored-by: Omar López <zomars@me.com>
pull/5592/head^2
Carina Wollendorfer 2022-11-23 23:42:42 +01:00 committed by GitHub
parent 38d8852819
commit e3a7fd006b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 40 deletions

View File

@ -29,7 +29,6 @@ interface IAddActionDialog {
isOpenDialog: boolean;
setIsOpenDialog: Dispatch<SetStateAction<boolean>>;
addAction: (action: WorkflowActions, sendTo?: string, numberRequired?: boolean, sender?: string) => void;
isFreeUser: boolean;
}
interface ISelectActionOption {
@ -44,20 +43,13 @@ type AddActionFormValues = {
sender?: string;
};
const cleanUpActionsForFreeUser = (actions: ISelectActionOption[]) => {
return actions.filter(
(item) => item.value !== WorkflowActions.SMS_ATTENDEE && item.value !== WorkflowActions.SMS_NUMBER
);
};
export const AddActionDialog = (props: IAddActionDialog) => {
const { t } = useLocale();
const { isOpenDialog, setIsOpenDialog, addAction, isFreeUser } = props;
const { isOpenDialog, setIsOpenDialog, addAction } = props;
const [isPhoneNumberNeeded, setIsPhoneNumberNeeded] = useState(false);
const [isSenderIdNeeded, setIsSenderIdNeeded] = useState(false);
const [isEmailAddressNeeded, setIsEmailAddressNeeded] = useState(false);
const workflowActions = getWorkflowActionOptions(t);
const actionOptions = isFreeUser ? cleanUpActionsForFreeUser(workflowActions) : workflowActions;
const actionOptions = getWorkflowActionOptions(t);
const formSchema = z.object({
action: z.enum(WORKFLOW_ACTIONS),

View File

@ -28,9 +28,6 @@ export default function WorkflowDetailsPage(props: Props) {
const { t } = useLocale();
const router = useRouter();
const me = useMeQuery();
const isFreeUser = me.data?.plan === "FREE";
const [isAddActionDialogOpen, setIsAddActionDialogOpen] = useState(false);
const [reload, setReload] = useState(false);
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
@ -124,7 +121,7 @@ export default function WorkflowDetailsPage(props: Props) {
<div className="w-full rounded-md border border-gray-200 bg-gray-50 p-3 py-5 md:ml-3 md:p-8">
{form.getValues("trigger") && (
<div>
<WorkflowStepContainer form={form} isFreeUser={isFreeUser} />
<WorkflowStepContainer form={form} />
</div>
)}
{form.getValues("steps") && (
@ -137,7 +134,6 @@ export default function WorkflowDetailsPage(props: Props) {
step={step}
reload={reload}
setReload={setReload}
isFreeUser={isFreeUser}
/>
);
})}
@ -147,7 +143,11 @@ export default function WorkflowDetailsPage(props: Props) {
<Icon.FiArrowDown className="stroke-[1.5px] text-3xl text-gray-500" />
</div>
<div className="flex justify-center">
<Button type="button" onClick={() => setIsAddActionDialogOpen(true)} color="secondary">
<Button
type="button"
onClick={() => setIsAddActionDialogOpen(true)}
color="secondary"
className="bg-white">
{t("add_action")}
</Button>
</div>
@ -157,7 +157,6 @@ export default function WorkflowDetailsPage(props: Props) {
isOpenDialog={isAddActionDialogOpen}
setIsOpenDialog={setIsAddActionDialogOpen}
addAction={addAction}
isFreeUser={isFreeUser}
/>
<DeleteDialog
isOpenDialog={deleteDialogOpen}

View File

@ -48,12 +48,11 @@ type WorkflowStepProps = {
form: UseFormReturn<FormValues>;
reload?: boolean;
setReload?: Dispatch<SetStateAction<boolean>>;
isFreeUser: boolean;
};
export default function WorkflowStepContainer(props: WorkflowStepProps) {
const { t, i18n } = useLocale();
const { step, form, reload, setReload, isFreeUser } = props;
const { step, form, reload, setReload } = props;
const [isAdditionalInputsDialogOpen, setIsAdditionalInputsDialogOpen] = useState(false);
const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false);
@ -324,15 +323,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
}
}}
defaultValue={selectedAction}
options={
isFreeUser
? actionOptions.filter(
(actionOption) =>
actionOption.value !== WorkflowActions.SMS_ATTENDEE &&
actionOption.value !== WorkflowActions.SMS_NUMBER
)
: actionOptions
}
options={actionOptions}
/>
);
}}

View File

@ -32,12 +32,6 @@ import { TRPCError } from "@trpc/server";
import { router, authedProcedure } from "../../trpc";
function isSMSAction(action: WorkflowActions) {
if (action === WorkflowActions.SMS_ATTENDEE || action === WorkflowActions.SMS_NUMBER) {
return true;
}
}
export const workflowsRouter = router({
list: authedProcedure.query(async ({ ctx }) => {
const workflows = await ctx.prisma.workflow.findMany({
@ -524,9 +518,6 @@ export const workflowsRouter = router({
});
//step was edited
} else if (JSON.stringify(oldStep) !== JSON.stringify(newStep)) {
if (user.plan === "FREE" && !isSMSAction(oldStep.action) && isSMSAction(newStep.action)) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
await ctx.prisma.workflowStep.update({
where: {
id: oldStep.id,
@ -666,9 +657,6 @@ export const workflowsRouter = router({
//added steps
const addedSteps = steps.map((s) => {
if (s.id <= 0) {
if (user.plan === "FREE" && isSMSAction(s.action)) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
const { id: stepId, ...stepToAdd } = s;
return stepToAdd;
}