Apps Status + Updates to non-traditional calendars (#5034)
* Apps Status + Updates to non-traditional calendars * Recurring booking tweaks * Last tweaks * Fixing checks * Fixing eslint * Reverting unneeded changes, using plain text email * More unneeded changes revert * Update packages/features/bookings/lib/handleNewBooking.ts Co-authored-by: Omar López <zomars@me.com> * Fixing lint * Refactored appsStatus in emails * Update packages/emails/src/templates/OrganizerScheduledEmail.tsx Co-authored-by: Omar López <zomars@me.com>
This commit is contained in:
1 parent
f298865d9e
commit
b6be94fd14
16 files changed
+220
-38
No files matched your search
@@ -1,22 +1,46 @@
|
||||
import { AppsStatus } from "@calcom/types/Calendar";
|
||||
|
||||
import * as fetch from "@lib/core/http/fetch-wrapper";
|
||||
import { BookingCreateBody, BookingResponse } from "@lib/types/booking";
|
||||
|
||||
type ExtendedBookingCreateBody = BookingCreateBody & { noEmail?: boolean; recurringCount?: number };
|
||||
|
||||
const createRecurringBooking = async (data: ExtendedBookingCreateBody[]) => {
|
||||
return Promise.all(
|
||||
data.map((booking, key) => {
|
||||
// We only want to send the first occurrence of the meeting at the moment, not all at once
|
||||
if (key === 0) {
|
||||
return fetch.post<ExtendedBookingCreateBody, BookingResponse>("/api/book/event", booking);
|
||||
} else {
|
||||
return fetch.post<ExtendedBookingCreateBody, BookingResponse>("/api/book/event", {
|
||||
...booking,
|
||||
noEmail: true,
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
const createdBookings: BookingResponse[] = [];
|
||||
// Reversing to accumulate results for noEmail instances first, to then lastly, create the
|
||||
// emailed booking taking into account accumulated results to send app status accurately
|
||||
for (let key = 0; key < data.length; key++) {
|
||||
const booking = data[key];
|
||||
if (key === data.length - 1) {
|
||||
const calcAppsStatus: { [key: string]: AppsStatus } = createdBookings
|
||||
.flatMap((book) => (book.appsStatus !== undefined ? book.appsStatus : []))
|
||||
.reduce((prev, curr) => {
|
||||
if (prev[curr.type]) {
|
||||
prev[curr.type].failures += curr.failures;
|
||||
prev[curr.type].success += curr.success;
|
||||
} else {
|
||||
prev[curr.type] = curr;
|
||||
}
|
||||
return prev;
|
||||
}, {} as { [key: string]: AppsStatus });
|
||||
const appsStatus = Object.values(calcAppsStatus);
|
||||
const response = await fetch.post<
|
||||
ExtendedBookingCreateBody & { appsStatus: AppsStatus[] },
|
||||
BookingResponse
|
||||
>("/api/book/event", {
|
||||
...booking,
|
||||
appsStatus,
|
||||
});
|
||||
createdBookings.push(response);
|
||||
} else {
|
||||
const response = await fetch.post<ExtendedBookingCreateBody, BookingResponse>("/api/book/event", {
|
||||
...booking,
|
||||
noEmail: true,
|
||||
});
|
||||
createdBookings.push(response);
|
||||
}
|
||||
}
|
||||
return createdBookings;
|
||||
};
|
||||
|
||||
export default createRecurringBooking;
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Attendee, Booking } from "@prisma/client";
|
||||
|
||||
import { AppsStatus } from "@calcom/types/Calendar";
|
||||
|
||||
export type BookingCreateBody = {
|
||||
email: string;
|
||||
end: string;
|
||||
@@ -33,4 +35,5 @@ export type BookingCreateBody = {
|
||||
export type BookingResponse = Booking & {
|
||||
paymentUid?: string;
|
||||
attendees: Attendee[];
|
||||
appsStatus?: AppsStatus[];
|
||||
};
|
||||
@@ -543,6 +543,7 @@
|
||||
"link_shared": "Link shared!",
|
||||
"title": "Title",
|
||||
"description": "Description",
|
||||
"apps_status": "Apps Status",
|
||||
"quick_video_meeting": "A quick video meeting.",
|
||||
"scheduling_type": "Scheduling Type",
|
||||
"preview_team": "Preview team",
|
||||
|
||||
Reference in new issue
Block a user