Skip to content

Commit

Permalink
feat: DefaultLayout passes isAdmin to Navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu-foucault committed Dec 14, 2021
1 parent 1567c44 commit ef80c8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/components/Layout/DefaultLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useMemo } from "react";
import Grid from "@button-inc/bcgov-theme/Grid";
import { graphql, useFragment } from "react-relay";
import type { DefaultLayout_session$key } from "DefaultLayout_session.graphql";
Expand All @@ -7,6 +7,7 @@ import Navigation from "components/Layout/Navigation";
import Footer from "components/Layout/Footer";
import SiteNoticeBanner from "components/Layout/SiteNoticeBanner";
import UserProfile from "components/User/UserProfile";
import { ADMIN_ROLES } from "data/group-constants";

const runtimeConfig = getConfig()?.publicRuntimeConfig ?? {};

Expand All @@ -28,15 +29,22 @@ const DefaultLayout: React.FC<Props> = ({
cifUserBySub {
...UserProfile_user
}
userGroups
}
`,
sessionFragment
);

const isAdmin = useMemo(
() => ADMIN_ROLES.some((role) => session?.userGroups?.includes(role)),
[session?.userGroups]
);

return (
<div id="page-wrap">
<Navigation
isLoggedIn={Boolean(session)}
isAdmin={isAdmin}
title={title}
userProfileComponent={
<UserProfile user={session ? session.cifUserBySub : null} />
Expand Down
4 changes: 3 additions & 1 deletion app/components/Layout/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SubHeader from "./SubHeader";

interface Props {
isLoggedIn?: boolean;
isAdmin?: boolean;
children?: React.ReactNode;
title?: string;
userProfileComponent?: React.ReactNode;
Expand All @@ -16,6 +17,7 @@ const DEFAULT_MOBILE_BREAK_POINT = "900";

const Navigation: React.FC<Props> = ({
isLoggedIn = false,
isAdmin = false,
title = "CleanBC Industry Fund",
userProfileComponent,
}) => {
Expand Down Expand Up @@ -60,7 +62,7 @@ const Navigation: React.FC<Props> = ({
{rightSide}
</BaseHeader.Group>
</BaseHeader>
{isLoggedIn && <SubHeader />}
{isLoggedIn && <SubHeader isAdmin={isAdmin} />}
</BaseNavigation>
<style jsx>{`
h1 {
Expand Down

0 comments on commit ef80c8d

Please sign in to comment.