Skip to content

Commit

Permalink
ORV2-1433 adding a sticky navigation button bar for IDIR users (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikataot authored Oct 6, 2023
1 parent 6c979a4 commit e405b55
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 10 deletions.
7 changes: 7 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import OnRouteBCContext, {
BCeIDUserDetailContext,
IDIRUserDetailContext,
} from "./common/authentication/OnRouteBCContext";
import { NavIconSideBar } from "./common/components/naviconsidebar/NavIconSideBar";
import { NavIconHomeButton } from "./common/components/naviconsidebar/NavIconHomeButton";
import { NavIconReportButton } from "./common/components/naviconsidebar/NavIconReportButton";

const authority =
import.meta.env.VITE_AUTH0_ISSUER_URL || envConfig.VITE_AUTH0_ISSUER_URL;
Expand Down Expand Up @@ -104,6 +107,10 @@ const App = () => {
alertType={snackBar.alertType}
/>
<Router>
<NavIconSideBar>
<NavIconHomeButton />
<NavIconReportButton />
</NavIconSideBar>
<Header />
<AppRoutes />
</Router>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/common/authentication/Authentication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Button from "@mui/material/Button";
import { LoginRedirect } from "./LoginRedirect";
import { Box, Container, Typography } from "@mui/material";
import { Loading } from "../pages/Loading";
import { IDPS } from "../types/idp";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const LoginOptions = ({ auth }: any) => (
Expand All @@ -13,7 +14,7 @@ const LoginOptions = ({ auth }: any) => (
variant="contained"
onClick={() => {
auth.signinRedirect({
extraQueryParams: { kc_idp_hint: "bceidboth" },
extraQueryParams: { kc_idp_hint: IDPS.BCEID },
});
}}
sx={{ width: "200px" }}
Expand All @@ -27,7 +28,7 @@ const LoginOptions = ({ auth }: any) => (
variant="contained"
onClick={() => {
auth.signinRedirect({
extraQueryParams: { kc_idp_hint: "idir" },
extraQueryParams: { kc_idp_hint: IDPS.IDIR },
});
}}
sx={{ width: "200px" }}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/common/authentication/LoginRedirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { HomePage } from "../../features/homePage/HomePage";
import { BCeIDUserContextType } from "./types";
import { Loading } from "../pages/Loading";
import { useUserContext } from "../../features/manageProfile/apiManager/hooks";
import { IDPS } from "../types/idp";

/*
* Redirects user to their correct page after loading their
Expand All @@ -25,7 +26,7 @@ export const LoginRedirect = () => {
*/
useEffect(() => {
if (isAuthenticated && !isLoading) {
if (userFromToken?.profile?.identity_provider === "idir") {
if (userFromToken?.profile?.identity_provider === IDPS.IDIR) {
navigate(routes.IDIR_WELCOME);
} else {
const userContextData: BCeIDUserContextType | undefined =
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/common/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { UserSectionInfo } from "./components/UserSectionInfo";
import { getLoginUsernameFromSession } from "../../apiManager/httpRequestHandler";
import { SearchButton } from "./components/SearchButton";
import { SearchFilter } from "./components/SearchFilter";
import { IDPS } from "../../types/idp";

const getEnv = () => {
const env =
Expand Down Expand Up @@ -106,7 +107,7 @@ export const Header = () => {
const [filterOpen, setFilterOpen] = useState(false);
const { isAuthenticated, user } = useAuth();
const username = getLoginUsernameFromSession();
const isIdir = user?.profile?.identity_provider === "idir";
const isIdir = user?.profile?.identity_provider === IDPS.IDIR;

const toggleMenu = () => {
setMenuOpen(!menuOpen);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@use "../../../themes/orbcStyles";

.nav-icon-home-button-container {
border: 1px solid #003366;
background-color: #003366;
width: 45px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import './NavIconHomeButton.scss'
import { IconButton, Tooltip } from "@mui/material";
import { Home } from "@mui/icons-material";
import { useNavigate } from "react-router-dom";
import * as routes from "../../../routes/constants";

/**
* Displays the navigation icon for Home on the NavIconSideBar
*/
export const NavIconHomeButton = () => {

const navigate = useNavigate()

return (
<div className="nav-icon-home-button-container">
<Tooltip arrow placement="left" title="Home">
<IconButton
size="medium"
color="secondary"
onClick={() => {navigate(routes.IDIR_WELCOME)}}
>
<Home />
</IconButton>
</Tooltip>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@use "../../../themes/orbcStyles";

.nav-icon-report-button-container {
border: 1px solid #003366;
background-color: #003366;
width: 45px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import './NavIconReportButton.scss'
import { IconButton, Tooltip } from "@mui/material";
import { Note } from "@mui/icons-material";
import { useNavigate } from "react-router-dom";
import * as routes from "../../../routes/constants";

/**
* Displays the navigation icon for Reports on the NavIconSideBar
*/
export const NavIconReportButton = () => {

const navigate = useNavigate()

return (
<div className="nav-icon-report-button-container">
<Tooltip arrow placement="left" title="Reports">
<IconButton
size="medium"
color="secondary"
onClick={() => {navigate(routes.IDIR_WELCOME)}}
>
<Note />
</IconButton>
</Tooltip>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@use "../../../themes/orbcStyles";

.nav-icon-side-bar {
position: -webkit-sticky; /* Safari */
position: sticky;
left: 0;
top: 400px;
}
26 changes: 26 additions & 0 deletions frontend/src/common/components/naviconsidebar/NavIconSideBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import {IDPS} from '../../types/idp'
import './NavIconSideBar.scss'
import { useAuth } from 'react-oidc-context'

interface NavIconSideBarProps {
children?: React.ReactNode;
}

/**
* Displays a sidebar with NavIcon buttons as children
*/
export const NavIconSideBar = (props: NavIconSideBarProps) => {
const { children } = props;
const { user } = useAuth()
const isIdir = user?.profile?.identity_provider === IDPS.IDIR

return (
<div className="nav-icon-side-bar">
{isIdir && children}
</div>
)
}



6 changes: 6 additions & 0 deletions frontend/src/common/types/idp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const IDPS = {
BCEID: 'bceidboth',
IDIR: 'idir'
} as const

export type IDP = typeof IDPS[keyof typeof IDPS]
3 changes: 2 additions & 1 deletion frontend/src/features/homePage/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { useAuth } from "react-oidc-context";
import { LoadBCeIDUserRolesByCompany } from "../../common/authentication/LoadBCeIDUserRolesByCompany";
import OnRouteBCContext from "../../common/authentication/OnRouteBCContext";
import { LoadIDIRUserRoles } from "../../common/authentication/LoadIDIRUserRoles";
import { IDPS } from "../../common/types/idp";

/**
* @param identityProvider The identity provider from the user token.
* @returns Boolean indicating if a logged in user is an IDIR.
*/
const isIDIRUser = (identityProvider: string) => identityProvider === "idir";
const isIDIRUser = (identityProvider: string) => identityProvider === IDPS.IDIR;

export const HomePage = React.memo(() => {
const { isAuthenticated, user: userFromToken } = useAuth();
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/features/manageProfile/apiManager/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "../../../common/authentication/types";
import { BCeIDAuthGroup } from "../types/userManagement";
import { useAuth } from "react-oidc-context";
import { IDPS } from "../../../common/types/idp";

/**
* Fetches company info of current user.
Expand Down Expand Up @@ -55,7 +56,7 @@ export const useUserContext = () => {
) => {
if (
isAuthenticated &&
userFromToken?.profile?.identity_provider === "idir"
userFromToken?.profile?.identity_provider === IDPS.IDIR
) {
const { user } = userContextResponseBody as IDIRUserContextType;
if (user?.userGUID) {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/ProtectedRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { LoadBCeIDUserRolesByCompany } from "../common/authentication/LoadBCeIDU
import { LoadBCeIDUserContext } from "../common/authentication/LoadBCeIDUserContext";
import { LoadIDIRUserContext } from "../common/authentication/LoadIDIRUserContext";
import { LoadIDIRUserRoles } from "../common/authentication/LoadIDIRUserRoles";
import { IDPS } from "../common/types/idp";

const isIDIR = (identityProvider: string) => identityProvider === "idir";
const isIDIR = (identityProvider: string) => identityProvider === IDPS.IDIR;

export const ProtectedRoutes = ({
requiredRole,
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/routes/constants.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IDPS } from "../common/types/idp";

export const HOME = "/";
export const UNAUTHORIZED = "unauthorized";

Expand Down Expand Up @@ -27,9 +29,8 @@ export const WELCOME = "welcome";
export const USER_INFO = "user-info";

// IDIR
const IDIR = "idir";
export const IDIR_WELCOME = `/${IDIR}/welcome`;
export const SEARCH_RESULTS = `/${IDIR}/search-results`;
export const IDIR_WELCOME = `/${IDPS.IDIR}/welcome`;
export const SEARCH_RESULTS = `/${IDPS.IDIR}/search-results`;

// Payment
export const PAYMENT_REDIRECT = "payment"

0 comments on commit e405b55

Please sign in to comment.