feat: Booker atom read only fields (#16904)
* refactor: include user-readonly in BookingFields * feat: add read only name and email booking fields * feat: Booker atom prop for read only name and email * refactor: simplify props type
This commit is contained in:
1 parent
ba5b9e951a
commit
b0bfec7247
4 files changed
+61
-12
No files matched your search
@@ -62,6 +62,10 @@ export type BookerPlatformWrapperAtomProps = Omit<
|
||||
notes?: string;
|
||||
rescheduleReason?: string;
|
||||
} & Record<string, string | string[]>;
|
||||
readOnlyFormValues?: {
|
||||
name?: boolean;
|
||||
email?: boolean;
|
||||
};
|
||||
handleCreateBooking?: (input: UseCreateBookingInput) => void;
|
||||
onCreateBookingSuccess?: (data: ApiSuccessResponse<BookingResponse>) => void;
|
||||
onCreateBookingError?: (data: ApiErrorResponse | Error) => void;
|
||||
@@ -150,7 +154,7 @@ export const BookerPlatformWrapper = (
|
||||
isPending: isTeamPending,
|
||||
data:
|
||||
teamEventTypeData && teamEventTypeData.length > 0
|
||||
? transformApiTeamEventTypeForAtom(teamEventTypeData[0], props.entity)
|
||||
? transformApiTeamEventTypeForAtom(teamEventTypeData[0], props.entity, props.readOnlyFormValues)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
@@ -159,7 +163,10 @@ export const BookerPlatformWrapper = (
|
||||
isSuccess,
|
||||
isError,
|
||||
isPending,
|
||||
data: data && data.length > 0 ? transformApiEventTypeForAtom(data[0], props.entity) : undefined,
|
||||
data:
|
||||
data && data.length > 0
|
||||
? transformApiEventTypeForAtom(data[0], props.entity, props.readOnlyFormValues)
|
||||
: undefined,
|
||||
};
|
||||
}, [
|
||||
props.isTeamEvent,
|
||||
|
||||
+16
-8
@@ -1,4 +1,3 @@
|
||||
import type { BookerProps } from "@calcom/features/bookings/Booker";
|
||||
import { defaultEvents } from "@calcom/lib/defaultEvents";
|
||||
import type { CustomField, SystemField } from "@calcom/lib/event-types/transformers";
|
||||
import {
|
||||
@@ -9,6 +8,8 @@ import {
|
||||
systemBeforeFieldLocation,
|
||||
systemAfterFieldRescheduleReason,
|
||||
transformRecurrenceApiToInternal,
|
||||
systemBeforeFieldNameReadOnly,
|
||||
systemBeforeFieldEmailReadOnly,
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
import { getBookerBaseUrlSync } from "@calcom/lib/getBookerUrl/client";
|
||||
import type {
|
||||
@@ -24,9 +25,12 @@ import {
|
||||
eventTypeBookingFields,
|
||||
} from "@calcom/prisma/zod-utils";
|
||||
|
||||
import type { BookerPlatformWrapperAtomProps } from "../../booker/BookerPlatformWrapper";
|
||||
|
||||
export function transformApiEventTypeForAtom(
|
||||
eventType: Omit<EventTypeOutput_2024_06_14, "ownerId">,
|
||||
entity: BookerProps["entity"] | undefined
|
||||
entity: BookerPlatformWrapperAtomProps["entity"] | undefined,
|
||||
readOnlyFormValues: BookerPlatformWrapperAtomProps["readOnlyFormValues"] | undefined
|
||||
) {
|
||||
const { lengthInMinutes, locations, bookingFields, users, recurrence, ...rest } = eventType;
|
||||
|
||||
@@ -46,7 +50,7 @@ export function transformApiEventTypeForAtom(
|
||||
...rest,
|
||||
length: lengthInMinutes,
|
||||
locations: getLocations(locations),
|
||||
bookingFields: getBookingFields(bookingFields),
|
||||
bookingFields: getBookingFields(bookingFields, readOnlyFormValues),
|
||||
isDefault,
|
||||
isDynamic: false,
|
||||
profile: {
|
||||
@@ -102,7 +106,8 @@ export function transformApiEventTypeForAtom(
|
||||
|
||||
export function transformApiTeamEventTypeForAtom(
|
||||
eventType: TeamEventTypeOutput_2024_06_14,
|
||||
entity: BookerProps["entity"] | undefined
|
||||
entity: BookerPlatformWrapperAtomProps["entity"] | undefined,
|
||||
readOnlyFormValues: BookerPlatformWrapperAtomProps["readOnlyFormValues"] | undefined
|
||||
) {
|
||||
const { lengthInMinutes, locations, hosts, bookingFields, recurrence, ...rest } = eventType;
|
||||
|
||||
@@ -121,7 +126,7 @@ export function transformApiTeamEventTypeForAtom(
|
||||
...rest,
|
||||
length: lengthInMinutes,
|
||||
locations: getLocations(locations),
|
||||
bookingFields: getBookingFields(bookingFields),
|
||||
bookingFields: getBookingFields(bookingFields, readOnlyFormValues),
|
||||
isDefault,
|
||||
isDynamic: false,
|
||||
profile: {
|
||||
@@ -219,10 +224,13 @@ function getLocations(locations: EventTypeOutput_2024_06_14["locations"]) {
|
||||
return withPrivateHidden;
|
||||
}
|
||||
|
||||
function getBookingFields(bookingFields: EventTypeOutput_2024_06_14["bookingFields"]) {
|
||||
function getBookingFields(
|
||||
bookingFields: EventTypeOutput_2024_06_14["bookingFields"],
|
||||
readOnlyFormValues: BookerPlatformWrapperAtomProps["readOnlyFormValues"] | undefined
|
||||
) {
|
||||
const systemBeforeFields: SystemField[] = [
|
||||
systemBeforeFieldName,
|
||||
systemBeforeFieldEmail,
|
||||
readOnlyFormValues?.name ? systemBeforeFieldNameReadOnly : systemBeforeFieldName,
|
||||
readOnlyFormValues?.email ? systemBeforeFieldEmailReadOnly : systemBeforeFieldEmail,
|
||||
systemBeforeFieldLocation,
|
||||
];
|
||||
|
||||
|
||||
Reference in new issue
Block a user