Amended useEffect for simplication
parent
f6391404b7
commit
8641b64f24
|
@ -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;
|
||||||
|
|
|
@ -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(() => {
|
||||||
|
|
Loading…
Reference in New Issue