Skip to content

Commit

Permalink
add noShow btn
Browse files Browse the repository at this point in the history
  • Loading branch information
lucia-gomez committed Apr 3, 2024
1 parent 8bb06fb commit c863f9d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Booking, BookingStatusLabel } from '../../../../types';
import React, { useContext, useMemo, useState } from 'react';

import { BookingStatusLabel } from '../../../../types';
import { DatabaseContext } from '../../components/Provider';
import Loading from '../../../utils/Loading';
import { serverFunctions } from '../../../utils/serverFunctions';
import useBookingStatus from '../hooks/getBookingStatus';
import { useLocation } from 'react-router';

interface Props {
calendarEventId: string;
Expand All @@ -15,6 +15,9 @@ export default function BookingActions({ status, calendarEventId }: Props) {
const [loading, setLoading] = useState(false);
const { reloadBookings, reloadBookingStatuses } = useContext(DatabaseContext);

const location = useLocation();
const isAdminPage = useMemo(() => location.pathname === '/admin', [location]);

const reload = async () => {
await Promise.all([reloadBookings(), reloadBookingStatuses()]);
};
Expand All @@ -33,35 +36,54 @@ export default function BookingActions({ status, calendarEventId }: Props) {
} finally {
setLoading(false);
}
// await action();
// await reload();
// setLoading(false);
}}
>
{text}
</button>
);

if (loading) {
return <Loading />;
return (
<td className="px-2 py-4 w-28">
<Loading />
</td>
);
}

return (
const paBtns = (
<>
{status === BookingStatusLabel.PRE_APPROVED &&
ActionButton('Second Approve', () =>
serverFunctions.approveBooking(calendarEventId)
)}
{status === BookingStatusLabel.REQUESTED &&
ActionButton('First Approve', () =>
serverFunctions.approveBooking(calendarEventId)
)}
{ActionButton('Reject', () => serverFunctions.reject(calendarEventId))}
{ActionButton('Cancel', () => serverFunctions.cancel(calendarEventId))}
{status !== BookingStatusLabel.CHECKED_IN &&
ActionButton('Check In', () =>
serverFunctions.checkin(calendarEventId)
)}
{status !== BookingStatusLabel.NO_SHOW &&
ActionButton('No Show', () => serverFunctions.noShow(calendarEventId))}
</>
);

if (!isAdminPage) {
return (
<td className="px-2 py-4 w-28">
<div className="flex flex-col items-start">{paBtns}</div>
</td>
);
}

return (
<td className="px-2 py-4 w-36">
<div className="flex flex-col items-start">
{status === BookingStatusLabel.PRE_APPROVED &&
ActionButton('2nd Approve', () =>
serverFunctions.approveBooking(calendarEventId)
)}
{status === BookingStatusLabel.REQUESTED &&
ActionButton('1st Approve', () =>
serverFunctions.approveBooking(calendarEventId)
)}
{ActionButton('Reject', () => serverFunctions.reject(calendarEventId))}
{ActionButton('Cancel', () => serverFunctions.cancel(calendarEventId))}
{paBtns}
</div>
</td>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,12 @@ export const Bookings: React.FC<BookingsProps> = ({
{filteredBookings.map((booking, index) => {
const status = getBookingStatus(booking, bookingStatuses);
return (
<tr
key={index}
className="bg-white border-b dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600"
>
<tr key={index} className="">
{!isUserView && (
<td className="px-2 py-4 w-40 flex flex-col items-start">
<BookingActions
status={status}
calendarEventId={booking.calendarId}
/>
</td>
<BookingActions
status={status}
calendarEventId={booking.calendarId}
/>
)}
<td className="px-2 py-4 w-24">{status}</td>
<td className="px-2 py-4 w-36">{booking.roomId}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export default function getBookingStatus(
if (bookingStatusMatch === undefined) return BookingStatusLabel.UNKNOWN;
if (bookingStatusMatch.checkedInAt !== '') {
return BookingStatusLabel.CHECKED_IN;
} else if (bookingStatusMatch.noShowedAt !== '') {
return BookingStatusLabel.NO_SHOW;
} else if (bookingStatusMatch.canceledAt !== '') {
return BookingStatusLabel.CANCELED;
} else if (bookingStatusMatch.rejectedAt !== '') {
Expand Down
2 changes: 1 addition & 1 deletion media_commons_booking_app/src/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export enum ActiveSheetBookingStatusColumns {
REJECTED_DATE = 5,
CANCELLED_DATE = 6,
CHECKED_IN_DATE = 7,
STATUS = 8,
NO_SHOWED_DATE = 8,
}

export enum ActiveSheetRoomsColumns {
Expand Down
23 changes: 23 additions & 0 deletions media_commons_booking_app/src/server/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,29 @@ export const checkin = (id: string) => {
updateEventPrefix(id, BookingStatusLabel.CHECKED_IN);
};

export const noShow = (id: string) => {
updateActiveSheetValueById(
TableNames.BOOKING_STATUS,
id,
ActiveSheetBookingStatusColumns.NO_SHOWED_DATE,
new Date()
);
const guestEmail = getActiveSheetValueById(
TableNames.BOOKING_STATUS,
id,
ActiveSheetBookingStatusColumns.EMAIL
);
const eventTitle = getActiveSheetValueById(TableNames.BOOKING, id, 16);

sendTextEmail(
guestEmail,
BookingStatusLabel.NO_SHOW,
eventTitle,
'You did not check-in for your Media Commons Reservation and have been marked as a no-show.'
);
updateEventPrefix(id, BookingStatusLabel.NO_SHOW);
};

// assumes the email is in column 0 but that can be overridden
export const removeFromListByEmail = (
sheetName: TableNames,
Expand Down
2 changes: 2 additions & 0 deletions media_commons_booking_app/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
approveInstantBooking,
cancel,
checkin,
noShow,
reject,
removeFromListByEmail,
} from './admin';
Expand Down Expand Up @@ -58,6 +59,7 @@ export {
reject,
cancel,
checkin,
noShow,
approveInstantBooking,
removeFromListByEmail,
};
1 change: 1 addition & 0 deletions media_commons_booking_app/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type BookingStatus = {
rejectedAt: string;
canceledAt: string;
checkedInAt: string;
noShowedAt: string;
};

export enum BookingStatusLabel {
Expand Down

1 comment on commit c863f9d

@lucia-gomez
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.