feat: Add rescheduledBy & canceledBy fields in the DB (#15337)

* feat: Add rescheduledBy & canceledBy fields in the DB

* fix: type check

* fix: type check

* fix: use session user email for reschedule

* fix: unit test

* feat: db field email validation

* feat: rescheduledBy and cancelledBy in webhooks

* revert unrelated changes.

* make session user secondary, default to Anonymous

* if condition not required

* Make cancelledBy optional

Co-authored-by: Syed Ali Shahbaz <[email protected]>

* update cancel booking type

* fix: update cancelledBy in db when requesting reschedule

* remove default value for fields

* fix: type check

* feat: manage fields via api v1

* fix: add fields in booking read api v1

* test: expand to cover new fields

* fix: use cancelledBy param on booking page

---------

Co-authored-by: Anik Dhabal Babu <[email protected]>
Co-authored-by: Syed Ali Shahbaz <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-08-25 11:31:46 +02:00
1 parent 34075ee303
commit b6d31129a3
28 files changed
+139 -20

No files matched your search

+11 -2
View File
@@ -27,6 +27,7 @@ type StoreInitializeType = {
bookingData?: GetBookingType | null | undefined;
verifiedEmail?: string | null;
rescheduleUid?: string | null;
rescheduledBy?: string | null;
seatReferenceUid?: string;
durationConfig?: number[] | null;
org?: string | null;
@@ -113,11 +114,12 @@ export type BookerStore = {
dayCount: number | null;
setDayCount: (dayCount: number | null) => void;
/**
* If booking is being rescheduled or it has seats, it receives a rescheduleUid or bookingUid
* If booking is being rescheduled or it has seats, it receives a rescheduleUid with rescheduledBy or bookingUid
* the current booking details are passed in. The `bookingData`
* object is something that's fetched server side.
*/
rescheduleUid: string | null;
rescheduledBy: string | null;
bookingUid: string | null;
bookingData: GetBookingType | null;
setBookingData: (bookingData: GetBookingType | null | undefined) => void;
@@ -207,6 +209,7 @@ export const useBookerStore = create<BookerStore>((set, get) => ({
username: null,
eventSlug: null,
eventId: null,
rescheduledBy: null,
verifiedEmail: null,
setVerifiedEmail: (email: string | null) => {
set({ verifiedEmail: email });
@@ -242,6 +245,7 @@ export const useBookerStore = create<BookerStore>((set, get) => ({
month,
eventId,
rescheduleUid = null,
rescheduledBy = null,
bookingUid = null,
bookingData = null,
layout,
@@ -260,7 +264,8 @@ export const useBookerStore = create<BookerStore>((set, get) => ({
get().rescheduleUid === rescheduleUid &&
get().bookingUid === bookingUid &&
get().bookingData?.responses.email === bookingData?.responses.email &&
get().layout === layout
get().layout === layout &&
get().rescheduledBy === rescheduledBy
)
return;
set({
@@ -269,6 +274,7 @@ export const useBookerStore = create<BookerStore>((set, get) => ({
eventId,
org,
rescheduleUid,
rescheduledBy,
bookingUid,
bookingData,
layout: layout || BookerLayouts.MONTH_VIEW,
@@ -358,6 +364,7 @@ export const useInitializeBookerStore = ({
month,
eventId,
rescheduleUid = null,
rescheduledBy = null,
bookingData = null,
verifiedEmail = null,
layout,
@@ -374,6 +381,7 @@ export const useInitializeBookerStore = ({
month,
eventId,
rescheduleUid,
rescheduledBy,
bookingData,
layout,
isTeamEvent,
@@ -390,6 +398,7 @@ export const useInitializeBookerStore = ({
month,
eventId,
rescheduleUid,
rescheduledBy,
bookingData,
layout,
isTeamEvent,
@@ -90,6 +90,7 @@ export interface BookerProps {
export type WrappedBookerPropsMain = {
sessionUsername?: string | null;
rescheduleUid: string | null;
rescheduledBy: string | null;
bookingUid: string | null;
isRedirect: boolean;
fromUserNameRedirected: string;
@@ -14,6 +14,7 @@ export type BookingOptions = {
timeZone: string;
language: string;
rescheduleUid: string | undefined;
rescheduledBy: string | undefined;
username: string;
metadata?: Record<string, string>;
bookingUid?: string;
@@ -31,6 +32,7 @@ export const mapBookingToMutationInput = ({
timeZone,
language,
rescheduleUid,
rescheduledBy,
username,
metadata,
bookingUid,
@@ -52,6 +54,7 @@ export const mapBookingToMutationInput = ({
timeZone: timeZone,
language: language,
rescheduleUid,
rescheduledBy,
metadata: metadata || {},
hasHashedBookingLink: hashedLink ? true : false,
bookingUid,
@@ -155,7 +155,7 @@ export type HandleCancelBookingResponse = {
};
async function handler(req: CustomRequest) {
const { id, uid, allRemainingBookings, cancellationReason, seatReferenceUid } =
const { id, uid, allRemainingBookings, cancellationReason, seatReferenceUid, cancelledBy } =
schemaBookingCancelParams.parse(req.body);
req.bookingToDelete = await getBookingToDelete(id, uid);
const {
@@ -342,6 +342,7 @@ async function handler(req: CustomRequest) {
...eventTypeInfo,
status: "CANCELLED",
smsReminderNumber: bookingToDelete.smsReminderNumber || undefined,
cancelledBy: cancelledBy,
}).catch((e) => {
logger.error(
`Error executing webhook for event: ${eventTrigger}, URL: ${webhook.subscriberUrl}, bookingId: ${evt.bookingId}, bookingUid: ${evt.uid}`,
@@ -398,6 +399,7 @@ async function handler(req: CustomRequest) {
data: {
status: BookingStatus.CANCELLED,
cancellationReason: cancellationReason,
cancelledBy: cancelledBy,
},
});
const allUpdatedBookings = await prisma.booking.findMany({
@@ -440,6 +442,7 @@ async function handler(req: CustomRequest) {
data: {
status: BookingStatus.CANCELLED,
cancellationReason: cancellationReason,
cancelledBy: cancelledBy,
// Assume that canceling the booking is the last action
iCalSequence: evt.iCalSequence || 100,
},
@@ -110,6 +110,7 @@ describe("Cancel Booking", () => {
body: {
id: idOfBookingToBeCancelled,
uid: uidOfBookingToBeCancelled,
cancelledBy: organizer.email,
},
});
@@ -121,6 +122,7 @@ describe("Cancel Booking", () => {
location: BookingLocations.CalVideo,
subscriberUrl: "http://my-webhook.example.com",
payload: {
cancelledBy: organizer.email,
organizer: {
id: organizer.id,
username: organizer.username,
@@ -996,6 +996,7 @@ async function handler(
eventTrigger,
responses,
workflows,
rescheduledBy: reqBody.rescheduledBy,
});
if (newBooking) {
@@ -1066,6 +1067,7 @@ async function handler(
data: {
rescheduled: true,
status: BookingStatus.CANCELLED,
rescheduledBy: reqBody.rescheduledBy,
},
});
}
@@ -1561,6 +1563,7 @@ async function handler(
eventTypeId,
status: "ACCEPTED",
smsReminderNumber: booking?.smsReminderNumber || undefined,
rescheduledBy: reqBody.rescheduledBy,
};
if (bookingRequiresPayment) {
@@ -173,6 +173,7 @@ describe("handleNewBooking", () => {
name: booker.name,
location: { optionValue: "", value: BookingLocations.CalVideo },
},
rescheduledBy: organizer.email,
},
});
@@ -199,6 +200,7 @@ describe("handleNewBooking", () => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
uid: uidOfBookingToBeRescheduled,
status: BookingStatus.CANCELLED,
rescheduledBy: organizer.email,
});
expect(previousBooking?.status).toBe(BookingStatus.CANCELLED);
@@ -284,6 +286,9 @@ describe("handleNewBooking", () => {
location: BookingLocations.CalVideo,
subscriberUrl: "http://my-webhook.example.com",
videoCallUrl: `${WEBAPP_URL}/video/${createdBooking.uid}`,
payload: {
rescheduledBy: organizer.email,
},
});
},
timeout
@@ -1957,6 +1962,7 @@ describe("handleNewBooking", () => {
name: booker.name,
location: { optionValue: "", value: BookingLocations.CalVideo },
},
rescheduledBy: booker.email,
},
});
const { req } = createMockNextJsRequest({
@@ -1982,6 +1988,7 @@ describe("handleNewBooking", () => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
uid: uidOfBookingToBeRescheduled,
status: BookingStatus.CANCELLED,
rescheduledBy: booker.email,
});
expect(previousBooking?.status).toBe(BookingStatus.CANCELLED);
@@ -30,6 +30,7 @@ const handleSeats = async (newSeatedBookingObject: NewSeatedBookingObject) => {
eventTrigger,
evt,
workflows,
rescheduledBy,
} = newSeatedBookingObject;
const loggerWithEventDetails = createLoggerWithEventDetails(eventType.id, reqBodyUser, eventType.slug);
@@ -141,6 +142,7 @@ const handleSeats = async (newSeatedBookingObject: NewSeatedBookingObject) => {
eventTypeId,
status: "ACCEPTED",
smsReminderNumber: seatedBooking?.smsReminderNumber || undefined,
rescheduledBy,
};
await handleWebhookTrigger({ subscriberOptions, eventTrigger, webhookData });
@@ -2671,6 +2671,7 @@ describe("handleSeats", () => {
location: { optionValue: "", value: BookingLocations.CalVideo },
},
rescheduleUid: firstBookingUid,
cancelledBy: organizer.email,
},
});
@@ -2690,10 +2691,12 @@ describe("handleSeats", () => {
},
select: {
status: true,
cancelledBy: true,
},
});
expect(cancelledBooking?.status).toEqual(BookingStatus.CANCELLED);
expect(cancelledBooking?.cancelledBy).toEqual(organizer.email);
});
});
});
+1
View File
@@ -38,6 +38,7 @@ export type NewSeatedBookingObject = {
subscriberOptions: GetSubscriberOptions;
eventTrigger: WebhookTriggerEvents;
responses: z.infer<ReturnType<typeof getBookingDataSchema>>["responses"] | null;
rescheduledBy?: string;
workflows: Workflow[];
};
@@ -60,6 +60,8 @@ export type WebhookDataType = CalendarEvent &
createdAt: string;
downloadLink?: string;
paymentId?: number;
rescheduledBy?: string;
cancelledBy?: string;
paymentData?: Payment;
};