Skip to content

Commit

Permalink
useauth
Browse files Browse the repository at this point in the history
  • Loading branch information
john-tco committed Nov 8, 2023
1 parent 34dd6ea commit c44534d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 25 deletions.
4 changes: 3 additions & 1 deletion pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Script from 'next/script';
import nookies from 'nookies';
import React, { createContext, useEffect } from 'react';
import React, { createContext, useContext, useEffect } from 'react';
import TagManager from 'react-gtm-module';
import '../src/lib/ie11_nodelist_polyfill';
import '../styles/globals.scss';
Expand All @@ -10,6 +10,8 @@ import App from 'next/app';

export const AuthContext = createContext({ isUserLoggedIn: false });

export const useAuth = () => useContext(AuthContext);

const MyApp = ({ Component, pageProps, isUserLoggedIn }) => {
const cookies = nookies.get({});

Expand Down
6 changes: 2 additions & 4 deletions pages/grants/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Head from 'next/head';
import Link from 'next/link';
import { useRouter } from 'next/router';
import React, { useContext } from 'react';
import React from 'react';
import ErrorBanner from '../../src/components/displayErrors/errorBanner/ErrorBanner';
import { NewsletterCallToAction } from '../../src/components/newsletter/NewsletterCallToAction';
import { Pagination } from '../../src/components/pagination/Pagination';
Expand All @@ -22,7 +22,6 @@ import {
extractFiltersFields,
generateSearchHeadingFromDateRange,
} from '../../src/utils/transform';
import { AuthContext } from '../_app';

const conditionallyClearFiltersFromQuery = (
clearFilters,
Expand Down Expand Up @@ -129,7 +128,6 @@ const BrowseByCategory = ({
titleContent,
}) => {
const router = useRouter();
const { isUserLoggedIn } = useContext(AuthContext);

const handleSortByChange = (sort) => {
const newQuery = {
Expand All @@ -148,7 +146,7 @@ const BrowseByCategory = ({
<Head>
<title>{titleContent}</title>
</Head>
<Layout isUserLoggedIn={isUserLoggedIn} description="Find a grant">
<Layout description="Find a grant">
<div className="govuk-!-margin-top-3 govuk-!-margin-bottom-0 padding-bottom40">
<Link href={{ pathname: '../', query: { searchTerm } }}>
<a className="govuk-back-link" data-cy="cyBrowseBackText">
Expand Down
9 changes: 2 additions & 7 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ export function getServerSideProps({ query }) {
};
}

const Home = ({
searchTerm,
applicantUrl,
oneLoginEnabled,
isUserLoggedIn,
}) => {
const Home = ({ searchTerm, applicantUrl, oneLoginEnabled }) => {
return (
<>
<Head>
Expand All @@ -41,7 +36,7 @@ const Home = ({
/>
<title>Home - Find a grant</title>
</Head>
<Layout isUserLoggedIn={isUserLoggedIn} description="Find a grant">
<Layout description="Find a grant">
<div className="govuk-width-container ">
<div className="govuk-grid-row">
<div className="govuk-grid-column-full govuk-!-margin-top-5 govuk-!-margin-bottom-5">
Expand Down
2 changes: 1 addition & 1 deletion pages/notifications/manage-notifications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ const ManageNotifications = (props) => {
<Head>
<title>{gloss.title}</title>
</Head>
<Layout isUserLoggedIn={props.isUserLoggedIn}>
<Layout>
<div className="govuk-grid-row govuk-body padding-bottom40 govuk-!-margin-top-9">
{!!urlAction && !hideConfirmationMessage && (
<ConfirmationMessage
Expand Down
9 changes: 2 additions & 7 deletions pages/notifications/unsubscribe/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,14 @@ export async function getServerSideProps(ctx) {
};
}

function notifications({
unsubscribeGrant,
email,
grantDetails,
isUserLoggedIn,
}) {
function notifications({ unsubscribeGrant, email, grantDetails }) {
unsubscribeGrant = JSON.parse(unsubscribeGrant);
return (
<>
<Head>
<title>{gloss.title}</title>
</Head>
<Layout isUserLoggedIn={isUserLoggedIn} description="Notifications">
<Layout description="Notifications">
<div className="govuk-!-margin-top-3 govuk-!-margin-bottom-0 padding-bottom-0">
<a
href={`${notificationRoutes.manageNotifications}`}
Expand Down
8 changes: 3 additions & 5 deletions src/components/partials/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { useEffect } from 'react';
import CookieBanner from './cookie-banner';
import Footer from './Footer';
import { Header } from './header';
import { useAuth } from '../../../pages/_app';

const Layout = ({
children,
isBasicHeader = false,
isUserLoggedIn = false,
}) => {
const Layout = ({ children, isBasicHeader = false }) => {
const { isUserLoggedIn } = useAuth();
const clx = ['js-enabled', 'govuk-template__body'];
useEffect(() => {
document.querySelector('body').classList.add(...clx);
Expand Down

0 comments on commit c44534d

Please sign in to comment.