Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/components/CommunityPortal/CPDashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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 darkMode = useSelector(state => state.theme.darkMode);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -199,7 +207,16 @@ export function CPDashboard() {
<div className={styles.filterItem}>
<label htmlFor="online-only">Online</label>
<div>
<Input type="checkbox" /> Online Only
<Input
type="checkbox"
id="online-only"
checked={onlineOnly}
onChange={e => {
setOnlineOnly(e.target.checked);
setPagination(prev => ({ ...prev, currentPage: 1 }));
}}
/>{' '}
Online Only
</div>
</div>

Expand Down
20 changes: 15 additions & 5 deletions src/components/CommunityPortal/Login/CPLogin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,37 @@ const CPProtectedRoute = ({ component: Component, render, auth, fallback, ...res
<Route
{...rest}
render={props => {
// Check if auth state is properly initialized
if (!auth || typeof auth.isAuthenticated === 'undefined') {
return (
<div
className="d-flex justify-content-center align-items-center"
style={{ minHeight: '50vh' }}
>
<div className="text-center">
<i className="fa fa-spinner fa-pulse fa-2x text-primary"></i>
<p className="mt-2">Initializing authentication...</p>
</div>
</div>
);
}

// Check if we have a token but auth is still initializing
const token = localStorage.getItem('token') || localStorage.getItem('authToken');
if (token && !auth.isAuthenticated) {
return (
<div
className="d-flex justify-content-center align-items-center"
style={{ minHeight: '50vh' }}
>
<div className="text-center">
<i className="fa fa-spinner fa-pulse fa-2x text-primary"></i>
<p className="mt-2">Verifying authentication...</p>
</div>
</div>
);
}

if (!auth.isAuthenticated) {
return <Redirect to={{ pathname: '/login', state: { from: props.location } }} />;
}
Expand Down
Loading