This commit is contained in:
@@ -77,6 +77,7 @@ import RouteReportWithSignature from './components/trans-routes/RouteReportWithS
|
||||
|
||||
import Layout from "./components/home/layout";
|
||||
import Home from "./components/home/home";
|
||||
import NoDashboardAccess from "./components/home/NoDashboardAccess";
|
||||
|
||||
import Seating from "./components/seating/Seating";
|
||||
import CenterCalendar from "./components/center-calendar/CenterCalendar";
|
||||
@@ -231,6 +232,7 @@ function App() {
|
||||
|
||||
<Route path="/dashboard/dashboard" element={<Dashboard/>} />
|
||||
<Route path="/dashboard/admin-view" element={<AdminView/>} />
|
||||
<Route path="/home-empty" element={<NoDashboardAccess/>} />
|
||||
|
||||
<Route path="/seating" element={<Seating />} />
|
||||
<Route path="/center-calendar" element={<CenterCalendar/>} />
|
||||
|
||||
@@ -73,7 +73,7 @@ const AdminView = () => {
|
||||
|
||||
useEffect(() => {
|
||||
// Check if user has admin access
|
||||
if (!AuthService.canAccessLegacySystem()) {
|
||||
if (!AuthService.canViewAdminView()) {
|
||||
window.alert('You haven\'t login yet OR this user does not have access to this page. Please change an admin account to login.');
|
||||
AuthService.logout();
|
||||
window.location.href = '/login';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Breadcrumb, BreadcrumbItem, Card, Row, Col, Dropdown, Spinner } from 'react-bootstrap';
|
||||
import { AuthService, EventsService, CustomerService, TransRoutesService, ResourceService } from '../../services';
|
||||
import DashboardCustomersList from './DashboardCustomersList';
|
||||
@@ -7,6 +8,7 @@ import moment from 'moment';
|
||||
import './Dashboard.css';
|
||||
|
||||
const Dashboard = () => {
|
||||
const navigate = useNavigate();
|
||||
const [todayAttendance, setTodayAttendance] = useState(0);
|
||||
const [todayMedicalAppointments, setTodayMedicalAppointments] = useState(0);
|
||||
const [membersCount, setMembersCount] = useState(0);
|
||||
@@ -195,6 +197,10 @@ const Dashboard = () => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!AuthService.canViewDashboard()) {
|
||||
navigate('/home-empty');
|
||||
return;
|
||||
}
|
||||
setShowSpinner(true);
|
||||
Promise.all([
|
||||
fetchTodayAttendance(),
|
||||
@@ -208,7 +214,7 @@ const Dashboard = () => {
|
||||
]).finally(() => {
|
||||
setShowSpinner(false);
|
||||
});
|
||||
}, []);
|
||||
}, [navigate]);
|
||||
|
||||
// Separate useEffect for events that depends on selectedEventType, customers, and resources
|
||||
useEffect(() => {
|
||||
|
||||
7
client/src/components/home/NoDashboardAccess.js
Normal file
7
client/src/components/home/NoDashboardAccess.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import React from "react";
|
||||
|
||||
const NoDashboardAccess = () => {
|
||||
return <div />;
|
||||
};
|
||||
|
||||
export default NoDashboardAccess;
|
||||
@@ -1,11 +1,16 @@
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useEffect } from 'react';
|
||||
import { AuthService } from '../../services';
|
||||
|
||||
function Home() {
|
||||
const navigate = useNavigate();
|
||||
useEffect(() => {
|
||||
if (localStorage.getItem('user') && localStorage.getItem('token')) {
|
||||
navigate('/dashboard/dashboard')
|
||||
if (AuthService.canViewDashboard()) {
|
||||
navigate('/dashboard/dashboard');
|
||||
return;
|
||||
}
|
||||
navigate('/home-empty');
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ const SideMenu = () => {
|
||||
name: 'Admin View',
|
||||
link: '/dashboard/admin-view',
|
||||
category: '/dashboard/admin-view',
|
||||
roleFunc: AuthService.canAccessLegacySystem
|
||||
roleFunc: AuthService.canViewAdminView
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -207,11 +207,13 @@ const SideMenu = () => {
|
||||
{
|
||||
name: 'Meal Status',
|
||||
link: '/meal-status',
|
||||
category: '/meal-status',
|
||||
roleFunc: AuthService.canViewMealStatus
|
||||
},
|
||||
{
|
||||
name: 'Seating Chart',
|
||||
link: '/seating',
|
||||
category: '/seating',
|
||||
roleFunc: AuthService.canViewSeatingChart
|
||||
}
|
||||
]
|
||||
|
||||
@@ -10,13 +10,18 @@ const Login = ({ setMenu}) => {
|
||||
const [username, setUsername] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const navigate = useNavigate();
|
||||
const getPostLoginPath = () => {
|
||||
if (AuthService.canAccessLegacySystem()) {
|
||||
return '/landing';
|
||||
}
|
||||
if (AuthService.canViewDashboard()) {
|
||||
return '/dashboard/dashboard';
|
||||
}
|
||||
return '/home-empty';
|
||||
};
|
||||
useEffect(() => {
|
||||
if (localStorage.getItem('user') && localStorage.getItem('token')) {
|
||||
if (AuthService.canAccessLegacySystem()) {
|
||||
navigate(`/landing`);
|
||||
} else {
|
||||
navigate(`/admin`);
|
||||
}
|
||||
navigate(getPostLoginPath());
|
||||
}
|
||||
}, []);
|
||||
const loginAndRedirect = () => {
|
||||
@@ -26,11 +31,7 @@ const Login = ({ setMenu}) => {
|
||||
}).then(({data}) => {
|
||||
localStorage.setItem('token', data.accessToken);
|
||||
localStorage.setItem('user', JSON.stringify(data));
|
||||
if (AuthService.canAccessLegacySystem()) {
|
||||
navigate(`/landing`);
|
||||
} else {
|
||||
navigate(`/dashboard/dashboard`);
|
||||
}
|
||||
navigate(getPostLoginPath());
|
||||
setMenu();
|
||||
}).catch((error) => {
|
||||
window.alert(error?.response?.data?.message);
|
||||
|
||||
@@ -362,6 +362,10 @@ const canAddOrEditResources = () => {
|
||||
return canEditProviderInfo();
|
||||
}
|
||||
|
||||
const canViewAdminView = () => {
|
||||
return isAdmin() || hasPermission('Admin View');
|
||||
}
|
||||
|
||||
const canAccessLegacySystem = () => {
|
||||
return isAdmin() || hasAnyPermission([
|
||||
'Admin View',
|
||||
@@ -460,5 +464,6 @@ export const AuthService = {
|
||||
canAddOrEditCustomers,
|
||||
canAddOrEditAttendance,
|
||||
canViewAttendance,
|
||||
canViewAdminView,
|
||||
canAccessLegacySystem
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user