Skip to content

Commit

Permalink
Merge pull request #476 from ITPNYU/revert-474-revert-473-main
Browse files Browse the repository at this point in the history
Revert "Revert "Prod Release 11/1""
  • Loading branch information
rlho authored Nov 5, 2024
2 parents a13721a + 04289e2 commit 3453819
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 505 deletions.
34 changes: 15 additions & 19 deletions booking-app/app/api/bookings/route.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
import {
BookingFormDetails,
BookingStatusLabel,
RoomSetting,
} from "@/components/src/types";
import { NextRequest, NextResponse } from "next/server";
import {
approvalUrl,
declineUrl,
getBookingToolDeployUrl,
} from "@/components/src/server/ui";
import { deleteEvent, insertEvent } from "@/components/src/server/calendars";
serverFormatDate,
toFirebaseTimestampFromString,
} from "@/components/src/client/utils/serverDate";
import {
firstApproverEmails,
serverApproveInstantBooking,
serverBookingContents,
serverDeleteFieldsByCalendarEventId,
serverUpdateDataByCalendarEventId,
} from "@/components/src/server/admin";
import { deleteEvent, insertEvent } from "@/components/src/server/calendars";
import { getBookingToolDeployUrl } from "@/components/src/server/ui";
import {
serverFormatDate,
toFirebaseTimestampFromString,
} from "@/components/src/client/utils/serverDate";
ApproverType,
BookingFormDetails,
BookingStatusLabel,
RoomSetting,
} from "@/components/src/types";
import {
serverGetNextSequentialId,
serverSaveDataToFirestore,
} from "@/lib/firebase/server/adminDb";
import { NextRequest, NextResponse } from "next/server";

import { DateSelectArg } from "fullcalendar";
import { sendHTMLEmail } from "@/app/lib/sendHTMLEmail";
import { TableNames } from "@/components/src/policy";
import { Timestamp } from "firebase-admin/firestore";
import { sendHTMLEmail } from "@/app/lib/sendHTMLEmail";
import { DateSelectArg } from "fullcalendar";

async function createBookingCalendarEvent(
selectedRooms: RoomSetting[],
Expand Down Expand Up @@ -88,7 +85,7 @@ async function handleBookingApprovalEmails(
);
const emailPromises = recipients.map(recipient =>
sendHTMLEmail({
templateName: "approval_email",
templateName: "booking_detail",
contents: {
...otherContentsStrings,
roomId: selectedRoomIds,
Expand All @@ -101,6 +98,7 @@ async function handleBookingApprovalEmails(
eventTitle: contents.title,
requestNumber: contents.requestNumber ?? sequentialId,
body: "",
approverType: ApproverType.LIAISON,
}),
);
await Promise.all(emailPromises);
Expand All @@ -117,8 +115,6 @@ async function handleBookingApprovalEmails(
email,
startDate: bookingCalendarInfo?.startStr,
endDate: bookingCalendarInfo?.endStr,
approvalUrl: approvalUrl(calendarEventId),
declineUrl: declineUrl(calendarEventId),
bookingToolUrl: getBookingToolDeployUrl(),
headerMessage: "This is a request email for first approval.",
requestNumber: sequentialId,
Expand Down
2 changes: 2 additions & 0 deletions booking-app/app/api/sendEmail/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export async function POST(req: NextRequest) {
eventTitle,
requestNumber,
bodyMessage,
approverType,
} = await req.json();

// if (!templateName || !contents || !targetEmail || !status || !eventTitle) {
Expand All @@ -29,6 +30,7 @@ export async function POST(req: NextRequest) {
eventTitle,
requestNumber,
body: bodyMessage || "",
approverType,
});
return NextResponse.json(
{ message: "Email sent successfully" },
Expand Down
17 changes: 16 additions & 1 deletion booking-app/app/liaison/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
"use client";

import Liaison from "@/components/src/client/routes/liaison/Liaison";
import { useSearchParams } from "next/navigation";
import { Suspense } from "react";

const LiaisonPage: React.FC = () => <Liaison />;
const LiaisonWithParams: React.FC = () => {
const searchParams = useSearchParams();
const calendarEventId = searchParams.get("calendarEventId");

return <Liaison calendarEventId={calendarEventId} />;
};

const LiaisonPage: React.FC = () => {
return (
<Suspense fallback={<div>Loading...</div>}>
<LiaisonWithParams />
</Suspense>
);
};

export default LiaisonPage;
35 changes: 29 additions & 6 deletions booking-app/app/lib/sendHTMLEmail.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { approvalUrl, declineUrl } from "@/components/src/server/ui";

import fs from "fs";
import { serverFormatDate } from "@/components/src/client/utils/serverDate";
import { getEmailBranchTag } from "@/components/src/server/emails";
import { ApproverType } from "@/components/src/types";
import { getGmailClient } from "@/lib/googleClient";
import fs from "fs";
import path from "path";
import { serverFormatDate } from "@/components/src/client/utils/serverDate";

let Handlebars;

Expand All @@ -24,6 +23,7 @@ interface SendHTMLEmailParams {
eventTitle: string;
requestNumber: number;
body: string;
approverType?: ApproverType;
}

export const sendHTMLEmail = async (params: SendHTMLEmailParams) => {
Expand All @@ -35,17 +35,41 @@ export const sendHTMLEmail = async (params: SendHTMLEmailParams) => {
eventTitle,
requestNumber,
body,
approverType,
} = params;

const subj = `${getEmailBranchTag()}${status} - Media Commons request #${requestNumber}: "${eventTitle}"`;

const getUrlPathByApproverType = (
calendarEventId,
approverType?: ApproverType,
): string => {
let path: string;
switch (approverType) {
case ApproverType.LIAISON:
path = "/liaison";
break;
case ApproverType.FINAL_APPROVER:
path = "/admin";
break;
default:
path = "/";
}

return `${process.env.NEXT_PUBLIC_BASE_URL}${path}?calendarEventId=${calendarEventId}`;
};

const templatePath = path.join(
process.cwd(),
"app/templates",
`${templateName}.html`,
);
const templateSource = fs.readFileSync(templatePath, "utf8");
const template = Handlebars.compile(templateSource);
const approvalUrl = getUrlPathByApproverType(
contents.calendarEventId,
approverType,
);

const htmlBody = template({
eventTitle,
Expand All @@ -54,8 +78,7 @@ export const sendHTMLEmail = async (params: SendHTMLEmailParams) => {
contents,
startDate: serverFormatDate(contents.startDate),
endDate: serverFormatDate(contents.endDate),
approvalUrl: approvalUrl(contents.calendarEventId),
declineUrl: declineUrl(contents.calendarEventId),
approvalUrl,
});

const messageParts = [
Expand Down
114 changes: 0 additions & 114 deletions booking-app/app/templates/approval_email.html

This file was deleted.

Loading

0 comments on commit 3453819

Please sign in to comment.