From 7f667cbb9fa72548627815f8e4939359d083f6c6 Mon Sep 17 00:00:00 2001 From: "riho.takagi" Date: Thu, 7 Nov 2024 11:38:58 -0500 Subject: [PATCH 1/2] Debug log for pagePermission --- .../components/src/client/routes/components/Provider.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/booking-app/components/src/client/routes/components/Provider.tsx b/booking-app/components/src/client/routes/components/Provider.tsx index 1248881d..18a8cdbe 100644 --- a/booking-app/components/src/client/routes/components/Provider.tsx +++ b/booking-app/components/src/client/routes/components/Provider.tsx @@ -1,3 +1,5 @@ +import { ApproverLevel, TableNames } from "@/components/src/policy"; +import React, { createContext, useEffect, useMemo, useState } from "react"; import { AdminUser, Approver, @@ -12,12 +14,10 @@ import { SafetyTraining, Settings, } from "../../../types"; -import { ApproverLevel, TableNames } from "@/components/src/policy"; -import React, { createContext, useEffect, useMemo, useState } from "react"; -import { clientFetchAllDataFromCollection } from "@/lib/firebase/firebase"; -import { fetchAllFutureBooking } from "@/components/src/server/db"; import { useAuth } from "@/components/src/client/routes/components/AuthProvider"; +import { fetchAllFutureBooking } from "@/components/src/server/db"; +import { clientFetchAllDataFromCollection } from "@/lib/firebase/firebase"; export interface DatabaseContextType { adminUsers: AdminUser[]; @@ -103,6 +103,7 @@ export const DatabaseProvider = ({ return PagePermission.PA; else return PagePermission.BOOKING; }, [userEmail, adminUsers, paUsers]); + console.log("pagePermission", pagePermission); useEffect(() => { if (!bookingsLoading) { From 8e6b081b0559c5c5267325517845fb6b0a90f840 Mon Sep 17 00:00:00 2001 From: "riho.takagi" Date: Thu, 7 Nov 2024 17:47:04 -0500 Subject: [PATCH 2/2] Recalculate pagePermission after fetching liaisonUsers --- .../components/src/client/routes/components/Provider.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/booking-app/components/src/client/routes/components/Provider.tsx b/booking-app/components/src/client/routes/components/Provider.tsx index 18a8cdbe..256c779c 100644 --- a/booking-app/components/src/client/routes/components/Provider.tsx +++ b/booking-app/components/src/client/routes/components/Provider.tsx @@ -97,12 +97,18 @@ export const DatabaseProvider = ({ if (!userEmail) return PagePermission.BOOKING; if (adminUsers.map((admin) => admin.email).includes(userEmail)) return PagePermission.ADMIN; + console.log("liaisonUsers", liaisonUsers); + console.log("userEmail", userEmail); + console.log( + "liaisonUsers.map((liaison) => liaison.email).includes(userEmail)", + liaisonUsers.map((liaison) => liaison.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]); + }, [userEmail, adminUsers, paUsers, liaisonUsers]); console.log("pagePermission", pagePermission); useEffect(() => {