* 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>
239 lines
6.7 KiB
TypeScript
239 lines
6.7 KiB
TypeScript
import short from "short-uuid";
|
|
import { v5 as uuidv5 } from "uuid";
|
|
|
|
import type { CalendarEvent } from "@calcom/types/Calendar";
|
|
|
|
import { WEBAPP_URL } from "./constants";
|
|
import getLabelValueMapFromResponses from "./getLabelValueMapFromResponses";
|
|
|
|
const translator = short();
|
|
|
|
// The odd indentation in this file is necessary because otherwise the leading tabs will be applied into the event description.
|
|
|
|
export const getWhat = (calEvent: CalendarEvent) => {
|
|
return `
|
|
${calEvent.organizer.language.translate("what")}:
|
|
${calEvent.type}
|
|
`;
|
|
};
|
|
|
|
export const getWhen = (calEvent: CalendarEvent) => {
|
|
return calEvent.seatsPerTimeSlot
|
|
? `
|
|
${calEvent.organizer.language.translate("organizer_timezone")}:
|
|
${calEvent.organizer.timeZone}
|
|
`
|
|
: `
|
|
${calEvent.organizer.language.translate("invitee_timezone")}:
|
|
${calEvent.attendees[0].timeZone}
|
|
`;
|
|
};
|
|
|
|
export const getWho = (calEvent: CalendarEvent) => {
|
|
let attendeesFromCalEvent = [...calEvent.attendees];
|
|
if (calEvent.seatsPerTimeSlot && !calEvent.seatsShowAttendees) {
|
|
attendeesFromCalEvent = [];
|
|
}
|
|
const attendees = attendeesFromCalEvent
|
|
.map((attendee) => {
|
|
return `
|
|
${attendee?.name || calEvent.organizer.language.translate("guest")}
|
|
${attendee.email}
|
|
`;
|
|
})
|
|
.join("");
|
|
|
|
const organizer = `
|
|
${calEvent.organizer.name} - ${calEvent.organizer.language.translate("organizer")}
|
|
${calEvent.organizer.email}
|
|
`;
|
|
|
|
const teamMembers = calEvent.team?.members
|
|
? calEvent.team.members.map((member) => {
|
|
return `
|
|
${member.name} - ${calEvent.organizer.language.translate("team_member")}
|
|
${member.email}
|
|
`;
|
|
})
|
|
: [];
|
|
|
|
return `
|
|
${calEvent.organizer.language.translate("who")}:
|
|
${organizer + attendees + teamMembers.join("")}
|
|
`;
|
|
};
|
|
|
|
export const getAdditionalNotes = (calEvent: CalendarEvent) => {
|
|
if (!calEvent.additionalNotes) {
|
|
return "";
|
|
}
|
|
return `
|
|
${calEvent.organizer.language.translate("additional_notes")}:
|
|
${calEvent.additionalNotes}
|
|
`;
|
|
};
|
|
|
|
export const getUserFieldsResponses = (calEvent: CalendarEvent) => {
|
|
const labelValueMap = getLabelValueMapFromResponses(calEvent);
|
|
|
|
if (!labelValueMap) {
|
|
return "";
|
|
}
|
|
const responsesString = Object.keys(labelValueMap)
|
|
.map((key) => {
|
|
if (!labelValueMap) return "";
|
|
if (labelValueMap[key] !== "") {
|
|
return `
|
|
${key}:
|
|
${labelValueMap[key]}
|
|
`;
|
|
}
|
|
})
|
|
.join("");
|
|
|
|
return responsesString;
|
|
};
|
|
|
|
export const getAppsStatus = (calEvent: CalendarEvent) => {
|
|
if (!calEvent.appsStatus) {
|
|
return "";
|
|
}
|
|
return `\n${calEvent.organizer.language.translate("apps_status")}
|
|
${calEvent.appsStatus.map((app) => {
|
|
return `\n- ${app.appName} ${
|
|
app.success >= 1 ? `✅ ${app.success > 1 ? `(x${app.success})` : ""}` : ""
|
|
}${
|
|
app.warnings && app.warnings.length >= 1 ? app.warnings.map((warning) => `\n - ${warning}`) : ""
|
|
} ${app.failures && app.failures >= 1 ? `❌ ${app.failures > 1 ? `(x${app.failures})` : ""}` : ""} ${
|
|
app.errors && app.errors.length >= 1 ? app.errors.map((error) => `\n - ${error}`) : ""
|
|
}`;
|
|
})}
|
|
`;
|
|
};
|
|
|
|
export const getDescription = (calEvent: CalendarEvent) => {
|
|
if (!calEvent.description) {
|
|
return "";
|
|
}
|
|
return `\n${calEvent.organizer.language.translate("description")}
|
|
${calEvent.description}
|
|
`;
|
|
};
|
|
export const getLocation = (calEvent: CalendarEvent) => {
|
|
const meetingUrl = getVideoCallUrl(calEvent);
|
|
if (meetingUrl) {
|
|
return meetingUrl;
|
|
}
|
|
const providerName = getProviderName(calEvent);
|
|
return providerName || calEvent.location || "";
|
|
};
|
|
|
|
export const getProviderName = (calEvent: CalendarEvent): string => {
|
|
// TODO: use getAppName from @calcom/app-store
|
|
if (calEvent.location && calEvent.location.includes("integrations:")) {
|
|
let location = calEvent.location.split(":")[1];
|
|
if (location === "daily") {
|
|
location = "Cal Video";
|
|
}
|
|
return location[0].toUpperCase() + location.slice(1);
|
|
}
|
|
// If location its a url, probably we should be validating it with a custom library
|
|
if (calEvent.location && /^https?:\/\//.test(calEvent.location)) {
|
|
return calEvent.location;
|
|
}
|
|
return "";
|
|
};
|
|
|
|
export const getUid = (calEvent: CalendarEvent): string => {
|
|
const uid = calEvent.uid;
|
|
return uid ?? translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL));
|
|
};
|
|
|
|
const getSeatReferenceId = (calEvent: CalendarEvent): string => {
|
|
return calEvent.attendeeSeatId ? `seatReferenceUid=${calEvent.attendeeSeatId}` : "";
|
|
};
|
|
|
|
export const getManageLink = (calEvent: CalendarEvent) => {
|
|
return `
|
|
${calEvent.organizer.language.translate("need_to_reschedule_or_cancel")}
|
|
${WEBAPP_URL + "/booking/" + getUid(calEvent) + "?changes=true"}
|
|
`;
|
|
};
|
|
|
|
export const getCancelLink = (calEvent: CalendarEvent): string => {
|
|
return (
|
|
WEBAPP_URL +
|
|
`/booking/${getUid(
|
|
calEvent
|
|
)}?cancel=true&allRemainingBookings=${!!calEvent.recurringEvent}&${getSeatReferenceId}`
|
|
);
|
|
};
|
|
|
|
export const getRescheduleLink = (calEvent: CalendarEvent): string => {
|
|
const Uid = getUid(calEvent);
|
|
const seatUid = getSeatReferenceId(calEvent);
|
|
|
|
return `${WEBAPP_URL}/reschedule/${seatUid ? seatUid : Uid}`;
|
|
};
|
|
|
|
export const getRichDescription = (calEvent: CalendarEvent /*, attendee?: Person*/) => {
|
|
return `
|
|
${getCancellationReason(calEvent)}
|
|
${getWhat(calEvent)}
|
|
${getWhen(calEvent)}
|
|
${getWho(calEvent)}
|
|
${calEvent.organizer.language.translate("where")}:
|
|
${getLocation(calEvent)}
|
|
${getDescription(calEvent)}
|
|
${getAdditionalNotes(calEvent)}
|
|
${getUserFieldsResponses(calEvent)}
|
|
${getAppsStatus(calEvent)}
|
|
${
|
|
// TODO: Only the original attendee can make changes to the event
|
|
// Guests cannot
|
|
!calEvent.seatsPerTimeSlot && getManageLink(calEvent)
|
|
}
|
|
${
|
|
calEvent.paymentInfo
|
|
? `
|
|
${calEvent.organizer.language.translate("pay_now")}:
|
|
${calEvent.paymentInfo.link}
|
|
`
|
|
: ""
|
|
}
|
|
`.trim();
|
|
};
|
|
|
|
export const getCancellationReason = (calEvent: CalendarEvent) => {
|
|
if (!calEvent.cancellationReason) return "";
|
|
return `
|
|
${calEvent.organizer.language.translate("cancellation_reason")}:
|
|
${calEvent.cancellationReason}
|
|
`;
|
|
};
|
|
|
|
export const isDailyVideoCall = (calEvent: CalendarEvent): boolean => {
|
|
return calEvent?.videoCallData?.type === "daily_video";
|
|
};
|
|
|
|
export const getPublicVideoCallUrl = (calEvent: CalendarEvent): string => {
|
|
return WEBAPP_URL + "/video/" + getUid(calEvent);
|
|
};
|
|
|
|
export const getVideoCallUrl = (calEvent: CalendarEvent): string => {
|
|
if (calEvent.videoCallData) {
|
|
if (isDailyVideoCall(calEvent)) {
|
|
return getPublicVideoCallUrl(calEvent);
|
|
}
|
|
return calEvent.videoCallData.url;
|
|
}
|
|
if (calEvent.additionalInformation?.hangoutLink) {
|
|
return calEvent.additionalInformation.hangoutLink;
|
|
}
|
|
return "";
|
|
};
|
|
|
|
export const getVideoCallPassword = (calEvent: CalendarEvent): string => {
|
|
return isDailyVideoCall(calEvent) ? "" : calEvent?.videoCallData?.password ?? "";
|
|
};
|