Skip to content

Commit

Permalink
submit modification
Browse files Browse the repository at this point in the history
  • Loading branch information
lucia-gomez committed Sep 26, 2024
1 parent 9b848a7 commit b4ada6b
Show file tree
Hide file tree
Showing 5 changed files with 458 additions and 349 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default function BookingActions({
[Actions.MODIFICATION]: {
action: async () => {
loadExistingBookingData(calendarEventId);
reloadExistingCalendarEvents();
router.push("/modification/" + calendarEventId);
},
optimisticNextStatus: status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export default function BookingFormMediaServices(props: Props) {
const { selectedRooms } = useContext(BookingContext);
const roomIds = selectedRooms.map((room) => room.roomId);

const limitedContexts = [
FormContextLevel.WALK_IN,
FormContextLevel.MODIFICATION,
];

const checkboxes = useMemo(() => {
const options: MediaServices[] = [];
const checkRoomMediaServices = (list: number[]) =>
Expand Down Expand Up @@ -74,7 +79,7 @@ export default function BookingFormMediaServices(props: Props) {
if (!e.target.checked) {
// de-select boxes if switch says "no media services"
field.onChange("");
} else if (formContext === FormContextLevel.WALK_IN) {
} else if (limitedContexts.includes(formContext)) {
field.onChange(MediaServices.CHECKOUT_EQUIPMENT);
}

Expand All @@ -88,7 +93,7 @@ export default function BookingFormMediaServices(props: Props) {
></Controller>
);

if (formContext === FormContextLevel.WALK_IN) {
if (limitedContexts.includes(formContext)) {
return (
<div style={{ marginBottom: 8 }}>
<Label htmlFor={id}>Media Services</Label>
Expand Down
Loading

0 comments on commit b4ada6b

Please sign in to comment.