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
@@ -0,0 +1,67 @@
|
||||
## 1.0.63
|
||||
1. 💥 BREAKING - `useGetBooking` hook has been renamed to `useBooking` hook and `useGetBookings` hook to `useBookings` and the data returned has different
|
||||
structure. Here is example response from `useBooking`:
|
||||
```
|
||||
{
|
||||
"id": 73,
|
||||
"uid": "wPnPGRQCnEi8nij7eaQ5E1",
|
||||
"title": "with confirmation and limit between Jane Doe and dojgqhylze-clxyyy21o0003sbk7yw5z6tzg-example",
|
||||
"description": "",
|
||||
"hosts": [
|
||||
{
|
||||
"id": 95,
|
||||
"name": "Jane Doe",
|
||||
"timeZone": "Europe/Madrid"
|
||||
}
|
||||
],
|
||||
"status": "accepted",
|
||||
"start": "2024-10-07T08:00:00.000Z",
|
||||
"end": "2024-10-07T09:00:00.000Z",
|
||||
"duration": 60,
|
||||
"eventTypeId": 1207,
|
||||
"eventType": {
|
||||
"id": 1207,
|
||||
"slug": "with-confirmation-and-limit"
|
||||
},
|
||||
"attendees": [
|
||||
{
|
||||
"name": "dojgqhylze-clxyyy21o0003sbk7yw5z6tzg-example",
|
||||
"timeZone": "Europe/Madrid",
|
||||
"language": "en",
|
||||
"absent": false
|
||||
}
|
||||
],
|
||||
"guests": [],
|
||||
"meetingUrl": "integrations:daily",
|
||||
"location": "integrations:daily",
|
||||
"absentHost": false,
|
||||
"bookingFieldsResponses": {
|
||||
"email": "[email protected]",
|
||||
"name": "dojgqhylze-clxyyy21o0003sbk7yw5z6tzg-example",
|
||||
"guests": [],
|
||||
"phone": "+37128224288",
|
||||
"location": {
|
||||
"value": "integrations:daily",
|
||||
"optionValue": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
It is important to note that `useBooking` can return one booking, one individual recurrence of recurring booking or if id of recurring booking is passed then array
|
||||
of all recurrences within recurring booking. Response schema can be viewed in api docs https://cal.com/docs/api-reference/v2/bookings/get-a-booking and switching
|
||||
between data response objects in the dropdown. This means that in your frontend you need to handle case if its an individual object or an array of bookings:
|
||||
```
|
||||
const { isLoading, data: booking, refetch } = useBooking((router.query.bookingUid as string) ?? "");
|
||||
|
||||
if (!Array.isArray(booking)) {
|
||||
...
|
||||
return abc
|
||||
} else {
|
||||
...
|
||||
return xyz
|
||||
}
|
||||
```
|
||||
|
||||
2. FIX - phone booking field not showing correctly https://linear.app/calcom/issue/CAL-4465/platform-fix-phone-booking-field
|
||||
3. FEAT - ability to hide booker event type details sidebar https://linear.app/calcom/issue/CAL-4443/platform-feat-booker-hide-event-details
|
||||
4. FEAT - make booker name and email booker properties read only if specified https://linear.app/calcom/issue/CAL-4441/platform-feat-make-name-and-email-fields-not-editable
|
||||
@@ -25,21 +25,21 @@ import {
|
||||
transformApiEventTypeForAtom,
|
||||
transformApiTeamEventTypeForAtom,
|
||||
} from "../event-types/atom-api-transformers/transformApiEventTypeForAtom";
|
||||
import type { UseCreateBookingInput } from "../hooks/bookings/useCreateBooking";
|
||||
import { useCreateBooking } from "../hooks/bookings/useCreateBooking";
|
||||
import { useCreateInstantBooking } from "../hooks/bookings/useCreateInstantBooking";
|
||||
import { useCreateRecurringBooking } from "../hooks/bookings/useCreateRecurringBooking";
|
||||
import {
|
||||
useGetBookingForReschedule,
|
||||
QUERY_KEY as BOOKING_RESCHEDULE_KEY,
|
||||
} from "../hooks/bookings/useGetBookingForReschedule";
|
||||
import { useHandleBookEvent } from "../hooks/bookings/useHandleBookEvent";
|
||||
import { useEventType } from "../hooks/event-types/public/useEventType";
|
||||
import { useTeamEventType } from "../hooks/event-types/public/useTeamEventType";
|
||||
import { useAtomsContext } from "../hooks/useAtomsContext";
|
||||
import { useAvailableSlots } from "../hooks/useAvailableSlots";
|
||||
import { useCalendarsBusyTimes } from "../hooks/useCalendarsBusyTimes";
|
||||
import { useConnectedCalendars } from "../hooks/useConnectedCalendars";
|
||||
import type { UseCreateBookingInput } from "../hooks/useCreateBooking";
|
||||
import { useCreateBooking } from "../hooks/useCreateBooking";
|
||||
import { useCreateInstantBooking } from "../hooks/useCreateInstantBooking";
|
||||
import { useCreateRecurringBooking } from "../hooks/useCreateRecurringBooking";
|
||||
import {
|
||||
useGetBookingForReschedule,
|
||||
QUERY_KEY as BOOKING_RESCHEDULE_KEY,
|
||||
} from "../hooks/useGetBookingForReschedule";
|
||||
import { useHandleBookEvent } from "../hooks/useHandleBookEvent";
|
||||
import { useMe } from "../hooks/useMe";
|
||||
import { useSlots } from "../hooks/useSlots";
|
||||
import { AtomsWrapper } from "../src/components/atoms-wrapper";
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import {
|
||||
V2_ENDPOINTS,
|
||||
SUCCESS_STATUS,
|
||||
CAL_API_VERSION_HEADER,
|
||||
VERSION_2024_08_13,
|
||||
} from "@calcom/platform-constants";
|
||||
import type { GetBookingOutput_2024_08_13 } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../lib/http";
|
||||
|
||||
export const useBooking = (uid: string) => {
|
||||
const pathname = `/${V2_ENDPOINTS.bookings}/${uid}`;
|
||||
const headers = {
|
||||
[CAL_API_VERSION_HEADER]: VERSION_2024_08_13,
|
||||
};
|
||||
|
||||
const bookingQuery = useQuery({
|
||||
queryKey: ["use-booking", uid],
|
||||
queryFn: async () => {
|
||||
return http.get<GetBookingOutput_2024_08_13>(pathname, { headers }).then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return res.data.data;
|
||||
}
|
||||
throw new Error(res.data?.error?.message);
|
||||
});
|
||||
},
|
||||
enabled: !!uid,
|
||||
});
|
||||
|
||||
return bookingQuery;
|
||||
};
|
||||
@@ -0,0 +1,54 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import {
|
||||
CAL_API_VERSION_HEADER,
|
||||
SUCCESS_STATUS,
|
||||
V2_ENDPOINTS,
|
||||
VERSION_2024_08_13,
|
||||
} from "@calcom/platform-constants";
|
||||
import type { GetBookingsOutput_2024_08_13 } from "@calcom/platform-types";
|
||||
import type { GetBookingsInput_2024_08_13 } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../lib/http";
|
||||
|
||||
export const useBookings = (input: GetBookingsInput_2024_08_13) => {
|
||||
const pathname = `/${V2_ENDPOINTS.bookings}`;
|
||||
const headers = {
|
||||
[CAL_API_VERSION_HEADER]: VERSION_2024_08_13,
|
||||
};
|
||||
|
||||
const bookingsQuery = useQuery({
|
||||
queryKey: [
|
||||
"use-bookings",
|
||||
input.status,
|
||||
input.attendeeEmail,
|
||||
input.attendeeName,
|
||||
input.eventTypeIds,
|
||||
input.eventTypeId,
|
||||
input.teamsIds,
|
||||
input.teamId,
|
||||
input.afterStart,
|
||||
input.beforeEnd,
|
||||
input.sortStart,
|
||||
input.sortEnd,
|
||||
input.sortCreated,
|
||||
input.take,
|
||||
input.skip,
|
||||
],
|
||||
queryFn: async () => {
|
||||
return http
|
||||
.get<GetBookingsOutput_2024_08_13>(pathname, {
|
||||
params: input,
|
||||
headers,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return res.data.data;
|
||||
}
|
||||
throw new Error(res.data?.error?.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return bookingsQuery;
|
||||
};
|
||||
+1
-1
@@ -5,7 +5,7 @@ import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { ApiResponse, ApiErrorResponse } from "@calcom/platform-types";
|
||||
import type { bookingCancelSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import http from "../lib/http";
|
||||
import http from "../../lib/http";
|
||||
|
||||
interface IUseCancelBooking {
|
||||
onSuccess?: () => void;
|
||||
+1
-1
@@ -5,7 +5,7 @@ import type { BookingResponse } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiErrorResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
import type { BookingCreateBody } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import http from "../lib/http";
|
||||
import http from "../../lib/http";
|
||||
|
||||
export type UseCreateBookingInput = BookingCreateBody & { locationUrl?: string };
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import type { BookingResponse } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiErrorResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
import type { BookingCreateBody } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import http from "../lib/http";
|
||||
import http from "../../lib/http";
|
||||
|
||||
interface IUseCreateInstantBooking {
|
||||
onSuccess?: (res: ApiSuccessResponse<BookingResponse>) => void;
|
||||
+1
-1
@@ -4,7 +4,7 @@ import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { BookingResponse, RecurringBookingCreateBody } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiErrorResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../lib/http";
|
||||
import http from "../../lib/http";
|
||||
|
||||
interface IUseCreateRecurringBooking {
|
||||
onSuccess?: (res: ApiSuccessResponse<BookingResponse[]>) => void;
|
||||
+2
-2
@@ -4,8 +4,8 @@ import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { getBookingForReschedule } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../lib/http";
|
||||
import { useAtomsContext } from "./useAtomsContext";
|
||||
import http from "../../lib/http";
|
||||
import { useAtomsContext } from "../useAtomsContext";
|
||||
|
||||
export const QUERY_KEY = "user-booking";
|
||||
|
||||
File renamed without changes.
@@ -1,18 +0,0 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import type { IUseBookings } from "@calcom/features/bookings/Booker/components/hooks/useBookings";
|
||||
import { useBookerStore } from "@calcom/features/bookings/Booker/store";
|
||||
|
||||
export const useBookings = ({ event, hashedLink, bookingForm, metadata }: IUseBookings) => {
|
||||
const eventSlug = useBookerStore((state) => state.eventSlug);
|
||||
const setFormValues = useBookerStore((state) => state.setFormValues);
|
||||
const rescheduleUid = useBookerStore((state) => state.rescheduleUid);
|
||||
const bookingData = useBookerStore((state) => state.bookingData);
|
||||
const timeslot = useBookerStore((state) => state.selectedTimeslot);
|
||||
const seatedEventData = useBookerStore((state) => state.seatedEventData);
|
||||
const [expiryTime, setExpiryTime] = useState<Date | undefined>();
|
||||
const recurringEventCount = useBookerStore((state) => state.recurringEventCount);
|
||||
const isInstantMeeting = useBookerStore((state) => state.isInstantMeeting);
|
||||
const duration = useBookerStore((state) => state.selectedDuration);
|
||||
const hasInstantMeetingTokenExpired = expiryTime && new Date(expiryTime) < new Date();
|
||||
};
|
||||
@@ -1,31 +0,0 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { getBookingInfo } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../lib/http";
|
||||
|
||||
export const QUERY_KEY = "user-booking";
|
||||
|
||||
export const useGetBooking = (uid = "") => {
|
||||
const pathname = `/${V2_ENDPOINTS.bookings}/${uid}`;
|
||||
|
||||
const bookingQuery = useQuery({
|
||||
queryKey: [QUERY_KEY, uid],
|
||||
queryFn: () => {
|
||||
return http
|
||||
.get<ApiResponse<Awaited<ReturnType<typeof getBookingInfo>>["bookingInfo"]>>(pathname)
|
||||
.then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return (res.data as ApiSuccessResponse<Awaited<ReturnType<typeof getBookingInfo>>["bookingInfo"]>)
|
||||
.data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
},
|
||||
enabled: !!uid,
|
||||
});
|
||||
|
||||
return bookingQuery;
|
||||
};
|
||||
@@ -1,32 +0,0 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { SUCCESS_STATUS, V2_ENDPOINTS } from "@calcom/platform-constants";
|
||||
import type { getAllUserBookings } from "@calcom/platform-libraries";
|
||||
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
||||
import type { GetBookingsInput_2024_04_15 } from "@calcom/platform-types/bookings";
|
||||
|
||||
import http from "../lib/http";
|
||||
|
||||
export const QUERY_KEY = "user-bookings";
|
||||
|
||||
export const useGetBookings = (input: GetBookingsInput_2024_04_15) => {
|
||||
const pathname = `/${V2_ENDPOINTS.bookings}`;
|
||||
|
||||
const bookingsQuery = useQuery({
|
||||
queryKey: [QUERY_KEY, input?.limit ?? 50, input?.cursor ?? 0, input?.filters?.status ?? "upcoming"],
|
||||
queryFn: () => {
|
||||
return http
|
||||
.get<ApiResponse<Awaited<ReturnType<typeof getAllUserBookings>>>>(pathname, {
|
||||
params: input,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.status === SUCCESS_STATUS) {
|
||||
return (res.data as ApiSuccessResponse<Awaited<ReturnType<typeof getAllUserBookings>>>).data;
|
||||
}
|
||||
throw new Error(res.data.error.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return bookingsQuery;
|
||||
};
|
||||
@@ -9,9 +9,9 @@ export { useEventTypes } from "./hooks/event-types/public/useEventTypes";
|
||||
export { useTeamEventTypes } from "./hooks/event-types/public/useTeamEventTypes";
|
||||
export { useEventType as useEvent } from "./hooks/event-types/public/useEventType";
|
||||
export { useEventTypeById } from "./hooks/event-types/private/useEventTypeById";
|
||||
export { useCancelBooking } from "./hooks/useCancelBooking";
|
||||
export { useGetBooking } from "./hooks/useGetBooking";
|
||||
export { useGetBookings } from "./hooks/useGetBookings";
|
||||
export { useCancelBooking } from "./hooks/bookings/useCancelBooking";
|
||||
export { useBooking } from "./hooks/bookings/useBooking";
|
||||
export { useBookings } from "./hooks/bookings/useBookings";
|
||||
export { useMe } from "./hooks/useMe";
|
||||
export { OutlookConnect } from "./connect/outlook/OutlookConnect";
|
||||
export * as Connect from "./connect";
|
||||
|
||||
@@ -3,7 +3,7 @@ export { CalProvider } from "./cal-provider/CalProvider";
|
||||
export { useIsPlatform } from "./hooks/useIsPlatform";
|
||||
export { useAtomsContext } from "./hooks/useAtomsContext";
|
||||
export { useEventTypeById } from "./hooks/event-types/private/useEventTypeById";
|
||||
export { useHandleBookEvent } from "./hooks/useHandleBookEvent";
|
||||
export { useHandleBookEvent } from "./hooks/bookings/useHandleBookEvent";
|
||||
export * as Dialog from "./src/components/ui/dialog";
|
||||
export { Timezone } from "./timezone";
|
||||
export { SelectedCalendarsSettingsWebWrapper } from "./selected-calendars/wrappers/SelectedCalendarsSettingsWebWrapper";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -89,16 +89,28 @@ export class CreateBookingInput_2024_08_13 {
|
||||
@IsOptional()
|
||||
guests?: string[];
|
||||
|
||||
@ApiPropertyOptional({
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
description:
|
||||
"Meeting URL just for this booking. Displayed in email and calendar event. If not provided then cal video link will be generated.",
|
||||
"Deprecated - use 'location' instead. Meeting URL just for this booking. Displayed in email and calendar event. If not provided then cal video link will be generated.",
|
||||
example: "https://example.com/meeting",
|
||||
required: false,
|
||||
deprecated: true,
|
||||
})
|
||||
@IsUrl()
|
||||
@IsOptional()
|
||||
meetingUrl?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
type: String,
|
||||
description: "Location for this booking. Displayed in email and calendar event.",
|
||||
example: "https://example.com/meeting",
|
||||
required: false,
|
||||
})
|
||||
@IsUrl()
|
||||
@IsOptional()
|
||||
location?: string;
|
||||
|
||||
// todo(Lauris): expose after refactoring metadata https://app.campsite.co/cal/posts/zysq8w9rwm9c
|
||||
// @ApiProperty({
|
||||
// type: Object,
|
||||
@@ -112,7 +124,8 @@ export class CreateBookingInput_2024_08_13 {
|
||||
|
||||
@ApiPropertyOptional({
|
||||
type: Object,
|
||||
description: "Booking field responses.",
|
||||
description:
|
||||
"Booking field responses consisting of an object with booking field slug as keys and user response as values.",
|
||||
example: { customField: "customValue" },
|
||||
required: false,
|
||||
})
|
||||
@@ -169,14 +182,13 @@ export class CreateRecurringBookingInput_2024_08_13 {
|
||||
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
description:
|
||||
"Meeting URL just for this booking. Displayed in email and calendar event. If not provided then cal video link will be generated.",
|
||||
description: "Location for this booking. Displayed in email and calendar event.",
|
||||
example: "https://example.com/meeting",
|
||||
required: false,
|
||||
})
|
||||
@IsUrl()
|
||||
@IsOptional()
|
||||
meetingUrl?: string;
|
||||
location?: string;
|
||||
|
||||
// todo(Lauris): expose after refactoring metadata https://app.campsite.co/cal/posts/zysq8w9rwm9c
|
||||
// @ApiProperty({
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
IsDateString,
|
||||
IsEnum,
|
||||
IsInt,
|
||||
IsObject,
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsTimeZone,
|
||||
@@ -56,6 +57,18 @@ class Host {
|
||||
timeZone!: string;
|
||||
}
|
||||
|
||||
class EventType {
|
||||
@ApiProperty({ type: Number, example: 1 })
|
||||
@IsInt()
|
||||
@Expose()
|
||||
id!: number;
|
||||
|
||||
@ApiProperty({ type: String, example: "some-event" })
|
||||
@IsString()
|
||||
@Expose()
|
||||
slug!: string;
|
||||
}
|
||||
|
||||
export class BookingOutput_2024_08_13 {
|
||||
@ApiProperty({ type: Number, example: 123 })
|
||||
@IsInt()
|
||||
@@ -67,6 +80,16 @@ export class BookingOutput_2024_08_13 {
|
||||
@Expose()
|
||||
uid!: string;
|
||||
|
||||
@ApiProperty({ type: String, example: "Consultation" })
|
||||
@IsString()
|
||||
@Expose()
|
||||
title!: string;
|
||||
|
||||
@ApiProperty({ type: String, example: "Learn how to integrate scheduling into marketplace." })
|
||||
@IsString()
|
||||
@Expose()
|
||||
description!: string;
|
||||
|
||||
@ApiProperty({ type: [Host] })
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => Host)
|
||||
@@ -111,11 +134,21 @@ export class BookingOutput_2024_08_13 {
|
||||
@Expose()
|
||||
duration!: number;
|
||||
|
||||
@ApiProperty({ type: Number, example: 45 })
|
||||
@ApiProperty({
|
||||
type: Number,
|
||||
example: 50,
|
||||
deprecated: true,
|
||||
description: "Deprecated - rely on 'eventType' object containing the id instead.",
|
||||
})
|
||||
@IsInt()
|
||||
@Expose()
|
||||
eventTypeId!: number;
|
||||
|
||||
@ApiProperty({ type: EventType })
|
||||
@Type(() => EventType)
|
||||
@Expose()
|
||||
eventType!: EventType;
|
||||
|
||||
@ApiProperty({ type: [Attendee] })
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => Attendee)
|
||||
@@ -129,16 +162,38 @@ export class BookingOutput_2024_08_13 {
|
||||
@Expose()
|
||||
guests?: string[];
|
||||
|
||||
@ApiProperty({ type: String, required: false, example: "https://example.com/meeting" })
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: false,
|
||||
description: "Deprecated - rely on 'location' field instead.",
|
||||
example: "https://example.com/recurring-meeting",
|
||||
deprecated: true,
|
||||
})
|
||||
@IsUrl()
|
||||
@IsOptional()
|
||||
@Expose()
|
||||
meetingUrl?: string;
|
||||
|
||||
@ApiProperty({ type: String, required: false, example: "https://example.com/meeting" })
|
||||
@IsOptional()
|
||||
@Expose()
|
||||
location!: string;
|
||||
|
||||
@ApiProperty({ type: Boolean, example: true })
|
||||
@IsBoolean()
|
||||
@Expose()
|
||||
absentHost!: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
type: Object,
|
||||
description:
|
||||
"Booking field responses consisting of an object with booking field slug as keys and user response as values.",
|
||||
example: { customField: "customValue" },
|
||||
required: false,
|
||||
})
|
||||
@IsObject()
|
||||
@Expose()
|
||||
bookingFieldsResponses!: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export class RecurringBookingOutput_2024_08_13 {
|
||||
@@ -152,6 +207,16 @@ export class RecurringBookingOutput_2024_08_13 {
|
||||
@Expose()
|
||||
uid!: string;
|
||||
|
||||
@ApiProperty({ type: String, example: "Recurring meeting" })
|
||||
@IsString()
|
||||
@Expose()
|
||||
title!: string;
|
||||
|
||||
@ApiProperty({ type: String, example: "Learn how to integrate scheduling into marketplace." })
|
||||
@IsString()
|
||||
@Expose()
|
||||
description!: string;
|
||||
|
||||
@ApiProperty({ type: [Host] })
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => Host)
|
||||
@@ -196,11 +261,21 @@ export class RecurringBookingOutput_2024_08_13 {
|
||||
@Expose()
|
||||
duration!: number;
|
||||
|
||||
@ApiProperty({ type: Number, example: 50 })
|
||||
@ApiProperty({
|
||||
type: Number,
|
||||
example: 50,
|
||||
deprecated: true,
|
||||
description: "Deprecated - rely on 'eventType' object containing the id instead.",
|
||||
})
|
||||
@IsInt()
|
||||
@Expose()
|
||||
eventTypeId!: number;
|
||||
|
||||
@ApiProperty({ type: EventType })
|
||||
@Type(() => EventType)
|
||||
@Expose()
|
||||
eventType!: EventType;
|
||||
|
||||
@ApiProperty({ type: String, example: "recurring_uid_987" })
|
||||
@IsString()
|
||||
@Expose()
|
||||
@@ -219,14 +294,36 @@ export class RecurringBookingOutput_2024_08_13 {
|
||||
@Expose()
|
||||
guests?: string[];
|
||||
|
||||
@ApiProperty({ type: String, required: false, example: "https://example.com/recurring-meeting" })
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: false,
|
||||
description: "Deprecated - rely on 'location' field instead.",
|
||||
example: "https://example.com/recurring-meeting",
|
||||
deprecated: true,
|
||||
})
|
||||
@IsUrl()
|
||||
@IsOptional()
|
||||
@Expose()
|
||||
meetingUrl?: string;
|
||||
|
||||
@ApiProperty({ type: String, required: false, example: "https://example.com/recurring-meeting" })
|
||||
@IsOptional()
|
||||
@Expose()
|
||||
location!: string;
|
||||
|
||||
@ApiProperty({ type: Boolean, example: false })
|
||||
@IsBoolean()
|
||||
@Expose()
|
||||
absentHost!: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
type: Object,
|
||||
description:
|
||||
"Booking field responses consisting of an object with booking field slug as keys and user response as values.",
|
||||
example: { customField: "customValue" },
|
||||
required: false,
|
||||
})
|
||||
@IsObject()
|
||||
@Expose()
|
||||
bookingFieldsResponses!: Record<string, unknown>;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { ApiProperty, ApiExtraModels, getSchemaPath } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsEnum, ValidateNested } from "class-validator";
|
||||
|
||||
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
|
||||
import { BookingOutput_2024_08_13, RecurringBookingOutput_2024_08_13 } from "@calcom/platform-types";
|
||||
|
||||
@ApiExtraModels(BookingOutput_2024_08_13, RecurringBookingOutput_2024_08_13)
|
||||
export class GetBookingOutput_2024_08_13 {
|
||||
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
|
||||
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
|
||||
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
|
||||
|
||||
@ValidateNested()
|
||||
@ApiProperty({
|
||||
oneOf: [
|
||||
{ $ref: getSchemaPath(BookingOutput_2024_08_13) },
|
||||
{ $ref: getSchemaPath(RecurringBookingOutput_2024_08_13) },
|
||||
{ type: "array", items: { $ref: getSchemaPath(RecurringBookingOutput_2024_08_13) } },
|
||||
],
|
||||
description:
|
||||
"Booking data, which can be either a BookingOutput object, a RecurringBookingOutput object, or an array of RecurringBookingOutput objects",
|
||||
})
|
||||
@Type(() => Object)
|
||||
data!: BookingOutput_2024_08_13 | RecurringBookingOutput_2024_08_13 | RecurringBookingOutput_2024_08_13[];
|
||||
|
||||
error?: Error;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { ApiProperty, ApiExtraModels, getSchemaPath } from "@nestjs/swagger";
|
||||
import { IsEnum, ValidateNested } from "class-validator";
|
||||
|
||||
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
|
||||
import { BookingOutput_2024_08_13, RecurringBookingOutput_2024_08_13 } from "@calcom/platform-types";
|
||||
|
||||
@ApiExtraModels(BookingOutput_2024_08_13, RecurringBookingOutput_2024_08_13)
|
||||
export class GetBookingsOutput_2024_08_13 {
|
||||
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
|
||||
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
|
||||
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
|
||||
|
||||
@ApiProperty({
|
||||
type: "array",
|
||||
items: {
|
||||
oneOf: [
|
||||
{ $ref: getSchemaPath(BookingOutput_2024_08_13) },
|
||||
{ $ref: getSchemaPath(RecurringBookingOutput_2024_08_13) },
|
||||
],
|
||||
},
|
||||
description:
|
||||
"Array of booking data, which can contain either BookingOutput objects or RecurringBookingOutput objects",
|
||||
})
|
||||
@ValidateNested({ each: true })
|
||||
data!: (BookingOutput_2024_08_13 | RecurringBookingOutput_2024_08_13)[];
|
||||
|
||||
error?: Error;
|
||||
}
|
||||
@@ -1 +1,3 @@
|
||||
export * from "./booking.output";
|
||||
export * from "./get-booking.output";
|
||||
export * from "./get-bookings.output";
|
||||
Reference in new issue
Block a user