Audito dashboard and OPERATOR permissions
This commit is contained in:
@@ -6,14 +6,14 @@ import {
|
||||
} from "../../api/concentrators";
|
||||
import { fetchProjects, type Project } from "../../api/projects";
|
||||
import { fetchMeterTypes, type MeterType } from "../../api/meterTypes";
|
||||
import { getCurrentUserRole, getCurrentUserProjectId } from "../../api/auth";
|
||||
import type { ProjectCard, SampleView } from "./ConcentratorsPage";
|
||||
|
||||
type User = {
|
||||
role: "SUPER_ADMIN" | "USER";
|
||||
project?: string;
|
||||
};
|
||||
export function useConcentrators() {
|
||||
|
||||
export function useConcentrators(currentUser: User) {
|
||||
const userRole = getCurrentUserRole();
|
||||
const userProjectId = getCurrentUserProjectId();
|
||||
const isAdmin = userRole?.toUpperCase() === 'ADMIN';
|
||||
const [sampleView, setSampleView] = useState<SampleView>("GENERAL");
|
||||
|
||||
const [loadingProjects, setLoadingProjects] = useState(true);
|
||||
@@ -51,12 +51,12 @@ export function useConcentrators(currentUser: User) {
|
||||
|
||||
const visibleProjects = useMemo(
|
||||
() =>
|
||||
currentUser.role === "SUPER_ADMIN"
|
||||
isAdmin
|
||||
? allProjects
|
||||
: currentUser.project
|
||||
? [currentUser.project]
|
||||
: userProjectId
|
||||
? [userProjectId]
|
||||
: [],
|
||||
[allProjects, currentUser.role, currentUser.project]
|
||||
[allProjects, isAdmin, userProjectId]
|
||||
);
|
||||
|
||||
const loadMeterTypes = async () => {
|
||||
@@ -82,8 +82,8 @@ export function useConcentrators(currentUser: User) {
|
||||
|
||||
setSelectedProject((prev) => {
|
||||
if (prev) return prev;
|
||||
if (currentUser.role !== "SUPER_ADMIN" && currentUser.project) {
|
||||
return currentUser.project;
|
||||
if (!isAdmin && userProjectId) {
|
||||
return userProjectId;
|
||||
}
|
||||
return projectIds[0] ?? "";
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user