Skip to content

Commit

Permalink
Merge branch 'refactor' into lucia/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
lucia-gomez committed Mar 30, 2024
2 parents 9ab1573 + dab1e27 commit d2b0a9d
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,9 @@ export const Bookings: React.FC<BookingsProps> = ({
{booking.sponsorFirstName} {booking.sponsorLastName}
</td>
<td className="px-2 py-4 w-20">{booking.sponsorEmail}</td>
<td className="px-2 py-4 w-52 break-all">
{booking.reservationTitle}
</td>
<td className="px-2 py-4 w-52 break-all">{booking.title}</td>
<td className="px-2 py-4 w-60 break-all">
{booking.reservationDescription}
{booking.description}
</td>
<td className="px-2 py-4 w-20">
{booking.expectedAttendance}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ <h2>Room Reservation Request</h2>
</p>
<p>
Reservation Title:
<?= reservationTitle ?>
<?= title ?>
</p>
<p>
Reservation Description:
<?= reservationDescription ?>
<?= description ?>
</p>
<p>
Expected Attendance:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ const FormInput = ({ handleParentSubmit }) => {
const [showTextbox, setShowTextbox] = useState(false);
const roomNumber = selectedRooms.map((room) => room.roomId);

console.log(selectedRooms);

const maxCapacity = selectedRooms.reduce((sum, room) => {
return sum + parseInt(room.capacity);
}, 0);
Expand Down Expand Up @@ -333,38 +331,36 @@ const FormInput = ({ handleParentSubmit }) => {
)}
<div className="mb-6">
<label
htmlFor="reservationTitle"
htmlFor="title"
className="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
>
Reservation Title
</label>
{errors.reservationTitle && (
<ErrorMessage errors={errors.reservationTitle.message} />
)}
{errors.title && <ErrorMessage errors={errors.title.message} />}
<input
type="reservationTitle"
id="reservationTitle"
type="title"
id="title"
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-[600px] p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder=""
{...register('reservationTitle', { required: true })}
{...register('title', { required: true })}
/>
</div>
<div className="mb-6">
<label
htmlFor="reservationDescription"
htmlFor="description"
className="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
>
Reservation Description
</label>
{errors.reservationDescription && (
<ErrorMessage errors={errors.reservationDescription.message} />
{errors.description && (
<ErrorMessage errors={errors.description.message} />
)}
<input
type="reservationDescription"
id="reservationDescription"
type="description"
id="description"
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-[600px] p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder=""
{...register('reservationDescription', { required: true })}
{...register('description', { required: true })}
/>
</div>
<div className="mb-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ const order: (keyof Inputs)[] = [
'sponsorFirstName',
'sponsorLastName',
'sponsorEmail',
'reservationTitle',
'reservationDescription',
'title',
'description',
'expectedAttendance',
'attendeeAffiliation',
'roomSetup',
Expand Down
110 changes: 14 additions & 96 deletions media_commons_booking_app/src/client/routes/components/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Ban,
Booking,
BookingStatus,
DevBranch,
LiaisonType,
PaUser,
PagePermission,
Expand Down Expand Up @@ -108,94 +107,62 @@ export const DatabaseProvider = ({ children }) => {
console.log('CURRENT BRANCH:', process.env.BRANCH_NAME);
const bookingRows = await serverFunctions
.getActiveBookingsFutureDates()
.then((rows) =>
rows
.map((row) => mappingBookingRows(row))
.filter((booking) => booking.devBranch === process.env.BRANCH_NAME)
);
.then((rows) => {
return (JSON.parse(rows) as Booking[]).filter((booking) => {
return booking.devBranch === process.env.BRANCH_NAME;
});
});
setBookings(bookingRows);
};

const fetchBookingStatuses = async () => {
const bookingStatusRows = await serverFunctions
.getAllActiveSheetRows(TableNames.BOOKING_STATUS)
.then((rows) => rows.map((row) => mappingBookingStatusRow(row)));
.then((rows) => JSON.parse(rows) as BookingStatus[]);
setBookingStatuses(bookingStatusRows);
};

const fetchAdminUsers = async () => {
const admins = await serverFunctions
.getAllActiveSheetRows(TableNames.ADMINS)
.then((rows) =>
rows.map((row) => ({
email: row[0],
createdAt: row[1],
}))
);
.then((rows) => JSON.parse(rows) as AdminUser[]);
setAdminUsers(admins);
};

const fetchPaUsers = async () => {
const pas = await serverFunctions
.getAllActiveSheetRows(TableNames.PAS)
.then((rows) =>
rows.map((row) => ({
email: row[0],
createdAt: row[1],
}))
);
.then((rows) => JSON.parse(rows) as PaUser[]);
setPaUsers(pas);
};

const fetchSafetyTrainedUsers = async () => {
const trained = await serverFunctions
.getAllActiveSheetRows(TableNames.SAFETY_TRAINING)
.then((rows) =>
rows.map((row) => ({
email: row[0],
completedAt: row[1],
}))
);
.then((rows) => JSON.parse(rows) as SafetyTraining[]);
setSafetyTrainedUsers(trained);
};

const fetchBannedUsers = async () => {
const banned = await serverFunctions
.getAllActiveSheetRows(TableNames.BANNED)
.then((rows) =>
rows.map((row) => ({
email: row[0],
bannedAt: row[1],
}))
);
.then((rows) => JSON.parse(rows) as Ban[]);
setBannedUsers(banned);
};

const fetchLiaisonUsers = async () => {
const liaisons = await serverFunctions
.getAllActiveSheetRows(TableNames.LIAISONS)
.then((rows) =>
rows.map((row) => ({
email: row[0],
department: row[1],
createdAt: row[2],
}))
);
.then((rows) => JSON.parse(rows) as LiaisonType[]);
setLiaisonUsers(liaisons);
};

const fetchRoomSettings = async () => {
const settings = await serverFunctions
.getAllActiveSheetRows(TableNames.ROOMS)
.then((rows) =>
rows.map((roomRow) => ({
roomId: roomRow[0],
name: roomRow[1],
capacity: roomRow[2],
calendarId: roomRow[3],
calendarIdProd: roomRow[4],
}))
);
.then((rows) => {
return JSON.parse(rows) as RoomSetting[];
});
setRoomSettings(settings);
};

Expand Down Expand Up @@ -226,52 +193,3 @@ export const DatabaseProvider = ({ children }) => {
</DatabaseContext.Provider>
);
};

const mappingBookingRows = (values: string[]): Booking => {
return {
calendarEventId: values[0],
roomId: values[1],
email: values[2],
startDate: values[3],
endDate: values[4],
firstName: values[5],
lastName: values[6],
secondaryName: values[7],
nNumber: values[8],
netId: values[9],
phoneNumber: values[10],
department: values[11],
role: values[12],
sponsorFirstName: values[13],
sponsorLastName: values[14],
sponsorEmail: values[15],
reservationTitle: values[16],
reservationDescription: values[17],
expectedAttendance: values[18],
attendeeAffiliation: values[19],
roomSetup: values[20],
setupDetails: values[21],
mediaServices: values[22],
mediaServicesDetails: values[23],
catering: values[24],
cateringService: values[25],
hireSecurity: values[26],
chartFieldForCatering: values[27],
chartFieldForSecurity: values[28],
chartFieldForRoomSetup: values[29],
devBranch: values[30] as DevBranch,
};
};

const mappingBookingStatusRow = (values: string[]): BookingStatus => {
return {
calendarEventId: values[0],
email: values[1],
requestedAt: values[2],
firstApprovedAt: values[3],
secondApprovedAt: values[4],
rejectedAt: values[5],
canceledAt: values[6],
checkedInAt: values[7],
};
};
43 changes: 5 additions & 38 deletions media_commons_booking_app/src/server/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,20 @@ import {
import { approvalUrl, rejectUrl } from './ui';
import {
fetchById,
fetchIndexById,
fetchIndexByUniqueValue,
getActiveSheetValueById,
removeRowActive,
updateActiveSheetValueById,
} from './db';
import { inviteUserToCalendarEvent, updateEventPrefix } from './calendars';

import { sendHTMLEmail, sendTextEmail } from './emails';

export const bookingContents = (id: string) => {
const values = fetchById(TableNames.BOOKING, id);
return {
calendarEventId: id,
roomId: values[2],
email: values[3],
startDate: values[4],
endDate: values[5],
firstName: values[6],
lastName: values[7],
secondaryName: values[8],
nNumber: values[9],
netId: values[10],
phoneNumber: values[11],
department: values[12],
role: values[13],
sponsorFirstName: values[14],
sponsorLastName: values[15],
sponsorEmail: values[16],
reservationTitle: values[17],
reservationDescription: values[18],
expectedAttendance: values[19],
attendeeAffiliation: values[20],
roomSetup: values[21],
setupDetails: values[22],
mediaServices: values[23],
mediaServicesDetails: values[24],
catering: values[25],
cateringService: values[26],

hireSecurity: values[27],
chartFieldForCatering: values[28],
chartFieldForSecurity: values[29],
chartFieldForRoomSetup: values[30],
approvalUrl: approvalUrl(id),
rejectedUrl: rejectUrl(id),
};
const bookingObj = fetchById(TableNames.BOOKING, id);
bookingObj.calendarEventId = id;
bookingObj.approvalUrl = approvalUrl(id);
bookingObj.rejectedUrl = rejectUrl(id);
return bookingObj;
};

export const approveInstantBooking = (id: string) => {
Expand Down
7 changes: 3 additions & 4 deletions media_commons_booking_app/src/server/calendars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// const startDate = new Date(startCalendarDate);
// const endDate = new Date(endCalendarDate);

import { ActiveSheetRoomsColumns, TableNames } from '../policy';

import { RoomSetting } from '../types';
import { TableNames } from '../policy';
import { getAllActiveSheetRows } from './db';

export const addEventToCalendar = (
Expand Down Expand Up @@ -63,8 +63,7 @@ export const getCalendarEvents = (calendarId: string) => {

const allRoomIds = () => {
const rows = getAllActiveSheetRows(TableNames.ROOMS);
const ids = rows.map((row) => row[ActiveSheetRoomsColumns.CALENDAR_ID]);
// ids.shift(); // remove header row
const ids = JSON.parse(rows).map((row: RoomSetting) => row.calendarId);
return ids;
};

Expand Down
Loading

0 comments on commit d2b0a9d

Please sign in to comment.