refactor: platform bookings hooks & bookings API (#16963)
* chore: delete unused bookings hook * refactor: group bookings hooks in folder * refactor: rename useGetBooking, useGetBookings to useBooking, useBookings * refactor: booking inputs and outputs * chore: make bookings controller work with new inputs and outputs * make examples app work * refactor: deprecate fields instead of removing them * readd eventtypeid * swagger regenerate * make recurring booking backwards compatible * fix test * update changelog * swagger update * fix import * chore: update lock file
This commit is contained in:
1 parent
d99f171597
commit
a10d3599e2
32 files changed
+1308
-824
No files matched your search
@@ -3,7 +3,7 @@ import { Inter } from "next/font/google";
|
||||
// eslint-disable-next-line @calcom/eslint/deprecated-imports-next-router
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
import { useGetBooking, useCancelBooking } from "@calcom/atoms";
|
||||
import { useBooking, useCancelBooking } from "@calcom/atoms";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { Icon } from "@calcom/ui";
|
||||
|
||||
@@ -12,158 +12,159 @@ const inter = Inter({ subsets: ["latin"] });
|
||||
export default function Bookings(props: { calUsername: string; calEmail: string }) {
|
||||
const router = useRouter();
|
||||
|
||||
const { isLoading, data: booking, refetch } = useGetBooking((router.query.bookingUid as string) ?? "");
|
||||
const startTime = dayjs(booking?.startTime).format(12 === 12 ? "h:mma" : "HH:mm");
|
||||
const endTime = dayjs(booking?.endTime).format(12 === 12 ? "h:mma" : "HH:mm");
|
||||
const date = dayjs(booking?.startTime).toDate();
|
||||
const dateToday = dayjs(booking?.startTime).date();
|
||||
const year = dayjs(booking?.startTime).year();
|
||||
const day = dayjs(date).format("dddd");
|
||||
const month = dayjs(date).format("MMMM");
|
||||
|
||||
const { isLoading, data: booking, refetch } = useBooking((router.query.bookingUid as string) ?? "");
|
||||
const { mutate: cancelBooking } = useCancelBooking({
|
||||
onSuccess: () => {
|
||||
refetch();
|
||||
},
|
||||
});
|
||||
return (
|
||||
<main
|
||||
className={`flex min-h-screen flex-col ${inter.className} main text-default flex min-h-full w-full flex-col items-center overflow-visible`}>
|
||||
<Navbar username={props.calUsername} />
|
||||
{isLoading && <p>Loading...</p>}
|
||||
{!isLoading && booking && (
|
||||
<div
|
||||
key={booking.id}
|
||||
className="my-10 w-[440px] overflow-hidden rounded-md border-[0.7px] border-black px-10 py-5">
|
||||
{booking.status === "ACCEPTED" ? (
|
||||
<div className="mx-2 my-4 flex flex-col items-center justify-center text-center">
|
||||
<Icon
|
||||
name="circle-check-big"
|
||||
className="my-5 flex h-[40px] w-[40px] rounded-full bg-green-500"
|
||||
/>
|
||||
<h1 className="text-xl font-bold">This meeting is scheduled</h1>
|
||||
<p>We sent an email with a calendar invitation with the details to everyone.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="mx-2 my-4 flex flex-col items-center justify-center text-center">
|
||||
<Icon name="x" className="my-5 flex h-[40px] w-[40px] rounded-full bg-red-400" />
|
||||
<h4 className="text-2xl font-bold">This event is cancelled</h4>
|
||||
</div>
|
||||
)}
|
||||
<hr className="mx-2 bg-black text-black" />
|
||||
<div className="mx-2 my-7 flex flex-col gap-y-3">
|
||||
<div className="flex gap-[70px]">
|
||||
<div>
|
||||
<h4>What</h4>
|
||||
|
||||
if (!Array.isArray(booking)) {
|
||||
const startTime = dayjs(booking?.start).format(12 === 12 ? "h:mma" : "HH:mm");
|
||||
const endTime = dayjs(booking?.end).format(12 === 12 ? "h:mma" : "HH:mm");
|
||||
const date = dayjs(booking?.start).toDate();
|
||||
const dateToday = dayjs(booking?.start).date();
|
||||
const year = dayjs(booking?.start).year();
|
||||
const day = dayjs(date).format("dddd");
|
||||
const month = dayjs(date).format("MMMM");
|
||||
|
||||
return (
|
||||
<main
|
||||
className={`flex min-h-screen flex-col ${inter.className} main text-default flex min-h-full w-full flex-col items-center overflow-visible`}>
|
||||
<Navbar username={props.calUsername} />
|
||||
{isLoading && <p>Loading...</p>}
|
||||
{!isLoading && booking && (
|
||||
<div
|
||||
key={booking.id}
|
||||
className="my-10 w-[440px] overflow-hidden rounded-md border-[0.7px] border-black px-10 py-5">
|
||||
{booking.status === "accepted" ? (
|
||||
<div className="mx-2 my-4 flex flex-col items-center justify-center text-center">
|
||||
<Icon
|
||||
name="circle-check-big"
|
||||
className="my-5 flex h-[40px] w-[40px] rounded-full bg-green-500"
|
||||
/>
|
||||
<h1 className="text-xl font-bold">This meeting is scheduled</h1>
|
||||
<p>We sent an email with a calendar invitation with the details to everyone.</p>
|
||||
</div>
|
||||
<div>
|
||||
<p>{booking.title}</p>
|
||||
) : (
|
||||
<div className="mx-2 my-4 flex flex-col items-center justify-center text-center">
|
||||
<Icon name="x" className="my-5 flex h-[40px] w-[40px] rounded-full bg-red-400" />
|
||||
<h4 className="text-2xl font-bold">This event is cancelled</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-[70px]">
|
||||
<div>
|
||||
<h4>When</h4>
|
||||
</div>
|
||||
<div>
|
||||
)}
|
||||
<hr className="mx-2 bg-black text-black" />
|
||||
<div className="mx-2 my-7 flex flex-col gap-y-3">
|
||||
<div className="flex gap-[70px]">
|
||||
<div>
|
||||
<p
|
||||
style={{
|
||||
textDecoration: booking.status === "ACCEPTED" ? "normal" : "line-through",
|
||||
}}>
|
||||
{`${day}, ${month} ${dateToday}, ${year}`}
|
||||
</p>
|
||||
<h4>What</h4>
|
||||
</div>
|
||||
<div>
|
||||
<p
|
||||
style={{
|
||||
textDecoration: booking.status === "ACCEPTED" ? "normal" : "line-through",
|
||||
}}>
|
||||
{`${startTime}`} - {`${endTime}`}
|
||||
</p>
|
||||
<p>{booking.title}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-[70px]">
|
||||
<div>Who</div>
|
||||
<div>
|
||||
<div className="flex gap-[70px]">
|
||||
<div>
|
||||
<h4>When</h4>
|
||||
</div>
|
||||
<div>
|
||||
<div>
|
||||
<h4>
|
||||
{booking.user?.name}{" "}
|
||||
<span className="rounded-md bg-blue-800 px-2 text-sm text-white">Host</span>
|
||||
</h4>
|
||||
<p>{booking.user?.email}</p>
|
||||
<p
|
||||
style={{
|
||||
textDecoration: booking.status === "accepted" ? "normal" : "line-through",
|
||||
}}>
|
||||
{`${day}, ${month} ${dateToday}, ${year}`}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p
|
||||
style={{
|
||||
textDecoration: booking.status === "accepted" ? "normal" : "line-through",
|
||||
}}>
|
||||
{`${startTime}`} - {`${endTime}`}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{booking.attendees.map((attendee, i) => {
|
||||
return (
|
||||
<div key={`${i}-${attendee.name}`}>
|
||||
<br />
|
||||
<div>
|
||||
<h4>{`${attendee.name}`}</h4>
|
||||
<p>{`${attendee.email}`}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-[70px]">
|
||||
<div>Who</div>
|
||||
<div>
|
||||
<div>
|
||||
<div>
|
||||
<h4>
|
||||
{booking.hosts[0]?.name}{" "}
|
||||
<span className="rounded-md bg-blue-800 px-2 text-sm text-white">Host</span>
|
||||
</h4>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{booking.attendees.map((attendee, i) => {
|
||||
return (
|
||||
<div key={`${i}-${attendee.name}`}>
|
||||
<br />
|
||||
<div>
|
||||
<h4>{`${attendee.name}`}</h4>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
{!!booking.location && (
|
||||
<div className="flex gap-[70px]">
|
||||
<div>
|
||||
<h4>Where</h4>
|
||||
</div>
|
||||
<div>
|
||||
<p>{booking.location}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{!!booking.bookingFieldsResponses?.notes && (
|
||||
<div className="flex gap-[70px]">
|
||||
<div className="w-[40px]">
|
||||
<h4>Additional notes</h4>
|
||||
</div>
|
||||
<div>
|
||||
<p>{`${booking.bookingFieldsResponses.notes}`}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{!!booking.location && booking.location.startsWith("http") && (
|
||||
<div className="flex gap-[70px]">
|
||||
<div>
|
||||
<h4>Where</h4>
|
||||
|
||||
{booking.status === "accepted" && (
|
||||
<>
|
||||
<hr className="mx-3" />
|
||||
<div className="mx-2 my-3 text-center">
|
||||
<p>
|
||||
Need to make a change?{" "}
|
||||
<button
|
||||
className="underline"
|
||||
onClick={() => {
|
||||
router.push(
|
||||
`/booking?rescheduleUid=${booking?.uid}&eventTypeSlug=${booking?.eventType.slug}`
|
||||
);
|
||||
}}>
|
||||
Reschedule
|
||||
</button>{" "}
|
||||
or{" "}
|
||||
<button
|
||||
className="underline"
|
||||
onClick={() => {
|
||||
cancelBooking({
|
||||
id: booking.id,
|
||||
uid: booking.uid,
|
||||
cancellationReason: "User request",
|
||||
allRemainingBookings: true,
|
||||
});
|
||||
}}>
|
||||
Cancel
|
||||
</button>
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p>{booking.location}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{booking.responses.notes && (
|
||||
<div className="flex gap-[70px]">
|
||||
<div className="w-[40px]">
|
||||
<h4>Additional notes</h4>
|
||||
</div>
|
||||
<div>
|
||||
<p>{`${booking.responses.notes}`}</p>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{booking.status === "ACCEPTED" && (
|
||||
<>
|
||||
<hr className="mx-3" />
|
||||
<div className="mx-2 my-3 text-center">
|
||||
<p>
|
||||
Need to make a change?{" "}
|
||||
<button
|
||||
className="underline"
|
||||
onClick={() => {
|
||||
router.push(
|
||||
`/booking?rescheduleUid=${booking?.uid}&eventTypeSlug=${booking?.eventType?.slug}`
|
||||
);
|
||||
}}>
|
||||
Reschedule
|
||||
</button>{" "}
|
||||
or{" "}
|
||||
<button
|
||||
className="underline"
|
||||
onClick={() => {
|
||||
cancelBooking({
|
||||
id: booking.id,
|
||||
uid: booking.uid,
|
||||
cancellationReason: "User request",
|
||||
allRemainingBookings: true,
|
||||
});
|
||||
}}>
|
||||
Cancel
|
||||
</button>
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,22 +3,22 @@ import { Inter } from "next/font/google";
|
||||
// eslint-disable-next-line @calcom/eslint/deprecated-imports-next-router
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
import { useGetBookings } from "@calcom/atoms";
|
||||
import { useBookings } from "@calcom/atoms";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
|
||||
const inter = Inter({ subsets: ["latin"] });
|
||||
|
||||
export default function Bookings(props: { calUsername: string; calEmail: string }) {
|
||||
const { isLoading: isLoadingUpcomingBookings, data: upcomingBookings } = useGetBookings({
|
||||
limit: 50,
|
||||
cursor: 0,
|
||||
filters: { status: "upcoming" },
|
||||
const { isLoading: isLoadingUpcomingBookings, data: upcomingBookings } = useBookings({
|
||||
take: 50,
|
||||
skip: 0,
|
||||
status: ["upcoming"],
|
||||
});
|
||||
|
||||
const { isLoading: isLoadingPastBookings, data: pastBookings } = useGetBookings({
|
||||
limit: 50,
|
||||
cursor: 0,
|
||||
filters: { status: "past" },
|
||||
const { isLoading: isLoadingPastBookings, data: pastBookings } = useBookings({
|
||||
take: 50,
|
||||
skip: 0,
|
||||
status: ["past"],
|
||||
});
|
||||
const isLoading = isLoadingUpcomingBookings || isLoadingPastBookings;
|
||||
const router = useRouter();
|
||||
@@ -30,13 +30,13 @@ export default function Bookings(props: { calUsername: string; calEmail: string
|
||||
<h1 className="my-4 text-2xl font-semibold">{props.calUsername} Bookings</h1>
|
||||
{isLoading && <p>Loading...</p>}
|
||||
{!isLoading &&
|
||||
pastBookings?.bookings &&
|
||||
upcomingBookings?.bookings &&
|
||||
(Boolean(upcomingBookings?.bookings.length) || Boolean(pastBookings?.bookings.length)) &&
|
||||
[...pastBookings?.bookings, ...upcomingBookings?.bookings].map((booking) => {
|
||||
const date = dayjs(booking.startTime).toDate();
|
||||
const startTime = dayjs(booking?.startTime).format(12 === 12 ? "h:mma" : "HH:mm");
|
||||
const endTime = dayjs(booking?.endTime).format(12 === 12 ? "h:mma" : "HH:mm");
|
||||
pastBookings &&
|
||||
upcomingBookings &&
|
||||
(Boolean(upcomingBookings?.length) || Boolean(pastBookings?.length)) &&
|
||||
[...pastBookings, ...upcomingBookings].map((booking) => {
|
||||
const date = dayjs(booking.start).toDate();
|
||||
const startTime = dayjs(booking?.start).format(12 === 12 ? "h:mma" : "HH:mm");
|
||||
const endTime = dayjs(booking?.end).format(12 === 12 ? "h:mma" : "HH:mm");
|
||||
const day = dayjs(date).format("dddd");
|
||||
const month = dayjs(date).format("MMMM");
|
||||
|
||||
@@ -48,7 +48,7 @@ export default function Bookings(props: { calUsername: string; calEmail: string
|
||||
router.push(`/${booking.uid}`);
|
||||
}}>
|
||||
<div>
|
||||
<div className="px-6">{`${day}, ${dayjs(booking.startTime).date()} ${month}`}</div>
|
||||
<div className="px-6">{`${day}, ${dayjs(booking.start).date()} ${month}`}</div>
|
||||
<div className="px-6">
|
||||
<p>
|
||||
{startTime} - {endTime}
|
||||
@@ -64,7 +64,7 @@ export default function Bookings(props: { calUsername: string; calEmail: string
|
||||
</div>
|
||||
<div className="px-6">
|
||||
<p>
|
||||
{booking?.user?.name} and {booking.attendees[0].name}
|
||||
{booking?.hosts?.[0]?.name} and {booking.attendees[0].name}
|
||||
</p>{" "}
|
||||
<p />
|
||||
</div>
|
||||
|
||||
@@ -30,7 +30,6 @@ export default function Bookings(props: { calUsername: string; calEmail: string
|
||||
|
||||
{!isLoadingEvents && !eventTypeId && Boolean(eventTypes?.length) && !rescheduleUid && (
|
||||
<div className="flex flex-col gap-4">
|
||||
<h1>User event types</h1>
|
||||
{eventTypes?.map(
|
||||
(event: { id: number; slug: string; title: string; lengthInMinutes: number }) => {
|
||||
const formatEventSlug = event.slug
|
||||
|
||||
Reference in new issue
Block a user