Skip to content

Commit

Permalink
Invite other room as guest
Browse files Browse the repository at this point in the history
  • Loading branch information
rlho committed Feb 5, 2024
1 parent 2078373 commit 81714e4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export const Calendars = ({
<CalendarDatePicker handleChange={handleChange} />
</div>
<div className="flex flex-col justify-center items-center">
<div className="">You are </div>
<div className="flex ">
<input
id="default-checkbox"
Expand All @@ -103,21 +102,6 @@ export const Calendars = ({
Enrolled in thesis
</label>
</div>
<div className="flex">
<input
id="default-checkbox"
type="checkbox"
value=""
className="pt-4 w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"
onChange={(e) => setFaculty(!enrolledThisis)}
/>
<label
htmlFor="default-checkbox"
className="ml-2 text-sm font-medium text-gray-900 dark:text-gray-300"
>
Faculty / Advisor
</label>
</div>
</div>
<div className="flex flex-col items-center ">
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export const RoomCalendar = ({
const [events, setEvents] = useState([]);

useEffect(() => {
fetchCalendarEvents(room.calendarIdProd);
//PROD
//fetchCalendarEvents(room.calendarIdProd);
//DEV
fetchCalendarEvents(room.calendarId);
}, []);
const fetchCalendarEvents = async (calendarId) => {
serverFunctions.getCalendarEvents(calendarId).then((rows) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Modal } from 'react-bootstrap';
import { InitialModal } from './InitialModal';
import { Loading } from '../../utils/Loading';
import { BAN_SHEET_NAME } from '../../admin-page/components/Ban';
import { RoleModal } from './RoleModal';
export type RoomSetting = {
roomId: string;
name: string;
Expand Down Expand Up @@ -47,15 +48,21 @@ const SheetEditor = () => {
//};

//IN DEV
const roomCalendarId = (room) =>
findByRoomId(mappingRoomSettings, room.roomId)?.calendarId;
const roomCalendarId = (room) => {
console.log(
'roomCalendarId',
findByRoomId(mappingRoomSettings, room.roomId)
);
return findByRoomId(mappingRoomSettings, room.roomId)?.calendarId;
};
const getActiveUserEmail = () => {
serverFunctions.getActiveUserEmail().then((response) => {
console.log('userEmail response', response);
setUserEmail(response);
});
};
const [showModal, setShowModal] = useState(true);
const [roleModal, setRoleModal] = useState(false);
const [userEmail, setUserEmail] = useState();
const [bookInfo, setBookInfo] = useState<DateSelectArg>();
const [isSafetyTrained, setIsSafetyTrained] = useState(false);
Expand Down Expand Up @@ -171,18 +178,22 @@ const SheetEditor = () => {
});
};

const registerEvent = (data) => {
const registerEvent = async (data) => {
const email = userEmail || data.missingEmail;
const [room, ...otherRoomIds] = selectedRoom;
console.log('roomId', roomCalendarId(room));
console.log('otherRoomIds', otherRoomIds);
// Add the event to the calendar.
const calendarEventId = await serverFunctions.addEventToCalendar(
roomCalendarId(room),
`[REQUESTED] ${room.roomId} ${data.department} - ${data.firstName} ${data.lastName} (${data.netId})`,
'Your reservation is not yet confirmed. The coordinator will review and finalize your reservation within a few days.',
bookInfo.startStr,
bookInfo.endStr,
email,
otherRoomIds.map((r) => roomCalendarId(r))
);
selectedRoom.map(async (room) => {
// Add the event to the calendar.
const calendarEventId = await serverFunctions.addEventToCalendar(
roomCalendarId,
`[REQUESTED] ${room.roomId} ${data.department} - ${data.firstName} ${data.lastName} (${data.netId})`,
'Your reservation is not yet confirmed. The coordinator will review and finalize your reservation within a few days.',
bookInfo.startStr,
bookInfo.endStr,
email
);
// Record the event to the spread sheet.
const contents = order.map(function (key) {
return data[key];
Expand Down Expand Up @@ -217,10 +228,10 @@ const SheetEditor = () => {
});
}
});
alert('Your request has been sent.');
setLoading(false);
setSection('selectRoom');
});
alert('Your request has been sent.');
setLoading(false);
setSection('selectRoom');
};
const handleSubmit = async (data) => {
setLoading(true);
Expand Down Expand Up @@ -301,10 +312,15 @@ const SheetEditor = () => {

const handleModalClick = () => {
setShowModal(false);
setRoleModal(true);
};
const handleRoleModalClick = () => {
setRoleModal(false);
};
return (
<div className="p-10 dark:bg-gray-800">
{showModal && <InitialModal handleClick={handleModalClick} />}
{roleModal && <RoleModal handleClick={handleRoleModalClick} />}
{!showModal && (
<>
<div className="flex flex-col justify-items-end items-end">
Expand Down
15 changes: 8 additions & 7 deletions media_commons_booking_app/src/server/sheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,26 @@ export const addEventToCalendar = (
description,
startTime,
endTime,
guestEmail
guestEmail,
roomEmails
) => {
const calendar = CalendarApp.getCalendarById(id);
console.log('calendar', calendar);
console.log('guestEmail', guestEmail);
const htmlTemplate = HtmlService.createTemplateFromFile(templateName);
for (const key in contents) {
htmlTemplate[key] = contents[key] || '';
}
const htmlBody = htmlTemplate.evaluate().getContent();

const event = calendar.createEvent(
title,
new Date(startTime),
new Date(endTime),
{
htmlBody,
description,
}
);
event.setColor(CalendarApp.EventColor.GRAY);
event.addGuest(guestEmail);
roomEmails.forEach((roomEmail) => {
event.addGuest(roomEmail);
});
console.log('event.id', event.getId());
return event.getId();
};
Expand Down

0 comments on commit 81714e4

Please sign in to comment.