Skip to content

Commit

Permalink
Merge pull request #430 from ITPNYU/main
Browse files Browse the repository at this point in the history
Prod Release 0926
  • Loading branch information
rlho authored Sep 26, 2024
2 parents 3656b90 + f634554 commit 9392264
Show file tree
Hide file tree
Showing 50 changed files with 1,278 additions and 640 deletions.
57 changes: 57 additions & 0 deletions booking-app/app/api/bookings/export/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Booking, BookingStatus } from "@/components/src/types";
import { NextRequest, NextResponse } from "next/server";

import { TableNames } from "@/components/src/policy";
import { parse } from "json2csv";
import { serverFetchAllDataFromCollection } from "@/lib/firebase/server/adminDb";

export async function GET(request: NextRequest) {
const bookings = await serverFetchAllDataFromCollection<Booking>(
TableNames.BOOKING,
);
const statuses = await serverFetchAllDataFromCollection<BookingStatus>(
TableNames.BOOKING_STATUS,
);

// need to find corresponding status row for booking row
const idsToData: {
[key: string]: {
booking: Booking;
status: BookingStatus;
};
} = {};

for (let booking of bookings) {
const calendarEventId = booking.calendarEventId;
const statusMatch = statuses.filter(
row => row.calendarEventId === calendarEventId,
)[0];
idsToData[calendarEventId] = {
booking,
status: statusMatch,
};
}

const rows = Object.entries(idsToData)
.map(([_, { booking, status }]) => {
const { requestNumber, ...otherBooking } = booking;
return { requestNumber, ...otherBooking, ...status };
})
.sort((a, b) => a.requestNumber - b.requestNumber);

try {
const csv = parse(rows);
return new NextResponse(csv, {
status: 200,
headers: {
"Content-Type": "text/csv",
"Content-Disposition": 'attachment; filename="data.csv"',
},
});
} catch (error) {
return NextResponse.json(
{ error: "Failed to fetch CSV data" },
{ status: 400 },
);
}
}
29 changes: 19 additions & 10 deletions booking-app/app/api/bookings/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@ import {
declineUrl,
getBookingToolDeployUrl,
} from "@/components/src/server/ui";
import { deleteEvent, insertEvent } from "@/components/src/server/calendars";
import {
firstApproverEmails,
serverApproveInstantBooking,
serverBookingContents,
serverDeleteDataByCalendarEventId,
serverUpdateDataByCalendarEventId,
} from "@/components/src/server/admin";
import { deleteEvent, insertEvent } from "@/components/src/server/calendars";
import {
serverFormatDate,
toFirebaseTimestampFromString,
} from "@/components/src/client/utils/serverDate";
import {
serverGetNextSequentialId,
serverSaveDataToFirestore,
} from "@/lib/firebase/server/adminDb";

import { DateSelectArg } from "fullcalendar";
import { TableNames } from "@/components/src/policy";
import { Timestamp } from "firebase-admin/firestore";
import { sendHTMLEmail } from "@/app/lib/sendHTMLEmail";
import {
serverGetNextSequentialId,
serverSaveDataToFirestore,
} from "@/lib/firebase/server/adminDb";
import {
serverFormatDate,
toFirebaseTimestampFromString,
} from "@/components/src/client/utils/serverDate";

async function createBookingCalendarEvent(
selectedRooms: RoomSetting[],
Expand Down Expand Up @@ -188,6 +189,7 @@ export async function PUT(request: NextRequest) {
const {
email,
selectedRooms,
allRooms,
bookingCalendarInfo,
data,
isAutoApproval,
Expand All @@ -200,13 +202,20 @@ export async function PUT(request: NextRequest) {
{ status: 500 },
);
}

const existingContents = await serverBookingContents(calendarEventId);
const oldRoomIds = existingContents.roomId.split(",").map(x => x.trim());
const oldRooms = allRooms.filter((room: RoomSetting) =>
oldRoomIds.includes(room.roomId + ""),
);

const selectedRoomIds = selectedRooms
.map((r: { roomId: number }) => r.roomId)
.join(", ");

// delete existing cal events
await Promise.all(
selectedRooms.map(async room => {
oldRooms.map(async room => {
await deleteEvent(room.calendarId, calendarEventId, room.roomId);
}),
);
Expand Down
8 changes: 4 additions & 4 deletions booking-app/app/api/calendarEvents/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
import {
deleteEvent,
insertEvent,
updateEventPrefix,
updateCalendarEvent,
} from "@/components/src/server/calendars";

import { getCalendarClient } from "@/lib/googleClient";
Expand Down Expand Up @@ -101,17 +101,17 @@ export async function GET(req: NextRequest) {
}

export async function PUT(req: NextRequest) {
const { calendarEventId, newPrefix } = await req.json();
const { calendarEventId, newValues } = await req.json();

if (!calendarEventId || !newPrefix) {
if (!calendarEventId || !newValues) {
return NextResponse.json(
{ error: "Missing required fields" },
{ status: 400 },
);
}
const contents = await serverBookingContents(calendarEventId);
try {
await updateEventPrefix(calendarEventId, newPrefix, contents);
await updateCalendarEvent(calendarEventId, newValues, contents);
return NextResponse.json(
{ message: "Event updated successfully" },
{ status: 200 },
Expand Down
7 changes: 1 addition & 6 deletions booking-app/app/book/confirmation/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// app/book/confirmation/page.tsx
import BookingForm from "@/components/src/client/routes/booking/BookingForm";
import BookingFormConfirmationPage from "@/components/src/client/routes/booking/formPages/BookingFormConfirmationPage";
import React from "react";

const Role: React.FC = () => (
<BookingForm>
<BookingFormConfirmationPage />
</BookingForm>
);
const Role: React.FC = () => <BookingFormConfirmationPage />;

export default Role;
7 changes: 1 addition & 6 deletions booking-app/app/book/form/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

"use client";

import BookingForm from "@/components/src/client/routes/booking/BookingForm";
import BookingFormDetailsPage from "@/components/src/client/routes/booking/formPages/BookingFormDetailsPage";
import React from "react";

const Form: React.FC = () => (
<BookingForm>
<BookingFormDetailsPage />
</BookingForm>
);
const Form: React.FC = () => <BookingFormDetailsPage />;

export default Form;
14 changes: 14 additions & 0 deletions booking-app/app/book/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// app/book/layout.tsx
import BookingForm from "@/components/src/client/routes/booking/BookingForm";
import { FormContextLevel } from "@/components/src/types";
import React from "react";

type LayoutProps = {
children: React.ReactNode;
};

const BookingLayout: React.FC<LayoutProps> = ({ children }) => (
<BookingForm formContext={FormContextLevel.FULL_FORM}>{children}</BookingForm>
);

export default BookingLayout;
9 changes: 2 additions & 7 deletions booking-app/app/book/role/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React from "react";
// app/book/form/page.tsx
import BookingForm from "@/components/src/client/routes/booking/BookingForm";
import UserRolePage from "@/components/src/client/routes/booking/formPages/UserRolePage";
import React from "react";

const Role: React.FC = () => (
<BookingForm>
<UserRolePage />
</BookingForm>
);
const Role: React.FC = () => <UserRolePage />;

export default Role;
9 changes: 2 additions & 7 deletions booking-app/app/book/selectRoom/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

"use client";

import BookingForm from "@/components/src/client/routes/booking/BookingForm";
import SelectRoomPage from "@/components/src/client/routes/booking/formPages/SelectRoomPage";
import React from "react";
import SelectRoomPage from "@/components/src/client/routes/booking/formPages/SelectRoomPage";

const SelectRoom: React.FC = () => (
<BookingForm>
<SelectRoomPage />
</BookingForm>
);
const SelectRoom: React.FC = () => <SelectRoomPage />;

export default SelectRoom;
6 changes: 5 additions & 1 deletion booking-app/app/edit/form/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
"use client";

import BookingFormDetailsPage from "@/components/src/client/routes/booking/formPages/BookingFormDetailsPage";
import { FormContextLevel } from "@/components/src/types";
import React from "react";

const Form: React.FC = ({ params }: { params: { id: string } }) => (
<BookingFormDetailsPage calendarEventId={params.id} isEdit={true} />
<BookingFormDetailsPage
calendarEventId={params.id}
formContext={FormContextLevel.EDIT}
/>
);

export default Form;
3 changes: 2 additions & 1 deletion booking-app/app/edit/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// app/edit/layout.tsx
import BookingForm from "@/components/src/client/routes/booking/BookingForm";
import { FormContextLevel } from "@/components/src/types";
import React from "react";

type LayoutProps = {
children: React.ReactNode;
};

const BookingLayout: React.FC<LayoutProps> = ({ children }) => (
<BookingForm>{children}</BookingForm>
<BookingForm formContext={FormContextLevel.EDIT}>{children}</BookingForm>
);

export default BookingLayout;
6 changes: 5 additions & 1 deletion booking-app/app/edit/role/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { FormContextLevel } from "@/components/src/types";
// app/edit/role/[id].tsx
import React from "react";
import UserRolePage from "@/components/src/client/routes/booking/formPages/UserRolePage";

const Role: React.FC = ({ params }: { params: { id: string } }) => (
<UserRolePage calendarEventId={params.id} isEdit={true} />
<UserRolePage
calendarEventId={params.id}
formContext={FormContextLevel.EDIT}
/>
);

export default Role;
6 changes: 5 additions & 1 deletion booking-app/app/edit/selectRoom/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

"use client";

import { FormContextLevel } from "@/components/src/types";
import React from "react";
import SelectRoomPage from "@/components/src/client/routes/booking/formPages/SelectRoomPage";

const SelectRoom: React.FC = ({ params }: { params: { id: string } }) => (
<SelectRoomPage isEdit={true} calendarEventId={params.id} />
<SelectRoomPage
calendarEventId={params.id}
formContext={FormContextLevel.EDIT}
/>
);

export default SelectRoom;
12 changes: 12 additions & 0 deletions booking-app/app/modification/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// app/modification/[id].tsx

"use client";

import ModificationLandingPage from "@/components/src/client/routes/modification/ModificationLandingPage";
import React from "react";

const HomePage: React.FC = ({ params }: { params: { id: string } }) => (
<ModificationLandingPage calendarEventId={params.id} />
);

export default HomePage;
16 changes: 16 additions & 0 deletions booking-app/app/modification/form/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// app/modification/form/[id].tsx

"use client";

import BookingFormDetailsPage from "@/components/src/client/routes/booking/formPages/BookingFormDetailsPage";
import { FormContextLevel } from "@/components/src/types";
import React from "react";

const Form: React.FC = ({ params }: { params: { id: string } }) => (
<BookingFormDetailsPage
calendarEventId={params.id}
formContext={FormContextLevel.MODIFICATION}
/>
);

export default Form;
16 changes: 16 additions & 0 deletions booking-app/app/modification/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// app/modification/layout.tsx
import BookingForm from "@/components/src/client/routes/booking/BookingForm";
import { FormContextLevel } from "@/components/src/types";
import React from "react";

type LayoutProps = {
children: React.ReactNode;
};

const BookingLayout: React.FC<LayoutProps> = ({ children }) => (
<BookingForm formContext={FormContextLevel.MODIFICATION}>
{children}
</BookingForm>
);

export default BookingLayout;
16 changes: 16 additions & 0 deletions booking-app/app/modification/selectRoom/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// app/modification/selectRoom/[id].tsx

"use client";

import { FormContextLevel } from "@/components/src/types";
import React from "react";
import SelectRoomPage from "@/components/src/client/routes/booking/formPages/SelectRoomPage";

const SelectRoom: React.FC = ({ params }: { params: { id: string } }) => (
<SelectRoomPage
calendarEventId={params.id}
formContext={FormContextLevel.MODIFICATION}
/>
);

export default SelectRoom;
5 changes: 4 additions & 1 deletion booking-app/app/walk-in/form/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
"use client";

import BookingFormDetailsPage from "@/components/src/client/routes/booking/formPages/BookingFormDetailsPage";
import { FormContextLevel } from "@/components/src/types";
import React from "react";

const Form: React.FC = () => <BookingFormDetailsPage isWalkIn={true} />;
const Form: React.FC = () => (
<BookingFormDetailsPage formContext={FormContextLevel.WALK_IN} />
);

export default Form;
3 changes: 2 additions & 1 deletion booking-app/app/walk-in/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// app/walk-in/layout.tsx
import BookingForm from "@/components/src/client/routes/booking/BookingForm";
import { FormContextLevel } from "@/components/src/types";
import React from "react";

type LayoutProps = {
children: React.ReactNode;
};

const BookingLayout: React.FC<LayoutProps> = ({ children }) => (
<BookingForm>{children}</BookingForm>
<BookingForm formContext={FormContextLevel.WALK_IN}>{children}</BookingForm>
);

export default BookingLayout;
Loading

0 comments on commit 9392264

Please sign in to comment.