From 198e1003177503422ff3439b070462616db0c7a9 Mon Sep 17 00:00:00 2001 From: lucia <51058748+lucia-gomez@users.noreply.github.com> Date: Sun, 29 Sep 2024 20:40:48 -0400 Subject: [PATCH] liaison dashboard --- .../admin/components/BookingActions.tsx | 7 +++ .../src/client/routes/components/Provider.tsx | 6 ++- .../components/bookingTable/Bookings.tsx | 52 +++++++++++++++---- .../src/client/routes/components/navBar.tsx | 29 +++++++---- booking-app/components/src/types.ts | 7 +-- 5 files changed, 76 insertions(+), 25 deletions(-) diff --git a/booking-app/components/src/client/routes/admin/components/BookingActions.tsx b/booking-app/components/src/client/routes/admin/components/BookingActions.tsx index 3a6a8a7a..916bdb7a 100644 --- a/booking-app/components/src/client/routes/admin/components/BookingActions.tsx +++ b/booking-app/components/src/client/routes/admin/components/BookingActions.tsx @@ -191,6 +191,11 @@ export default function BookingActions({ return options; }, [status]); + const liaisonOptions = useMemo( + () => [Actions.FIRST_APPROVE, Actions.DECLINE], + [status] + ); + const paOptions = useMemo(() => { let options = []; @@ -236,6 +241,8 @@ export default function BookingActions({ return userOptions; case PageContextLevel.PA: return paOptions; + case PageContextLevel.LIAISON: + return liaisonOptions; default: return adminOptions; } diff --git a/booking-app/components/src/client/routes/components/Provider.tsx b/booking-app/components/src/client/routes/components/Provider.tsx index a31389f0..9a679d78 100644 --- a/booking-app/components/src/client/routes/components/Provider.tsx +++ b/booking-app/components/src/client/routes/components/Provider.tsx @@ -19,6 +19,7 @@ import { fetchAllFutureBookingStatus, } from "@/components/src/server/db"; +import { Liaisons } from "../admin/components/Liaisons"; import { TableNames } from "@/components/src/policy"; import { clientFetchAllDataFromCollection } from "@/lib/firebase/firebase"; import { useAuth } from "@/components/src/client/routes/components/AuthProvider"; @@ -106,10 +107,11 @@ export const DatabaseProvider = ({ // page permission updates with respect to user email, admin list, PA list const pagePermission = useMemo(() => { if (!userEmail) return PagePermission.BOOKING; - if (adminUsers.map((admin) => admin.email).includes(userEmail)) return PagePermission.ADMIN; - else if (paUsers.map((pa) => pa.email).includes(userEmail)) + if (liaisonUsers.map((liaison) => liaison.email).includes(userEmail)) { + return PagePermission.LIAISON; + } else if (paUsers.map((pa) => pa.email).includes(userEmail)) return PagePermission.PA; else return PagePermission.BOOKING; }, [userEmail, adminUsers, paUsers]); diff --git a/booking-app/components/src/client/routes/components/bookingTable/Bookings.tsx b/booking-app/components/src/client/routes/components/bookingTable/Bookings.tsx index 6693827d..ab9a48ed 100644 --- a/booking-app/components/src/client/routes/components/bookingTable/Bookings.tsx +++ b/booking-app/components/src/client/routes/components/bookingTable/Bookings.tsx @@ -35,6 +35,7 @@ export const Bookings: React.FC = ({ pageContext }) => { bookings, bookingsLoading, bookingStatuses, + liaisonUsers, userEmail, reloadBookings, reloadBookingStatuses, @@ -73,15 +74,16 @@ export const Bookings: React.FC = ({ pageContext }) => { }, []); const allowedStatuses: BookingStatusLabel[] = useMemo(() => { - const paViewStatuses = [ - BookingStatusLabel.APPROVED, - BookingStatusLabel.CHECKED_IN, - BookingStatusLabel.CHECKED_OUT, - BookingStatusLabel.NO_SHOW, - BookingStatusLabel.WALK_IN, - ]; if (pageContext === PageContextLevel.PA) { - return paViewStatuses; + return [ + BookingStatusLabel.APPROVED, + BookingStatusLabel.CHECKED_IN, + BookingStatusLabel.CHECKED_OUT, + BookingStatusLabel.NO_SHOW, + BookingStatusLabel.WALK_IN, + ]; + } else if (pageContext === PageContextLevel.LIAISON) { + return [BookingStatusLabel.REQUESTED]; } else { return Object.values(BookingStatusLabel); } @@ -106,12 +108,24 @@ export const Bookings: React.FC = ({ pageContext }) => { ); // filter based on user view - if (pageContext === PageContextLevel.USER) + if (pageContext === PageContextLevel.USER) { filtered = rows.filter((row) => row.email === userEmail); - else if (pageContext === PageContextLevel.PA) { - filtered = rows.filter((row) => allowedStatuses.includes(row.status)); + } else if (pageContext === PageContextLevel.LIAISON) { + const liaisonMatches = liaisonUsers.filter( + (user) => user.email === userEmail + ); + if (liaisonMatches.length > 0) { + const liaisonDepartments = liaisonMatches.map( + (user) => user.department + ); + filtered = rows.filter((row) => + liaisonDepartments.includes(row.department) + ); + } } + filtered = filtered.filter((row) => allowedStatuses.includes(row.status)); + if (pageContext >= PageContextLevel.PA) { // PA and Admin // filter by selected PA date range @@ -154,6 +168,22 @@ export const Bookings: React.FC = ({ pageContext }) => { ); } + + if (pageContext === PageContextLevel.LIAISON) { + return ( + + Department Requests + + ); + } + return ( { if ( pagePermission !== PagePermission.ADMIN && - pagePermission !== PagePermission.PA + pagePermission !== PagePermission.PA && + pagePermission !== PagePermission.LIAISON ) { return null; } + const showPA = + pagePermission === PagePermission.PA || + pagePermission === PagePermission.ADMIN; + const showLiaison = + pagePermission === PagePermission.LIAISON || + pagePermission === PagePermission.ADMIN; + const showAdmin = pagePermission === PagePermission.ADMIN; + return ( ); }, [pagePermission, selectedView]); diff --git a/booking-app/components/src/types.ts b/booking-app/components/src/types.ts index ed195f43..77db896c 100644 --- a/booking-app/components/src/types.ts +++ b/booking-app/components/src/types.ts @@ -160,9 +160,10 @@ export type PaUser = { }; export enum PagePermission { - ADMIN = "Admin", - BOOKING = "User", - PA = "PA", + BOOKING = 0, + PA, + LIAISON, + ADMIN, } export enum PageContextLevel {