mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
fix
This commit is contained in:
@@ -7,6 +7,7 @@ import React, {
|
||||
} from "react";
|
||||
import Cookies from "js-cookie";
|
||||
import { MeDto } from "@/shared/dto/user/meDto";
|
||||
import { useAuth as useFreightAuth } from "@/auth/useAuth";
|
||||
|
||||
// ----- TYPES -----
|
||||
export interface Role {
|
||||
@@ -49,21 +50,32 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
||||
const [showOtpModal, setShowOtpModal] = useState(false);
|
||||
const [rememberMePreference, setRememberMePreference] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const cookieUser = Cookies.get("auth-user");
|
||||
const positionId = Cookies.get("selected-position-id");
|
||||
// Bridge to the freight session: this provider renders inside the freight
|
||||
// AuthProvider, so the real signed-in user is available here. The vendored IAM
|
||||
// code (AppMenuTabs, pages) reads `user` from this context — feed it the
|
||||
// freight user so it isn't null. Falls back to the legacy auth-user cookie.
|
||||
const { user: freightUser } = useFreightAuth();
|
||||
|
||||
useEffect(() => {
|
||||
const positionId = Cookies.get("selected-position-id");
|
||||
if (positionId) setSelectedPositionId(positionId);
|
||||
|
||||
if (freightUser) {
|
||||
setUser(freightUser as unknown as MeDto);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const cookieUser = Cookies.get("auth-user");
|
||||
if (cookieUser) {
|
||||
try {
|
||||
const parsed = JSON.parse(cookieUser);
|
||||
setUser(parsed);
|
||||
if (positionId) setSelectedPositionId(positionId);
|
||||
setUser(JSON.parse(cookieUser));
|
||||
} catch (e) {
|
||||
console.error("Invalid user cookie");
|
||||
}
|
||||
}
|
||||
setLoading(false);
|
||||
}, []);
|
||||
}, [freightUser]);
|
||||
// useEffect(() => {
|
||||
// sessionStorage.setItem("tabActive", "true");
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export const AppLayout = () => {
|
||||
|
||||
return (
|
||||
<div className="w-full flex flex-col min-h-screen bg-background text-foreground">
|
||||
<Top onToggleSidebar={toggleSidebar} showRecordManagementShortcut={!isSuperAdmin} />
|
||||
{/* <Top onToggleSidebar={toggleSidebar} showRecordManagementShortcut={!isSuperAdmin} /> */}
|
||||
<AppMenuTabs />
|
||||
<div className="px-2 pb-2 pt-8 sm:px-4 sm:pb-4 sm:pt-10 flex-1">
|
||||
<div className="w-full overflow-x-auto">
|
||||
|
||||
@@ -44,6 +44,30 @@ import SectorReportsPage from "@/record-management/pages/User/sectorReports";
|
||||
import ArchivedUnitsPositionsPage from "@/pages/ArchivedUnitsPositionsPage";
|
||||
import ConfigurationPage from "@/pages/ConfigurationPage";
|
||||
import { SidebarProvider } from "@/shared/common/ui/sidebar";
|
||||
import { AuthProvider as UmAuthProvider } from "@/shared/context/AuthContext";
|
||||
import { PermissionProvider } from "@/shared/context/PermissionContext";
|
||||
|
||||
/**
|
||||
* Provider shell for the vendored IAM UI. Feeds its Auth + Permission contexts
|
||||
* from the real freight session so AppMenuTabs / pages see the signed-in user
|
||||
* and their permission keys (otherwise both are null/empty). Wraps AppLayout in
|
||||
* SidebarProvider (its useSidebar dependency).
|
||||
*/
|
||||
function UmShell(): ReactElement {
|
||||
const { user } = useAuth();
|
||||
return (
|
||||
<UmAuthProvider>
|
||||
<PermissionProvider
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
permissions={(user?.permissions as any) ?? []}
|
||||
>
|
||||
<SidebarProvider>
|
||||
<AppLayout />
|
||||
</SidebarProvider>
|
||||
</PermissionProvider>
|
||||
</UmAuthProvider>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Layout wrapper for the user-management route subtree. Self-contained (the
|
||||
@@ -96,11 +120,7 @@ export const UserManagementRedirect = () => {
|
||||
export function UserManagementRoutes(): ReactElement {
|
||||
return (
|
||||
<Route
|
||||
element={
|
||||
<SidebarProvider>
|
||||
<AppLayout />
|
||||
</SidebarProvider>
|
||||
}
|
||||
element={<UmShell />}
|
||||
>
|
||||
<Route
|
||||
path="user-management"
|
||||
|
||||
Reference in New Issue
Block a user