Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add layout for authenticated pages #3058

Merged
merged 15 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions public/nextjs_migration/client/js/userMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const userMenuButton = document.querySelector('.user-menu-button')
const userMenuPopover = document.querySelector('.user-menu-popover')
const userMenuWrapper = document.querySelector('.user-menu-wrapper')

function handleBlur (event, onBlur) {
const currentTarget = event.currentTarget

requestAnimationFrame(() => {
const isChildElement = currentTarget.contains(document.activeElement)

if (!isChildElement) {
onBlur()
}
})
}

function handleMenuButton () {
if (!userMenuPopover || !userMenuWrapper) {
return
}

if (userMenuPopover.hasAttribute('hidden')) {
// Show popover
userMenuPopover.setAttribute('aria-expanded', true)
userMenuPopover.removeAttribute('hidden')

// Handle onblur
userMenuWrapper.addEventListener('blur', (event) => handleBlur(event, handleMenuButton))
userMenuWrapper.focus()

// TODO: Re-enable event gtag events
// window.gtag('event', 'opened_closed_user_menu', { action: 'open' })
} else {
// Hide popover
userMenuPopover.setAttribute('aria-expanded', false)
userMenuPopover.setAttribute('hidden', '')

userMenuButton.focus()

// window.gtag('event', 'opened_closed_user_menu', { action: 'close' })
}
}

if (userMenuButton) {
userMenuButton.addEventListener('click', handleMenuButton)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

export default async function UserBreaches() {
return <div>Dashboard</div>;
}
109 changes: 109 additions & 0 deletions src/app/(nextjs_migration)/(authenticated)/user/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { ReactNode } from "react";
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";
import Image from "next/image";

import "../../../../client/css/index.css";
import { UserMenu } from "../../components/client/UserMenu";
import { SiteNavigation } from "../../components/client/SiteNavigation";
import AppConstants from "../../../../appConstants.js";
import MonitorLogo from "../../../../client/images/monitor-logo-transparent@2x.webp";
import MozillaLogo from "../../../../client/images/moz-logo-1color-white-rgb-01.svg";
import { getL10n } from "../../../functions/server/l10n";
import { authOptions } from "../../../api/auth/[...nextauth]/route";
export type Props = {
children: ReactNode;
};

const MainLayout = async (props: Props) => {
const session = await getServerSession(authOptions);
if (!session) {
redirect("/");
}

const l10n = getL10n();

return (
<>
<header>
<a href="/user/breaches">
<Image
className="monitor-logo"
src={MonitorLogo}
width="213"
height="33"
alt={l10n.getString("brand-fx-monitor")}
/>
</a>
<div className="nav-wrapper">
<button className="nav-toggle">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 10 8"
width="20"
>
<path
d="M1 1h8M1 4h8M1 7h8"
stroke="#000"
strokeWidth="1"
strokeLinecap="round"
/>
</svg>
</button>
<UserMenu
session={session}
fxaSettingsUrl={AppConstants.FXA_SETTINGS_URL}
/>
</div>
</header>

<SiteNavigation />

<main>{props.children}</main>

<footer className="site-footer">
<a href="https://www.mozilla.org" target="_blank">
<Image
src={MozillaLogo}
width="100"
height="29"
loading="lazy"
alt={l10n.getString("mozilla")}
/>
</a>
<menu>
<li>
<a href="/breaches">{l10n.getString("footer-nav-all-breaches")}</a>
</li>
<li>
<a
href="https://support.mozilla.org/kb/firefox-monitor-faq"
target="_blank"
>
FAQ
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that we never submitted this for translation 😂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was already wondering if “FAQ” is just something that was decided to not be translated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</a>
</li>
<li>
<a
href="https://www.mozilla.org/privacy/firefox-monitor"
target="_blank"
>
{l10n.getString("terms-and-privacy")}
</a>
</li>
<li>
<a href="https://github.com/mozilla/blurts-server" target="_blank">
{l10n.getString("github")}
</a>
</li>
</menu>
</footer>
</>
);
};

export default MainLayout;
83 changes: 58 additions & 25 deletions src/app/(nextjs_migration)/(guest)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,79 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { ReactNode } from 'react'
import '../../../client/css/index.css'
import Image from 'next/image'
import MonitorLogo from '../../../client/images/monitor-logo-transparent@2x.webp'
import MozillaLogo from '../../../client/images/moz-logo-1color-white-rgb-01.svg'
import { getL10n } from '../../functions/server/l10n'
import { ReactNode } from "react";
import "../../../client/css/index.css";
import Image from "next/image";
import MonitorLogo from "../../../client/images/monitor-logo-transparent@2x.webp";
import MozillaLogo from "../../../client/images/moz-logo-1color-white-rgb-01.svg";
import { SignInButton } from "../components/client/SignInButton";
import { getL10n } from "../../functions/server/l10n";

export type Props = {
children: ReactNode
}
children: ReactNode;
};

const GuestLayout = (props: Props) => {
const l10n = getL10n()
const l10n = getL10n();

return (
<>
<header>
<a href='/'>
<Image className='monitor-logo' src={MonitorLogo} width='213' height='33' alt={l10n.getString('brand-fx-monitor')}/>
<a href="/">
<Image
className="monitor-logo"
src={MonitorLogo}
width="213"
height="33"
alt={l10n.getString("brand-fx-monitor")}
/>
</a>
<menu>
<li><a href='/user/breaches' data-cta-id='sign-in-1' className='button secondary'>{l10n.getString('sign-in')}</a></li>
<li>
<SignInButton />
</li>
</menu>
</header>
<main>
{props.children}
</main>
<footer className='site-footer'>
<a href='https://www.mozilla.org' target='_blank'>
<Image src={MozillaLogo} width='100' height='29' loading='lazy' alt={l10n.getString('mozilla')}/>
<main>{props.children}</main>
<footer className="site-footer">
<a href="https://www.mozilla.org" target="_blank">
<Image
src={MozillaLogo}
width="100"
height="29"
loading="lazy"
alt={l10n.getString("mozilla")}
/>
</a>
<menu>
<li><a href='/breaches'>{l10n.getString('footer-nav-all-breaches')}</a></li>
<li><a href='https://support.mozilla.org/kb/firefox-monitor-faq' target='_blank'>FAQ</a></li>
<li><a href='https://www.mozilla.org/privacy/firefox-monitor' target='_blank'>{l10n.getString('terms-and-privacy')}</a></li>
<li><a href='https://github.com/mozilla/blurts-server' target='_blank'>{l10n.getString('github')}</a></li>
<li>
<a href="/breaches">{l10n.getString("footer-nav-all-breaches")}</a>
</li>
<li>
<a
href="https://support.mozilla.org/kb/firefox-monitor-faq"
target="_blank"
>
FAQ
</a>
</li>
<li>
<a
href="https://www.mozilla.org/privacy/firefox-monitor"
target="_blank"
>
{l10n.getString("terms-and-privacy")}
</a>
</li>
<li>
<a href="https://github.com/mozilla/blurts-server" target="_blank">
{l10n.getString("github")}
</a>
</li>
</menu>
</footer>
</>
)
}
);
};

export default GuestLayout
export default GuestLayout;
3 changes: 1 addition & 2 deletions src/app/(nextjs_migration)/(guest)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import Image from "next/image";
import Script from "next/script";
import "../../../client/css/partials/landing.css";

import { getL10n } from "../../functions/server/l10n";

import HeroImage from "../../../client/images/landing-hero@2x.webp";
Expand All @@ -14,7 +13,7 @@ import LockImage from "../../../client/images/landing-lock@2x.webp";
import MailImage from "../../../client/images/landing-mail@2x.webp";
import NaturePhoneImage from "../../../client/images/landing-nature-phone@2x.webp";

export default function Home() {
export default async function Home() {
const l10n = getL10n();

return (
Expand Down
22 changes: 22 additions & 0 deletions src/app/(nextjs_migration)/components/client/SignInButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use client";

import { signIn } from "next-auth/react";
import { useL10n } from "../../../hooks/l10n";

export const SignInButton = () => {
const l10n = useL10n();

return (
<button
onClick={() => signIn("fxa", { callbackUrl: "/user/breaches" })}
data-cta-id="sign-in-1"
className="button secondary"
>
{l10n.getString("sign-in")}
</button>
);
};
Loading