Skip to content

Commit a575190

Browse files
authored
Fix: hydration error /booking/[uid] (#7732)
1 parent 3924731 commit a575190

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

apps/web/components/booking/CancelBooking.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useRouter } from "next/router";
2-
import { useState } from "react";
2+
import { useCallback, useState } from "react";
33

44
import { useLocale } from "@calcom/lib/hooks/useLocale";
55
import useTheme from "@calcom/lib/hooks/useTheme";
@@ -36,6 +36,13 @@ export default function CancelBooking(props: Props) {
3636
const [error, setError] = useState<string | null>(booking ? null : t("booking_already_cancelled"));
3737
useTheme(props.theme);
3838

39+
const cancelBookingRef = useCallback((node: HTMLTextAreaElement) => {
40+
if (node !== null) {
41+
node.scrollIntoView({ behavior: "smooth" });
42+
node.focus();
43+
}
44+
// eslint-disable-next-line react-hooks/exhaustive-deps
45+
}, []);
3946
return (
4047
<>
4148
{error && (
@@ -54,6 +61,7 @@ export default function CancelBooking(props: Props) {
5461
<div className="mt-5 sm:mt-6">
5562
<label className="text-bookingdark font-medium dark:text-white">{t("cancellation_reason")}</label>
5663
<TextArea
64+
ref={cancelBookingRef}
5765
placeholder={t("cancellation_reason_placeholder")}
5866
value={cancellationReason}
5967
onChange={(e) => setCancellationReason(e.target.value)}

apps/web/pages/booking/[uid].tsx

+33-30
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import prisma from "@calcom/prisma";
4747
import type { Prisma } from "@calcom/prisma/client";
4848
import { bookingMetadataSchema } from "@calcom/prisma/zod-utils";
4949
import { customInputSchema, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
50-
import { Badge, Button, EmailInput, HeadSeo } from "@calcom/ui";
50+
import { Button, EmailInput, HeadSeo, Badge } from "@calcom/ui";
5151
import { FiX, FiExternalLink, FiChevronLeft, FiCheck, FiCalendar } from "@calcom/ui/components/icon";
5252

5353
import { timeZone } from "@lib/clock";
@@ -199,9 +199,6 @@ export default function Success(props: SuccessProps) {
199199
seatReferenceUid,
200200
} = querySchema.parse(router.query);
201201

202-
if ((isCancellationMode || changes) && typeof window !== "undefined") {
203-
window.scrollTo(0, document.body.scrollHeight);
204-
}
205202
const tz =
206203
(isSuccessBookingPage
207204
? props.bookingInfo.attendees.find((attendee) => attendee.email === email)?.timeZone
@@ -213,10 +210,6 @@ export default function Success(props: SuccessProps) {
213210
props?.bookingInfo?.metadata || {}
214211
)?.videoCallUrl;
215212

216-
if (!location) {
217-
// Can't use logger.error because it throws error on client. stdout isn't available to it.
218-
console.error(`No location found `);
219-
}
220213
const status = props.bookingInfo?.status;
221214
const reschedule = props.bookingInfo.status === BookingStatus.ACCEPTED;
222215
const cancellationReason = props.bookingInfo.cancellationReason || props.bookingInfo.rejectionReason;
@@ -239,12 +232,24 @@ export default function Success(props: SuccessProps) {
239232
const [calculatedDuration, setCalculatedDuration] = useState<number | undefined>(undefined);
240233

241234
function setIsCancellationMode(value: boolean) {
242-
if (value) router.query.cancel = "true";
243-
else delete router.query.cancel;
244-
router.replace({
245-
pathname: router.pathname,
246-
query: { ...router.query },
247-
});
235+
const query_ = { ...router.query };
236+
237+
if (value) {
238+
query_.cancel = "true";
239+
} else {
240+
if (query_.cancel) {
241+
delete query_.cancel;
242+
}
243+
}
244+
245+
router.replace(
246+
{
247+
pathname: router.pathname,
248+
query: { ...query_ },
249+
},
250+
undefined,
251+
{ scroll: false }
252+
);
248253
}
249254

250255
const eventNameObject = {
@@ -514,23 +519,21 @@ export default function Success(props: SuccessProps) {
514519
<>
515520
<div className="font-medium">{t("who")}</div>
516521
<div className="col-span-2 last:mb-0">
517-
<>
518-
{bookingInfo?.user && (
519-
<div className="mb-3">
520-
<p>
521-
<span className="mr-2">{bookingInfo.user.name}</span>
522-
<Badge variant="blue">{t("Host")}</Badge>
523-
</p>
524-
<p className="text-bookinglight">{bookingInfo.user.email}</p>
522+
{bookingInfo?.user && (
523+
<div className="mb-3">
524+
<div>
525+
<span className="mr-2">{bookingInfo.user.name}</span>
526+
<Badge variant="blue">{t("Host")}</Badge>
525527
</div>
526-
)}
527-
{bookingInfo?.attendees.map((attendee) => (
528-
<div key={attendee.name} className="mb-3 last:mb-0">
529-
{attendee.name && <p>{attendee.name}</p>}
530-
<p className="text-bookinglight">{attendee.email}</p>
531-
</div>
532-
))}
533-
</>
528+
<p className="text-bookinglight">{bookingInfo.user.email}</p>
529+
</div>
530+
)}
531+
{bookingInfo?.attendees.map((attendee) => (
532+
<div key={attendee.name} className="mb-3 last:mb-0">
533+
{attendee.name && <p>{attendee.name}</p>}
534+
<p className="text-bookinglight">{attendee.email}</p>
535+
</div>
536+
))}
534537
</div>
535538
</>
536539
)}

0 commit comments

Comments
 (0)