Skip to content

Commit

Permalink
Merge pull request #474 from ITPNYU/revert-473-main
Browse files Browse the repository at this point in the history
Revert "Prod Release 11/1"
  • Loading branch information
rlho authored Nov 1, 2024
2 parents b52c45d + 3bd91a1 commit a13721a
Show file tree
Hide file tree
Showing 17 changed files with 505 additions and 274 deletions.
34 changes: 19 additions & 15 deletions booking-app/app/api/bookings/route.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
import {
serverFormatDate,
toFirebaseTimestampFromString,
} from "@/components/src/client/utils/serverDate";
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";
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 {
ApproverType,
BookingFormDetails,
BookingStatusLabel,
RoomSetting,
} from "@/components/src/types";
serverFormatDate,
toFirebaseTimestampFromString,
} from "@/components/src/client/utils/serverDate";
import {
serverGetNextSequentialId,
serverSaveDataToFirestore,
} from "@/lib/firebase/server/adminDb";
import { NextRequest, NextResponse } from "next/server";

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

async function createBookingCalendarEvent(
selectedRooms: RoomSetting[],
Expand Down Expand Up @@ -85,7 +88,7 @@ async function handleBookingApprovalEmails(
);
const emailPromises = recipients.map(recipient =>
sendHTMLEmail({
templateName: "booking_detail",
templateName: "approval_email",
contents: {
...otherContentsStrings,
roomId: selectedRoomIds,
Expand All @@ -98,7 +101,6 @@ async function handleBookingApprovalEmails(
eventTitle: contents.title,
requestNumber: contents.requestNumber ?? sequentialId,
body: "",
approverType: ApproverType.LIAISON,
}),
);
await Promise.all(emailPromises);
Expand All @@ -115,6 +117,8 @@ 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: 0 additions & 2 deletions booking-app/app/api/sendEmail/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export async function POST(req: NextRequest) {
eventTitle,
requestNumber,
bodyMessage,
approverType,
} = await req.json();

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

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

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>
);
};
const LiaisonPage: React.FC = () => <Liaison />;

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

import fs from "fs";
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 @@ -23,7 +24,6 @@ interface SendHTMLEmailParams {
eventTitle: string;
requestNumber: number;
body: string;
approverType?: ApproverType;
}

export const sendHTMLEmail = async (params: SendHTMLEmailParams) => {
Expand All @@ -35,41 +35,17 @@ 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 @@ -78,7 +54,8 @@ export const sendHTMLEmail = async (params: SendHTMLEmailParams) => {
contents,
startDate: serverFormatDate(contents.startDate),
endDate: serverFormatDate(contents.endDate),
approvalUrl,
approvalUrl: approvalUrl(contents.calendarEventId),
declineUrl: declineUrl(contents.calendarEventId),
});

const messageParts = [
Expand Down
114 changes: 114 additions & 0 deletions booking-app/app/templates/approval_email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<!doctype html>
<html>
<head>
<style>
.container {
width: 100%;
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}

.button {
cursor: pointer;
outline: 0;
display: inline-block;
font-weight: 400;
line-height: 1.5;
text-align: center;
background-color: transparent;
border: 1px solid transparent;
padding: 6px 12px;
font-size: 1rem;
border-radius: 0.25rem;
transition:
color 0.15s ease-in-out,
background-color 0.15s ease-in-out,
border-color 0.15s ease-in-out,
box-shadow 0.15s ease-in-out;
color: #0d6efd;
border-color: #0d6efd;
:hover {
color: #fff;
background-color: #0d6efd;
border-color: #0d6efd;
}
}

.button:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(4px);
}

.button-red {
padding: 8px 12px;
border: 1px solid #ed2939;
border-radius: 2px;
font-family: Helvetica, Arial, sans-serif;
font-size: 14px;
color: #ffffff;
text-decoration: none;
font-weight: bold;
display: inline-block;
}

.button-red:active {
background-color: #8b0000;
}
</style>
</head>
<body>
<div id="index"></div>
<div class="container">
<p>{{ contents.headerMessage }}</p>
</div>
<div class="container">
<h2>Room Reservation Request</h2>
<p>Room Number: {{ contents.roomId }}</p>

<p>First name: {{ contents.firstName }}</p>
<p>Last name: {{ contents.lastName }}</p>

<p>Email: {{ contents.email }}</p>
<p>Start date: {{ startDate }}</p>
<p>End date: {{ endDate }}</p>
<p>Secondary Point of Contact: {{ contents.secondaryName }}</p>
<p>NYU N-number: {{ contents.nNumber }}</p>
<p>Net Id: {{ contents.netId }}</p>
<p>Phone Number: {{ contents.phoneNumber }}</p>
<p>Department: {{ contents.department }}</p>
<p>Requestor's Role: {{ contents.role}}</p>
<p>Sponsor First Name: {{ contents.sponsorFirstName }}</p>
<p>Sponsor Last Name: {{ contents.sponsorLastName }}</p>
<p>Sponsor Email: {{ contents.sponsorEmail }}</p>
<p>Title: {{ contents.title }}</p>
<p>Description: {{ contents.description }}</p>
<p>Booking Type: {{ contents.bookingType }}</p>
<p>Expected Attendance: {{ contents.expectedAttendance }}</p>
<p>Attendee Affiliations: {{ contents.attendeeAffiliation }}</p>
<p>
Room setup needed?: {{ contents.roomSetup }} {{ contents.setupDetails }}
</p>
<p>Chartfield for Room setup?: {{ contents.chartFieldForRoomSetup }}</p>
<p>
Media Services: {{ contents.mediaServices }} {{
contents.mediaServicesDetails }}
</p>
<p>Catering: {{ contents.catering }}</p>
<p>Catering Details: {{ contents.cateringService }}</p>
<p>Chartfield for Catering?: {{ contents.chartFieldForCatering }}</p>
<p>Hire Security: {{ contents.hireSecurity }}</p>
<p>
Chartfield for Hiring Security?: {{ contents.chartFieldForSecurity }}
</p>

<a href="{{ approvalUrl }}" target="_blank" class="button">Approve</a>
<a href="{{ declineUrl }}" target="_blank" class="button-red">Decline</a>
<a href="{{ contents.bookingToolUrl }}" target="_blank" class="button"
>Open Booking Tool</a
>
</div>
</body>
</html>
Loading

0 comments on commit a13721a

Please sign in to comment.