* WIP-already-reschedule-success-emails-missing * WIP now saving bookingSeatsReferences and identifyin on reschedule/book page * Remove logs and created test * WIP saving progress * Select second slot to pass test * Delete attendee from event * Clean up * Update with main changes * Fix emails not being sent * Changed test end url from success to booking * Remove unused pkg * Fix new booking reschedule * remove log * Renable test * remove unused pkg * rename table name * review changes * Fix and and other test to reschedule with seats * Fix api for cancel booking * Typings * Update [uid].tsx * Abstracted common pattern into maybeGetBookingUidFromSeat * Reverts * Nitpicks * Update handleCancelBooking.ts * Adds missing cascades * Improve booking seats changes (#6858) * Create sendCancelledSeatEmails * Draft attendee cancelled seat email * Send no longer attendee email to attendee * Send email to organizer when attendee cancels * Pass cloned event data to emails * Send booked email for first seat * Add seat reference uid from email link * Query for seatReferenceUId and add to cancel & reschedule links * WIP * Display proper attendee when rescheduling seats * Remove console.logs * Only check for already invited when not rescheduling * WIP sending reschedule email to just single attendee and owner * Merge branch 'main' into send-email-on-seats-attendee-changes * Remove console.logs * Add cloned event to seat emails * Do not show manage link for calendar event * First seat, have both attendees on calendar * WIP refactor booking seats reschedule logic * WIP Refactor handleSeats * Change relation of attendee & seat reference to a one-to-one * Migration with relationship change * Booking page handling unique seat references * Abstract to handleSeats * Remove console.logs and clean up * New migration file, delete on cascade * Check if attendee is already a part of the booking * Move deleting booking logic to `handleSeats` * When owner reschedule, move whole booking * Prevent owner from rescheduling if not enough seats * Add owner reschedule * Send reschedule email when moving to new timeslot * Add event data to reschedule email for seats * Remove DB changes from event manager * When a booking has no attendees then delete * Update calendar when merging bookings * Move both attendees and seat references when merging * Remove guest list from seats booking page * Update original booking when moving an attendee * Delete calendar and video events if no more attendees * Update or delete integrations when attendees cancel * Show no longer attendee if a single attendee cancels * Change booking to accepted if an attendee books on an empty booking * If booking in same slot then just return the booking * Clean up * Clean up * Remove booking select * Typos --------- Co-authored-by: zomars <zomars@me.com> * Fix migration table name * Add missing trpc import * Rename bookingSeatReferences to bookingSeat * Change relationship between Attendee & BookingSeat to one to one * Fix some merge conflicts * Minor merge artifact fixup * Add the right 'Person' type * Check on email, less (although still) editable than name * Removed calEvent.attendeeUniqueId * rename referenceUId -> referenceUid * Squashes migrations * Run cached installs Should still be faster. Ensures prisma client is up to date. * Solve attendee form on booking page * Remove unused code * Some type fixes * Squash migrations * Type fixes * Fix for reschedule/[uid] redirect * Fix e2e test * Solve double declaration of host * Solve lint errors * Drop constraint only if exists * Renamed UId to Uid * Explicit vs. implicit * Attempt to work around text flakiness by adding a little break between animations * Various bugfixes * Persistently apply seatReferenceUid (#7545) * Persistently apply seatReferenceUid * Small ts fix * Setup guards correctly * Type fixes * Fix render 0 in conditional * Test refactoring * Fix type on handleSeats * Fix handle seats conditional * Fix type inference * Update packages/features/bookings/lib/handleNewBooking.ts * Update apps/web/components/booking/pages/BookingPage.tsx * Fix type and missing logic for reschedule * Fix delete of calendar event and booking * Add handleSeats return type * Fix seats booking creation * Fall through normal booking for initial booking, handleSeats for secondary/reschedule * Simplification of fetching booking * Enable seats for round-robin events * A lot harder than I expected * ignore-owner-if-seat-reference-given * Return seatReferenceUid when second seat * negate userIsOwner * Fix booking seats with a link without bookingUid * Needed a time check otherwise the attendee will be in the older booking * Can't open dialog twice in test.. * Allow passing the booking ID from the server * Fixed isCancelled check, fixed test * Delete through cascade instead of multiple deletes --------- Co-authored-by: Joe Au-Yeung <j.auyeung419@gmail.com> Co-authored-by: Peer Richelsen <peer@cal.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Efraín Rochín <roae.85@gmail.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com>
288 lines
9.9 KiB
TypeScript
288 lines
9.9 KiB
TypeScript
import { cloneDeep } from "lodash";
|
|
import type { TFunction } from "next-i18next";
|
|
|
|
import type { EventNameObjectType } from "@calcom/core/event";
|
|
import { getEventName } from "@calcom/core/event";
|
|
import type BaseEmail from "@calcom/emails/templates/_base-email";
|
|
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
|
|
|
import AttendeeAwaitingPaymentEmail from "./templates/attendee-awaiting-payment-email";
|
|
import AttendeeCancelledEmail from "./templates/attendee-cancelled-email";
|
|
import AttendeeCancelledSeatEmail from "./templates/attendee-cancelled-seat-email";
|
|
import AttendeeDeclinedEmail from "./templates/attendee-declined-email";
|
|
import AttendeeLocationChangeEmail from "./templates/attendee-location-change-email";
|
|
import AttendeeRequestEmail from "./templates/attendee-request-email";
|
|
import AttendeeRescheduledEmail from "./templates/attendee-rescheduled-email";
|
|
import AttendeeScheduledEmail from "./templates/attendee-scheduled-email";
|
|
import AttendeeWasRequestedToRescheduleEmail from "./templates/attendee-was-requested-to-reschedule-email";
|
|
import BrokenIntegrationEmail from "./templates/broken-integration-email";
|
|
import DisabledAppEmail from "./templates/disabled-app-email";
|
|
import type { Feedback } from "./templates/feedback-email";
|
|
import FeedbackEmail from "./templates/feedback-email";
|
|
import type { PasswordReset } from "./templates/forgot-password-email";
|
|
import ForgotPasswordEmail from "./templates/forgot-password-email";
|
|
import OrganizerAttendeeCancelledSeatEmail from "./templates/organizer-attendee-cancelled-seat-email";
|
|
import OrganizerCancelledEmail from "./templates/organizer-cancelled-email";
|
|
import OrganizerLocationChangeEmail from "./templates/organizer-location-change-email";
|
|
import OrganizerPaymentRefundFailedEmail from "./templates/organizer-payment-refund-failed-email";
|
|
import OrganizerRequestEmail from "./templates/organizer-request-email";
|
|
import OrganizerRequestReminderEmail from "./templates/organizer-request-reminder-email";
|
|
import OrganizerRequestedToRescheduleEmail from "./templates/organizer-requested-to-reschedule-email";
|
|
import OrganizerRescheduledEmail from "./templates/organizer-rescheduled-email";
|
|
import OrganizerScheduledEmail from "./templates/organizer-scheduled-email";
|
|
import type { TeamInvite } from "./templates/team-invite-email";
|
|
import TeamInviteEmail from "./templates/team-invite-email";
|
|
|
|
const sendEmail = (prepare: () => BaseEmail) => {
|
|
return new Promise((resolve, reject) => {
|
|
try {
|
|
const email = prepare();
|
|
resolve(email.sendEmail());
|
|
} catch (e) {
|
|
reject(console.error(`${prepare.constructor.name}.sendEmail failed`, e));
|
|
}
|
|
});
|
|
};
|
|
|
|
export const sendScheduledEmails = async (calEvent: CalendarEvent, eventNameObject?: EventNameObjectType) => {
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerScheduledEmail({ calEvent })));
|
|
|
|
if (calEvent.team) {
|
|
for (const teamMember of calEvent.team.members) {
|
|
emailsToSend.push(sendEmail(() => new OrganizerScheduledEmail({ calEvent, teamMember })));
|
|
}
|
|
}
|
|
|
|
emailsToSend.push(
|
|
...calEvent.attendees.map((attendee) => {
|
|
return sendEmail(
|
|
() =>
|
|
new AttendeeScheduledEmail(
|
|
{
|
|
...calEvent,
|
|
...(eventNameObject && {
|
|
title: getEventName({ ...eventNameObject, t: attendee.language.translate }),
|
|
}),
|
|
},
|
|
attendee
|
|
)
|
|
);
|
|
})
|
|
);
|
|
|
|
await Promise.all(emailsToSend);
|
|
};
|
|
|
|
export const sendRescheduledEmails = async (calEvent: CalendarEvent) => {
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerRescheduledEmail({ calEvent })));
|
|
|
|
if (calEvent.team) {
|
|
for (const teamMember of calEvent.team.members) {
|
|
emailsToSend.push(sendEmail(() => new OrganizerRescheduledEmail({ calEvent, teamMember })));
|
|
}
|
|
}
|
|
|
|
emailsToSend.push(
|
|
...calEvent.attendees.map((attendee) => {
|
|
return sendEmail(() => new AttendeeRescheduledEmail(calEvent, attendee));
|
|
})
|
|
);
|
|
|
|
await Promise.all(emailsToSend);
|
|
};
|
|
|
|
export const sendRescheduledSeatEmail = async (calEvent: CalendarEvent, attendee: Person) => {
|
|
const clonedCalEvent = cloneDeep(calEvent);
|
|
const emailsToSend: Promise<unknown>[] = [
|
|
sendEmail(() => new AttendeeRescheduledEmail(clonedCalEvent, attendee)),
|
|
sendEmail(() => new OrganizerRescheduledEmail({ calEvent })),
|
|
];
|
|
|
|
await Promise.all(emailsToSend);
|
|
};
|
|
|
|
export const sendScheduledSeatsEmails = async (
|
|
calEvent: CalendarEvent,
|
|
invitee: Person,
|
|
newSeat: boolean,
|
|
showAttendees: boolean
|
|
) => {
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerScheduledEmail({ calEvent, newSeat })));
|
|
|
|
if (calEvent.team) {
|
|
for (const teamMember of calEvent.team.members) {
|
|
emailsToSend.push(sendEmail(() => new OrganizerScheduledEmail({ calEvent, newSeat, teamMember })));
|
|
}
|
|
}
|
|
|
|
emailsToSend.push(sendEmail(() => new AttendeeScheduledEmail(calEvent, invitee, showAttendees)));
|
|
|
|
await Promise.all(emailsToSend);
|
|
};
|
|
|
|
export const sendCancelledSeatEmails = async (calEvent: CalendarEvent, cancelledAttendee: Person) => {
|
|
const clonedCalEvent = cloneDeep(calEvent);
|
|
await Promise.all([
|
|
sendEmail(() => new AttendeeCancelledSeatEmail(clonedCalEvent, cancelledAttendee)),
|
|
sendEmail(() => new OrganizerAttendeeCancelledSeatEmail({ calEvent })),
|
|
]);
|
|
};
|
|
|
|
export const sendOrganizerRequestEmail = async (calEvent: CalendarEvent) => {
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerRequestEmail({ calEvent })));
|
|
|
|
if (calEvent.team?.members) {
|
|
for (const teamMember of calEvent.team.members) {
|
|
emailsToSend.push(sendEmail(() => new OrganizerRequestEmail({ calEvent, teamMember })));
|
|
}
|
|
}
|
|
|
|
await Promise.all(emailsToSend);
|
|
};
|
|
|
|
export const sendAttendeeRequestEmail = async (calEvent: CalendarEvent, attendee: Person) => {
|
|
await sendEmail(() => new AttendeeRequestEmail(calEvent, attendee));
|
|
};
|
|
|
|
export const sendDeclinedEmails = async (calEvent: CalendarEvent) => {
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
emailsToSend.push(
|
|
...calEvent.attendees.map((attendee) => {
|
|
return sendEmail(() => new AttendeeDeclinedEmail(calEvent, attendee));
|
|
})
|
|
);
|
|
|
|
await Promise.all(emailsToSend);
|
|
};
|
|
|
|
export const sendCancelledEmails = async (calEvent: CalendarEvent) => {
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerCancelledEmail({ calEvent })));
|
|
|
|
if (calEvent.team?.members) {
|
|
for (const teamMember of calEvent.team.members) {
|
|
emailsToSend.push(sendEmail(() => new OrganizerCancelledEmail({ calEvent, teamMember })));
|
|
}
|
|
}
|
|
|
|
emailsToSend.push(
|
|
...calEvent.attendees.map((attendee) => {
|
|
return sendEmail(() => new AttendeeCancelledEmail(calEvent, attendee));
|
|
})
|
|
);
|
|
|
|
await Promise.all(emailsToSend);
|
|
};
|
|
|
|
export const sendOrganizerRequestReminderEmail = async (calEvent: CalendarEvent) => {
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerRequestReminderEmail({ calEvent })));
|
|
|
|
if (calEvent.team?.members) {
|
|
for (const teamMember of calEvent.team.members) {
|
|
emailsToSend.push(sendEmail(() => new OrganizerRequestReminderEmail({ calEvent, teamMember })));
|
|
}
|
|
}
|
|
};
|
|
|
|
export const sendAwaitingPaymentEmail = async (calEvent: CalendarEvent) => {
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
emailsToSend.push(
|
|
...calEvent.attendees.map((attendee) => {
|
|
return sendEmail(() => new AttendeeAwaitingPaymentEmail(calEvent, attendee));
|
|
})
|
|
);
|
|
await Promise.all(emailsToSend);
|
|
};
|
|
|
|
export const sendOrganizerPaymentRefundFailedEmail = async (calEvent: CalendarEvent) => {
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
emailsToSend.push(sendEmail(() => new OrganizerPaymentRefundFailedEmail({ calEvent })));
|
|
|
|
if (calEvent.team?.members) {
|
|
for (const teamMember of calEvent.team.members) {
|
|
emailsToSend.push(sendEmail(() => new OrganizerPaymentRefundFailedEmail({ calEvent, teamMember })));
|
|
}
|
|
}
|
|
|
|
await Promise.all(emailsToSend);
|
|
};
|
|
|
|
export const sendPasswordResetEmail = async (passwordResetEvent: PasswordReset) => {
|
|
await sendEmail(() => new ForgotPasswordEmail(passwordResetEvent));
|
|
};
|
|
|
|
export const sendTeamInviteEmail = async (teamInviteEvent: TeamInvite) => {
|
|
await sendEmail(() => new TeamInviteEmail(teamInviteEvent));
|
|
};
|
|
|
|
export const sendRequestRescheduleEmail = async (
|
|
calEvent: CalendarEvent,
|
|
metadata: { rescheduleLink: string }
|
|
) => {
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerRequestedToRescheduleEmail(calEvent, metadata)));
|
|
|
|
emailsToSend.push(sendEmail(() => new AttendeeWasRequestedToRescheduleEmail(calEvent, metadata)));
|
|
|
|
await Promise.all(emailsToSend);
|
|
};
|
|
|
|
export const sendLocationChangeEmails = async (calEvent: CalendarEvent) => {
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
emailsToSend.push(sendEmail(() => new OrganizerLocationChangeEmail({ calEvent })));
|
|
|
|
if (calEvent.team?.members) {
|
|
for (const teamMember of calEvent.team.members) {
|
|
emailsToSend.push(sendEmail(() => new OrganizerLocationChangeEmail({ calEvent, teamMember })));
|
|
}
|
|
}
|
|
|
|
emailsToSend.push(
|
|
...calEvent.attendees.map((attendee) => {
|
|
return sendEmail(() => new AttendeeLocationChangeEmail(calEvent, attendee));
|
|
})
|
|
);
|
|
|
|
await Promise.all(emailsToSend);
|
|
};
|
|
export const sendFeedbackEmail = async (feedback: Feedback) => {
|
|
await sendEmail(() => new FeedbackEmail(feedback));
|
|
};
|
|
|
|
export const sendBrokenIntegrationEmail = async (evt: CalendarEvent, type: "video" | "calendar") => {
|
|
await sendEmail(() => new BrokenIntegrationEmail(evt, type));
|
|
};
|
|
|
|
export const sendDisabledAppEmail = async ({
|
|
email,
|
|
appName,
|
|
appType,
|
|
t,
|
|
title = undefined,
|
|
eventTypeId = undefined,
|
|
}: {
|
|
email: string;
|
|
appName: string;
|
|
appType: string[];
|
|
t: TFunction;
|
|
title?: string;
|
|
eventTypeId?: number;
|
|
}) => {
|
|
await sendEmail(() => new DisabledAppEmail(email, appName, appType, t, title, eventTypeId));
|
|
};
|