Skip to content

Commit

Permalink
front: hide stdcm debug button and remove isuserrolesfetched
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainValls committed Oct 31, 2024
1 parent 3dd12e4 commit 1d67551
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
24 changes: 12 additions & 12 deletions front/src/applications/stdcm/components/StdcmHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ const StdcmHeader = ({ isDebugMode, onDebugModeToggle }: StdcmHeaderProps) => {
{t('notificationTitle')}
</span>
</div>

<div className="stdcm-header_debug">
<button
type="button"
aria-label="stdcm-debug"
className={cx({ 'debug-on': isDebugMode, 'debug-off': !isDebugMode })}
onClick={() => onDebugModeToggle(!isDebugMode)}
disabled={!isSuperUser}
>
<Bug />
</button>
</div>
{isSuperUser && (
<div className="stdcm-header_debug">
<button
type="button"
aria-label="stdcm-debug"
className={cx({ 'debug-on': isDebugMode, 'debug-off': !isDebugMode })}
onClick={() => onDebugModeToggle(!isDebugMode)}
>
<Bug />
</button>
</div>
)}
</div>
);
};
Expand Down
6 changes: 3 additions & 3 deletions front/src/main/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ export default function App() {
// Blindly dispatch current front version for storage
dispatch(updateLastInterfaceVersion(import.meta.env.OSRD_GIT_DESCRIBE));
}, []);
const { isUserLogged, isUserRolesFetched } = useAuth();
const { isLoading } = useAuth();
return (
<Suspense fallback={<Loader />}>
<NotificationsState />
{isUserLogged && isUserRolesFetched && <RouterProvider router={router} />}
{(!isUserLogged || !isUserRolesFetched) && <Loader />}
{!isLoading && <RouterProvider router={router} />}
{isLoading && <Loader />}
</Suspense>
);
}
8 changes: 2 additions & 6 deletions front/src/utils/hooks/OsrdAuth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useEffect } from 'react';

import { useDispatch, useSelector } from 'react-redux';

Expand All @@ -11,12 +11,10 @@ type AuthHookData = {
username?: string;
isUserLogged: boolean;
isLoading: boolean;
isUserRolesFetched: boolean;
logout: () => void;
};

function useAuth(): AuthHookData {
const [isUserRolesFetched, setIsUserRolesFetched] = useState(false);
const isUserLogged = useSelector(getIsUserLogged);
const username = useSelector(getUsername);
const dispatch = useDispatch();
Expand All @@ -39,15 +37,13 @@ function useAuth(): AuthHookData {
useEffect(() => {
if (data) {
dispatch(setUserRoles(data?.builtin));
setIsUserRolesFetched(true);
}
}, [isUserLogged, data]);

return {
username,
isUserLogged,
isLoading: isAuthenticateLoading,
isUserRolesFetched,
isLoading: isAuthenticateLoading || !data,
logout,
};
}
Expand Down

0 comments on commit 1d67551

Please sign in to comment.