feat: platform endpoints to fetch/cancel/reschedule bookings and hooks (#14164)

* init bookings endpoint

* abstracting functions

* e2e tests for bookings

* hooks for bookings endpoint

* bookings respository fixtures

* typings for booking input

* fixup

* abstract booking info code and use it as handler

* import handlers for bookings endpoint

* add cancel booking input

* add handleCancelBooking handler in platform libraries

* cancel booking endpoint

* abstract call into its own separate fn

* cancel booking hook

* e2e test for cancel booking endpoint

* fix import

* export getBookings function

* move getAllUserBookings into lib

* add bookings folder to package exports

* use getAllUserBookings from lib

* fix import path

* fix: hooks, endpoint and example for cancel / reschedule / list / booking success page

* fix: unit test mock classNames import from lib

* fix: unit test mock classNames import from lib

---------

Co-authored-by: Morgan Vernay <[email protected]>
Co-authored-by: Morgan <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-03-27 12:34:54 +00:00
1 parent a35683667b
commit cc2164657c
27 files changed
+986 -131

No files matched your search

@@ -118,6 +118,8 @@ export type BookerStore = {
rescheduleUid: string | null;
bookingUid: string | null;
bookingData: GetBookingType | null;
setBookingData: (bookingData: GetBookingType | null | undefined) => void;
/**
* Method called by booker component to set initial data.
*/
@@ -317,6 +319,9 @@ export const useBookerStore = create<BookerStore>((set, get) => ({
set({ selectedDuration });
updateQueryParam("duration", selectedDuration ?? "");
},
setBookingData: (bookingData: GetBookingType | null | undefined) => {
set({ bookingData: bookingData ?? null });
},
recurringEventCount: null,
setRecurringEventCount: (recurringEventCount: number | null) => set({ recurringEventCount }),
occurenceCount: null,
@@ -0,0 +1,17 @@
import { getBookingWithResponses } from "@calcom/features/bookings/lib/get-booking";
import getUserBooking from "./getUserBooking";
const getBookingInfo = async (uid: string) => {
const bookingInfoRaw = await getUserBooking(uid);
if (!bookingInfoRaw) {
return { bookingInfoRaw: undefined, bookingInfo: undefined };
}
const bookingInfo = getBookingWithResponses(bookingInfoRaw);
return { bookingInfoRaw, bookingInfo };
};
export default getBookingInfo;
@@ -0,0 +1,60 @@
import prisma from "@calcom/prisma";
const getUserBooking = async (uid: string) => {
const bookingInfo = await prisma.booking.findFirst({
where: {
uid: uid,
},
select: {
title: true,
id: true,
uid: true,
description: true,
customInputs: true,
smsReminderNumber: true,
recurringEventId: true,
startTime: true,
endTime: true,
location: true,
status: true,
metadata: true,
cancellationReason: true,
responses: true,
rejectionReason: true,
userPrimaryEmail: true,
user: {
select: {
id: true,
name: true,
email: true,
username: true,
timeZone: true,
},
},
attendees: {
select: {
name: true,
email: true,
timeZone: true,
},
},
eventTypeId: true,
eventType: {
select: {
eventName: true,
slug: true,
timeZone: true,
},
},
seatsReferences: {
select: {
referenceUid: true,
},
},
},
});
return bookingInfo;
};
export default getUserBooking;