disable guests field when offer seats is enabled (#10132)

Co-authored-by: rkreddy99 <rreddy@e2clouds.com>
This commit is contained in:
Rama Krishna Reddy
2023-07-13 13:57:30 +02:00
committed by GitHub
co-authored by rkreddy99
parent 0093b6faa5
commit 26afc077a7
3 changed files with 8 additions and 9 deletions
@@ -5,6 +5,7 @@ import { useEffect, useState } from "react";
import { Controller, useFormContext } from "react-hook-form";
import short from "short-uuid";
import { v5 as uuidv5 } from "uuid";
import { z } from "zod";
import type { EventNameObjectType } from "@calcom/core/event";
import { getEventName } from "@calcom/core/event";
@@ -16,6 +17,7 @@ import {
allowDisablingHostConfirmationEmails,
} from "@calcom/features/ee/workflows/lib/allowDisablingStandardEmails";
import { FormBuilder } from "@calcom/features/form-builder/FormBuilder";
import { EditableSchema } from "@calcom/features/form-builder/FormBuilderFieldsSchema"
import { BookerLayoutSelector } from "@calcom/features/settings/BookerLayoutSelector";
import { classNames } from "@calcom/lib";
import { APP_NAME, CAL_URL } from "@calcom/lib/constants";
@@ -85,6 +87,7 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
return {
...field,
hidden: !enabled,
editable: (!enabled ? "system-but-hidden" : "system-but-optional") as z.infer<typeof EditableSchema>
};
}
return field;
@@ -299,8 +299,9 @@ export const FormBuilder = function FormBuilder({
const fieldType = FieldTypesMap[field.type];
const isRequired = field.required;
const isFieldEditableSystemButOptional = field.editable === "system-but-optional";
const isFieldEditableSystemButHidden = field.editable === "system-but-hidden";
const isFieldEditableSystem = field.editable === "system";
const isUserField = !isFieldEditableSystem && !isFieldEditableSystemButOptional;
const isUserField = !isFieldEditableSystem && !isFieldEditableSystemButOptional && !isFieldEditableSystemButHidden;
if (!fieldType) {
throw new Error(`Invalid field type - ${field.type}`);
@@ -368,7 +369,7 @@ export const FormBuilder = function FormBuilder({
</div>
{field.editable !== "user-readonly" && !disabled && (
<div className="flex items-center space-x-2">
{!isFieldEditableSystem && !disabled && (
{!isFieldEditableSystem && !isFieldEditableSystemButHidden && !disabled && (
<Switch
data-testid="toggle-field"
disabled={isFieldEditableSystem}
@@ -20,6 +20,7 @@ const fieldTypeEnum = z.enum([
export const EditableSchema = z.enum([
"system", // Can't be deleted, can't be hidden, name can't be edited, can't be marked optional
"system-but-optional", // Can't be deleted. Name can't be edited. But can be hidden or be marked optional
"system-but-hidden", // Can't be deleted, name can't be edited, will be shown
"user", // Fully editable
"user-readonly", // All fields are readOnly.
]);
@@ -70,13 +71,7 @@ const fieldSchema = z.object({
required: z.boolean().default(false).optional(),
hidden: z.boolean().optional(),
editable: z
.enum([
"system", // Can't be deleted, can't be hidden, name can't be edited, can't be marked optional
"system-but-optional", // Can't be deleted. Name can't be edited. But can be hidden or be marked optional
"user", // Fully editable
"user-readonly", // All fields are readOnly.
])
editable: EditableSchema
.default("user")
.optional(),
sources: z