Amended useEffect for simplication

pull/6146/head
Alex van Andel 2022-12-21 16:03:18 +00:00
parent f6391404b7
commit 8641b64f24
2 changed files with 11 additions and 19 deletions

View File

@ -44,18 +44,17 @@ const BookingDescription: FC<Props> = (props) => {
const { profile, eventType, isBookingPage = false, children } = props; const { profile, eventType, isBookingPage = false, children } = props;
const { date: bookingDate } = useRouterQuery("date"); const { date: bookingDate } = useRouterQuery("date");
const { t } = useLocale(); const { t } = useLocale();
const { duration, setQuery: setDuration } = useRouterQuery("duration"); const { duration = eventType.length.toString(), setQuery: setDuration } = useRouterQuery("duration");
useEffect(() => { useEffect(() => {
if (eventType.metadata?.multipleDuration !== undefined) { if (
if (!duration) { eventType.metadata?.multipleDuration &&
setDuration(eventType.length); !eventType.metadata?.multipleDuration?.includes(Number(duration))
} else { ) {
if (!eventType.metadata?.multipleDuration.includes(Number(duration))) { setDuration(eventType.length.toString());
setDuration(eventType.length);
}
}
} }
}, [setDuration, eventType.length, eventType.metadata?.multipleDuration, duration]); }, [duration, setDuration, eventType.length, eventType.metadata?.multipleDuration]);
let requiresConfirmation = eventType?.requiresConfirmation; let requiresConfirmation = eventType?.requiresConfirmation;
let requiresConfirmationText = t("requires_confirmation"); let requiresConfirmationText = t("requires_confirmation");
const rcThreshold = eventType?.metadata?.requiresConfirmationThreshold; const rcThreshold = eventType?.metadata?.requiresConfirmationThreshold;

View File

@ -26,7 +26,6 @@ import notEmpty from "@calcom/lib/notEmpty";
import { getRecurringFreq } from "@calcom/lib/recurringStrings"; import { getRecurringFreq } from "@calcom/lib/recurringStrings";
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry"; import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
import { detectBrowserTimeFormat, setIs24hClockInLocalStorage, TimeFormat } from "@calcom/lib/timeFormat"; import { detectBrowserTimeFormat, setIs24hClockInLocalStorage, TimeFormat } from "@calcom/lib/timeFormat";
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
import { trpc } from "@calcom/trpc/react"; import { trpc } from "@calcom/trpc/react";
import { Icon, DatePicker } from "@calcom/ui"; import { Icon, DatePicker } from "@calcom/ui";
@ -98,7 +97,7 @@ const SlotPicker = ({
weekStart = 0, weekStart = 0,
ethSignature, ethSignature,
}: { }: {
eventType: Pick<EventType, "id" | "schedulingType" | "slug" | "metadata">; eventType: Pick<EventType, "id" | "schedulingType" | "slug">;
timeFormat: TimeFormat; timeFormat: TimeFormat;
onTimeFormatChange: (is24Hour: boolean) => void; onTimeFormatChange: (is24Hour: boolean) => void;
timeZone?: string; timeZone?: string;
@ -110,17 +109,11 @@ const SlotPicker = ({
}) => { }) => {
const [selectedDate, setSelectedDate] = useState<Dayjs>(); const [selectedDate, setSelectedDate] = useState<Dayjs>();
const [browsingDate, setBrowsingDate] = useState<Dayjs>(); const [browsingDate, setBrowsingDate] = useState<Dayjs>();
let { duration } = useRouterQuery("duration"); const { duration } = useRouterQuery("duration");
const { date, setQuery: setDate } = useRouterQuery("date"); const { date, setQuery: setDate } = useRouterQuery("date");
const { month, setQuery: setMonth } = useRouterQuery("month"); const { month, setQuery: setMonth } = useRouterQuery("month");
const router = useRouter(); const router = useRouter();
// Showing error if event type doesn't have multiple duration and duration query param exists
const metadata = EventTypeMetaDataSchema.parse(eventType.metadata);
if (!metadata?.multipleDuration && router.query.duration != undefined) {
duration = undefined;
}
const [slotPickerRef] = useAutoAnimate<HTMLDivElement>(); const [slotPickerRef] = useAutoAnimate<HTMLDivElement>();
useEffect(() => { useEffect(() => {