Direct links to accept/reject a booking (#5939)

* Impl

* Added reason

* Secondary reject CTA

* Update packages/emails/src/components/Info.tsx

* Adjusting recurring info

* Not showing reason for rejecting if none given

* Feedback

* Error handling + style fixes

Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
Leo GiovanettiandPeer Richelsen authored and GitHub committed 2022-12-13 22:09:28 +01:00
1 parent 2e6c3a6068
commit 61e6f76bc6
16 files changed
+1018 -478

No files matched your search

@@ -1,30 +1,33 @@
import { LinkIcon } from "./LinkIcon";
export const CallToAction = (props: { label: string; href: string }) => (
export const CallToAction = (props: { label: string; href: string; secondary?: boolean }) => (
<p
style={{
display: "inline-block",
background: "#292929",
background: props.secondary ? "#FFFFFF" : "#292929",
border: props.secondary ? "1px solid #d1d5db" : "",
color: "#ffffff",
fontFamily: "Roboto, Helvetica, sans-serif",
fontSize: "16px",
fontSize: "14px",
fontWeight: 500,
lineHeight: "120%",
lineHeight: "20px",
margin: 0,
textDecoration: "none",
textTransform: "none",
padding: "10px 25px",
padding: "10px 16px",
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
msoPaddingAlt: "0px",
borderRadius: "3px",
borderRadius: "6px",
boxSizing: "border-box",
}}>
<a
style={{ color: "#FFFFFF", textDecoration: "none" }}
style={{ color: props.secondary ? "#292929" : "#FFFFFF", textDecoration: "none" }}
href={props.href}
target="_blank"
rel="noreferrer">
{props.label} <LinkIcon />
{props.label}
<LinkIcon secondary />
</a>
</p>
);
@@ -4,7 +4,6 @@ export const CallToActionTable = (props: { children: React.ReactNode }) => (
<tr>
<td
align="center"
bgcolor="#292929"
role="presentation"
style={{
border: "none",
@@ -13,7 +12,6 @@ export const CallToActionTable = (props: { children: React.ReactNode }) => (
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
msoPaddingAlt: "10px 25px",
background: "#292929",
}}
valign="middle">
{props.children}
+4 -2
View File
@@ -1,9 +1,11 @@
import { BASE_URL, IS_PRODUCTION } from "@calcom/lib/constants";
export const LinkIcon = () => (
export const LinkIcon = ({ secondary }: { secondary?: boolean }) => (
<img
src={IS_PRODUCTION ? BASE_URL + "/emails/linkIcon.png" : "https://app.cal.com/emails/linkIcon.png"}
width="12px"
srcSet={IS_PRODUCTION ? BASE_URL + "/emails/linkIcon.svg" : "https://app.cal.com/emails/linkIcon.svg"}
width="16px"
style={{ marginBottom: "-3px", marginLeft: "8px", ...(secondary && { filter: "brightness(80%)" }) }}
alt=""
/>
);
@@ -0,0 +1,3 @@
export const Separator = () => (
<p style={{ width: "16px", height: "16px", display: "inline-block" }}>&nbsp;</p>
);
+19 -8
View File
@@ -3,21 +3,27 @@ import { RRule } from "rrule";
import dayjs from "@calcom/dayjs";
import { getEveryFreqFor } from "@calcom/lib/recurringStrings";
import type { CalendarEvent } from "@calcom/types/Calendar";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import type { RecurringEvent } from "@calcom/types/Calendar";
import { Info } from "./Info";
function getRecurringWhen({ calEvent }: { calEvent: CalendarEvent }) {
if (calEvent.recurringEvent) {
const t = calEvent.attendees[0].language.translate;
const rruleOptions = new RRule(calEvent.recurringEvent).options;
const recurringEvent: RecurringEvent = {
export function getRecurringWhen({
recurringEvent,
attendee,
}: {
recurringEvent?: RecurringEvent | null;
attendee: Pick<Person, "language">;
}) {
if (recurringEvent) {
const t = attendee.language.translate;
const rruleOptions = new RRule(recurringEvent).options;
const recurringEventConfig: RecurringEvent = {
freq: rruleOptions.freq,
count: rruleOptions.count || 1,
interval: rruleOptions.interval,
};
return ` - ${getEveryFreqFor({ t, recurringEvent })}`;
return `${getEveryFreqFor({ t, recurringEvent: recurringEventConfig })}`;
}
return "";
}
@@ -33,10 +39,15 @@ export function WhenInfo(props: { calEvent: CalendarEvent; timeZone: string; t:
return dayjs(props.calEvent.endTime).tz(timeZone).format(format);
}
const recurringInfo = getRecurringWhen({
recurringEvent: props.calEvent.recurringEvent,
attendee: props.calEvent.attendees[0],
});
return (
<div>
<Info
label={`${t("when")} ${getRecurringWhen(props)}`}
label={`${t("when")} ${recurringInfo !== "" ? ` - ${recurringInfo}` : ""}`}
lineThrough={
!!props.calEvent.cancellationReason && !props.calEvent.cancellationReason.includes("$RCH$")
}
+1
View File
@@ -11,3 +11,4 @@ export { default as RawHtml } from "./RawHtml";
export { WhenInfo } from "./WhenInfo";
export { WhoInfo } from "./WhoInfo";
export { AppsStatus } from "./AppsStatus";
export { Separator } from "./Separator";
@@ -1,27 +1,42 @@
import { CallToAction, CallToActionTable } from "../components";
import { createHmac } from "crypto";
import { CallToAction, CallToActionTable, Separator } from "../components";
import { OrganizerScheduledEmail } from "./OrganizerScheduledEmail";
export const OrganizerRequestEmail = (props: React.ComponentProps<typeof OrganizerScheduledEmail>) => (
<OrganizerScheduledEmail
title={
props.title || props.calEvent.recurringEvent?.count
? "event_awaiting_approval_recurring"
: "event_awaiting_approval"
}
subtitle={<>{props.calEvent.organizer.language.translate("someone_requested_an_event")}</>}
headerType="calendarCircle"
subject="event_awaiting_approval_subject"
callToAction={
<CallToActionTable>
<CallToAction
label={props.calEvent.organizer.language.translate("confirm_or_reject_request")}
href={
process.env.NEXT_PUBLIC_WEBAPP_URL +
(props.calEvent.recurringEvent?.count ? "/bookings/recurring" : "/bookings/upcoming")
}
/>
</CallToActionTable>
}
{...props}
/>
);
const CALENDSO_ENCRYPTION_KEY = process.env.CALENDSO_ENCRYPTION_KEY || "";
export const OrganizerRequestEmail = (props: React.ComponentProps<typeof OrganizerScheduledEmail>) => {
const signedData = `${props.attendee.email}/${props.calEvent.uid}`;
const signature = createHmac("sha1", CALENDSO_ENCRYPTION_KEY).update(signedData).digest("base64");
return (
<OrganizerScheduledEmail
title={
props.title || props.calEvent.recurringEvent?.count
? "event_awaiting_approval_recurring"
: "event_awaiting_approval"
}
subtitle={<>{props.calEvent.organizer.language.translate("someone_requested_an_event")}</>}
headerType="calendarCircle"
subject="event_awaiting_approval_subject"
callToAction={
<CallToActionTable>
<CallToAction
label={props.calEvent.organizer.language.translate("accept")}
href={`${process.env.NEXT_PUBLIC_WEBAPP_URL}/booking/direct/accept/${encodeURIComponent(
props.attendee.email
)}/${encodeURIComponent(props.calEvent.uid as string)}/${encodeURIComponent(signature)}`}
/>
<Separator />
<CallToAction
label={props.calEvent.organizer.language.translate("reject")}
secondary
href={`${process.env.NEXT_PUBLIC_WEBAPP_URL}/booking/direct/reject/${encodeURIComponent(
props.attendee.email
)}/${encodeURIComponent(props.calEvent.uid as string)}/${encodeURIComponent(signature)}`}
/>
</CallToActionTable>
}
{...props}
/>
);
};