chore: remove last booking response dead code (#21426)
This commit is contained in:
@@ -22,7 +22,6 @@ export interface IUseBookingForm {
|
||||
guests: string[];
|
||||
name: string | null;
|
||||
};
|
||||
lastBookingResponse?: Record<string, string>;
|
||||
clientId?: string;
|
||||
}
|
||||
|
||||
@@ -36,7 +35,6 @@ export const useBookingForm = ({
|
||||
hasSession,
|
||||
extraOptions,
|
||||
prefillFormParams,
|
||||
lastBookingResponse,
|
||||
clientId,
|
||||
}: IUseBookingForm) => {
|
||||
const rescheduleUid = useBookerStore((state) => state.rescheduleUid);
|
||||
@@ -76,7 +74,6 @@ export const useBookingForm = ({
|
||||
hasSession,
|
||||
extraOptions,
|
||||
prefillFormParams,
|
||||
lastBookingResponse,
|
||||
clientId,
|
||||
});
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ type UseInitialFormValuesProps = {
|
||||
guests: string[];
|
||||
name: string | null;
|
||||
};
|
||||
lastBookingResponse?: Record<string, string>;
|
||||
clientId?: string;
|
||||
};
|
||||
|
||||
@@ -63,7 +62,6 @@ export function useInitialFormValues({
|
||||
hasSession,
|
||||
extraOptions,
|
||||
prefillFormParams,
|
||||
lastBookingResponse,
|
||||
clientId,
|
||||
}: UseInitialFormValuesProps) {
|
||||
const stableHashExtraOptions = getStableHash(extraOptions);
|
||||
@@ -105,7 +103,6 @@ export function useInitialFormValues({
|
||||
// `guests` because the `name` of the corresponding bookingField is `guests`
|
||||
guests: prefillFormParams.guests,
|
||||
});
|
||||
const parsedLastBookingResponse = z.record(z.any()).nullish().parse(lastBookingResponse);
|
||||
|
||||
const defaultUserValues = {
|
||||
email:
|
||||
@@ -113,13 +110,13 @@ export function useInitialFormValues({
|
||||
? bookingData?.attendees[0].email
|
||||
: !!parsedQuery["email"]
|
||||
? parsedQuery["email"]
|
||||
: email ?? parsedLastBookingResponse?.email ?? "",
|
||||
: email ?? "",
|
||||
name:
|
||||
rescheduleUid && bookingData && bookingData.attendees.length > 0
|
||||
? bookingData?.attendees[0].name
|
||||
: !!parsedQuery["name"]
|
||||
? parsedQuery["name"]
|
||||
: name ?? username ?? parsedLastBookingResponse?.name ?? "",
|
||||
: name ?? username ?? "",
|
||||
};
|
||||
|
||||
if (clientId) {
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
import { describe, it, expect, beforeEach, vi } from "vitest";
|
||||
|
||||
import { localStorage } from "@calcom/lib/webstorage";
|
||||
|
||||
import { setLastBookingResponse, getLastBookingResponse } from "./lastBookingResponse";
|
||||
|
||||
vi.mock("@calcom/lib/webstorage", () => ({
|
||||
localStorage: {
|
||||
getItem: vi.fn(),
|
||||
setItem: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe.skip("Last Booking Response", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("setLastBookingResponse", () => {
|
||||
it("should not store anything if responses is null", () => {
|
||||
setLastBookingResponse(null);
|
||||
expect(localStorage.setItem).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should store only allowed responses in localStorage", () => {
|
||||
const responses = {
|
||||
email: "test@example.com",
|
||||
name: "John Doe",
|
||||
age: 30,
|
||||
};
|
||||
|
||||
setLastBookingResponse(responses);
|
||||
|
||||
expect(localStorage.setItem).toHaveBeenCalledWith(
|
||||
"lastBookingResponse",
|
||||
JSON.stringify({ email: "test@example.com", name: "John Doe" })
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getLastBookingResponse", () => {
|
||||
it("should return an empty object if there is no last booking response", () => {
|
||||
(localStorage.getItem as jest.Mock).mockReturnValue(null);
|
||||
|
||||
const result = getLastBookingResponse();
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
|
||||
it("should return parsed response if valid JSON is present", () => {
|
||||
const mockResponse = JSON.stringify({ email: "test@example.com", name: "John Doe" });
|
||||
(localStorage.getItem as jest.Mock).mockReturnValue(mockResponse);
|
||||
|
||||
const result = getLastBookingResponse();
|
||||
expect(result).toEqual({ email: "test@example.com", name: "John Doe" });
|
||||
});
|
||||
|
||||
it("should return an empty object if JSON is invalid", () => {
|
||||
const invalidJson = "{ email: 'test@example.com' ";
|
||||
(localStorage.getItem as jest.Mock).mockReturnValue(invalidJson);
|
||||
|
||||
const result = getLastBookingResponse();
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,22 +0,0 @@
|
||||
// const responsesToStore = ["email", "name"];
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export const setLastBookingResponse = (responses: Record<string, unknown> | null) => {
|
||||
return;
|
||||
// if (!responses) return;
|
||||
// const prevResponse = Object.fromEntries(
|
||||
// Object.entries(responses).filter(([key]) => responsesToStore.includes(key))
|
||||
// );
|
||||
// localStorage.setItem("lastBookingResponse", JSON.stringify(prevResponse));
|
||||
};
|
||||
|
||||
export const getLastBookingResponse = () => {
|
||||
return {};
|
||||
// const lastBookingResponse = localStorage.getItem("lastBookingResponse");
|
||||
// try {
|
||||
// return JSON.parse(lastBookingResponse ?? "{}");
|
||||
// } catch (err) {
|
||||
// logger.error("Error parsing lastBookingResponse: ", err);
|
||||
// return {};
|
||||
// }
|
||||
};
|
||||
@@ -20,7 +20,6 @@ import { useVerifyCode } from "@calcom/features/bookings/Booker/components/hooks
|
||||
import { useVerifyEmail } from "@calcom/features/bookings/Booker/components/hooks/useVerifyEmail";
|
||||
import { useBookerStore, useInitializeBookerStore } from "@calcom/features/bookings/Booker/store";
|
||||
import { useEvent, useScheduleForEvent } from "@calcom/features/bookings/Booker/utils/event";
|
||||
import { getLastBookingResponse } from "@calcom/features/bookings/Booker/utils/lastBookingResponse";
|
||||
import { useBrandColors } from "@calcom/features/bookings/Booker/utils/use-brand-colors";
|
||||
import type { getPublicEvent } from "@calcom/features/eventtypes/lib/getPublicEvent";
|
||||
import { DEFAULT_LIGHT_BRAND_COLOR, DEFAULT_DARK_BRAND_COLOR, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
@@ -104,8 +103,6 @@ export const BookerWebWrapper = (props: BookerWebWrapperAtomProps) => {
|
||||
};
|
||||
}, [searchParams, firstNameQueryParam, lastNameQueryParam]);
|
||||
|
||||
const lastBookingResponse = getLastBookingResponse();
|
||||
|
||||
const bookerForm = useBookingForm({
|
||||
event: event.data,
|
||||
sessionEmail: session?.user.email,
|
||||
@@ -114,7 +111,6 @@ export const BookerWebWrapper = (props: BookerWebWrapperAtomProps) => {
|
||||
hasSession,
|
||||
extraOptions: routerQuery,
|
||||
prefillFormParams,
|
||||
lastBookingResponse,
|
||||
});
|
||||
const calendars = useCalendars({ hasSession });
|
||||
const verifyEmail = useVerifyEmail({
|
||||
|
||||
@@ -4,7 +4,6 @@ import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform";
|
||||
import { useBookerTime } from "@calcom/features/bookings/Booker/components/hooks/useBookerTime";
|
||||
import type { UseBookingFormReturnType } from "@calcom/features/bookings/Booker/components/hooks/useBookingForm";
|
||||
import { useBookerStore } from "@calcom/features/bookings/Booker/store";
|
||||
import { setLastBookingResponse } from "@calcom/features/bookings/Booker/utils/lastBookingResponse";
|
||||
import { mapBookingToMutationInput, mapRecurringBookingToMutationInput } from "@calcom/features/bookings/lib";
|
||||
import type { BookerEvent } from "@calcom/features/bookings/types";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
@@ -91,8 +90,6 @@ export const useHandleBookEvent = ({
|
||||
? duration
|
||||
: event.data.length;
|
||||
|
||||
setLastBookingResponse(values.responses);
|
||||
|
||||
const bookingInput = {
|
||||
values,
|
||||
duration: validDuration,
|
||||
|
||||
Reference in New Issue
Block a user