From b5333caa58004330210c7b5dc1a8258cdf5ee8a5 Mon Sep 17 00:00:00 2001 From: shashank-madan Date: Mon, 22 Dec 2025 16:53:46 -0500 Subject: [PATCH 1/2] Fixed route permissions to allow access to CP routes --- .../CommunityPortal/Login/CPLogin.jsx | 20 +++++++++--- .../CPProtectedRoute/CPProtectedRoute.jsx | 31 +++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/components/CommunityPortal/Login/CPLogin.jsx b/src/components/CommunityPortal/Login/CPLogin.jsx index 961b5eb4d5..81ff487772 100644 --- a/src/components/CommunityPortal/Login/CPLogin.jsx +++ b/src/components/CommunityPortal/Login/CPLogin.jsx @@ -18,12 +18,14 @@ function CPLogin(props) { // If access login page from URL directly, redirect to CP Dashboard const prevLocation = location.state?.from || { pathname: '/communityportal' }; - // push to dashboard if user is authenticated + // push to dashboard if user is authenticated and has CP Portal access useEffect(() => { - if (auth.user.access && auth.user.access.canAccessCPPortal) { + if (auth.isAuthenticated && auth.user?.access?.canAccessBMPortal) { history.push(prevLocation.pathname); } - }, []); + }, [auth.isAuthenticated, auth.user?.access?.canAccessBMPortal, history, prevLocation.pathname]); + + // Also check hasAccess state (set after successful login) useEffect(() => { if (hasAccess) { history.push(prevLocation.pathname); @@ -77,8 +79,16 @@ function CPLogin(props) { message: '', }); } - // initiate push to BM Dashboard if validated (ie received token) - return setHasAccess(!!res.data.token); + // initiate push to CP Dashboard if validated (ie received token) + // The auth state will be updated by loginBMUser, which will trigger the useEffect + // But also set hasAccess as a fallback + if (res.data && res.data.token) { + setHasAccess(true); + // Small delay to ensure auth state is updated + setTimeout(() => { + history.push(prevLocation.pathname); + }, 100); + } }; // push Dashboard if not authenticated diff --git a/src/components/common/CPDashboard/CPProtectedRoute/CPProtectedRoute.jsx b/src/components/common/CPDashboard/CPProtectedRoute/CPProtectedRoute.jsx index 96371ab340..946dc387b6 100644 --- a/src/components/common/CPDashboard/CPProtectedRoute/CPProtectedRoute.jsx +++ b/src/components/common/CPDashboard/CPProtectedRoute/CPProtectedRoute.jsx @@ -9,6 +9,37 @@ const CPProtectedRoute = ({ component: Component, render, auth, fallback, ...res { + // Check if auth state is properly initialized + if (!auth || typeof auth.isAuthenticated === 'undefined') { + return ( +
+
+ +

Initializing authentication...

+
+
+ ); + } + + // Check if we have a token but auth is still initializing + const token = localStorage.getItem('token') || localStorage.getItem('authToken'); + if (token && !auth.isAuthenticated) { + return ( +
+
+ +

Verifying authentication...

+
+
+ ); + } + if (!auth.isAuthenticated) { return ; } From 8a2bc63c6990453ce8eda9d3ae2d350765c5e312 Mon Sep 17 00:00:00 2001 From: shashank-madan Date: Wed, 24 Dec 2025 22:49:11 -0500 Subject: [PATCH 2/2] Added filtering criteria for online events --- .../CommunityPortal/CPDashboard.jsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/components/CommunityPortal/CPDashboard.jsx b/src/components/CommunityPortal/CPDashboard.jsx index dd01ea1e0e..91841847ea 100644 --- a/src/components/CommunityPortal/CPDashboard.jsx +++ b/src/components/CommunityPortal/CPDashboard.jsx @@ -35,6 +35,7 @@ export function CPDashboard() { const [events, setEvents] = useState([]); const [searchInput, setSearchInput] = useState(''); const [searchQuery, setSearchQuery] = useState(''); + const [onlineOnly, setOnlineOnly] = useState(false); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const [pagination, setPagination] = useState({ @@ -97,6 +98,13 @@ export function CPDashboard() { }; const filteredEvents = events.filter(event => { + // Filter by online only if checkbox is checked + if (onlineOnly) { + const isOnlineEvent = event.location?.toLowerCase() === 'virtual'; + if (!isOnlineEvent) return false; + } + + // Filter by search query if provided if (!searchQuery) return true; const term = searchQuery.toLowerCase(); @@ -199,7 +207,16 @@ export function CPDashboard() {
- Online Only + { + setOnlineOnly(e.target.checked); + setPagination(prev => ({ ...prev, currentPage: 1 })); + }} + />{' '} + Online Only