chore: Platform Booker defaultFormValues for prefilling (#15219)

* chore: Platform Booker defaultFormValues for prefilling

* fixup! chore: Platform Booker defaultFormValues for prefilling
This commit is contained in:
Morgan
2024-05-28 11:36:54 +00:00
committed by GitHub
parent 655127d155
commit d8a6c375d0
@@ -43,12 +43,18 @@ import { AtomsWrapper } from "../src/components/atoms-wrapper";
type BookerPlatformWrapperAtomProps = Omit<BookerProps, "username" | "entity"> & {
rescheduleUid?: string;
bookingUid?: string;
firstName?: string;
lastName?: string;
guests?: string[];
name?: string;
username: string | string[];
entity?: BookerProps["entity"];
// values for the booking form and booking fields
defaultFormValues?: {
firstName?: string;
lastName?: string;
guests?: string[];
name?: string;
email?: string;
notes?: string;
rescheduleReason?: string;
} & Record<string, string | string[]>;
handleCreateBooking?: (input: UseCreateBookingInput) => void;
onCreateBookingSuccess?: (data: ApiSuccessResponse<BookingResponse>) => void;
onCreateBookingError?: (data: ApiErrorResponse | Error) => void;
@@ -139,12 +145,17 @@ export const BookerPlatformWrapper = (props: BookerPlatformWrapperAtomProps) =>
const { data: session } = useMe();
const hasSession = !!session;
const { name: defaultName, guests: defaultGuests, ...restFormValues } = props.defaultFormValues ?? {};
const prefillFormParams = useMemo(() => {
return {
name: props.name ?? null,
guests: props.guests ?? [],
name: defaultName ?? null,
guests: defaultGuests ?? [],
};
}, [props.name, props.guests]);
}, [defaultName, defaultGuests]);
const extraOptions = useMemo(() => {
return restFormValues;
}, [restFormValues]);
const date = dayjs(selectedDate).format("YYYY-MM-DD");
const prefetchNextMonth =
@@ -198,7 +209,7 @@ export const BookerPlatformWrapper = (props: BookerPlatformWrapperAtomProps) =>
sessionUsername: session?.data?.username,
sessionName: session?.data?.username,
hasSession,
extraOptions: {},
extraOptions: extraOptions ?? {},
prefillFormParams: prefillFormParams,
});
const {
@@ -314,7 +325,7 @@ export const BookerPlatformWrapper = (props: BookerPlatformWrapperAtomProps) =>
onOverlaySwitchStateChange={function (state: boolean): void {
throw new Error("Function not implemented.");
}}
extraOptions={{}}
extraOptions={extraOptions ?? {}}
bookings={{
handleBookEvent: () => {
handleBookEvent();