-
Notifications
You must be signed in to change notification settings - Fork 223
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
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
93221d1
Wire up Next.js to FxA using iron-session
Vinnl ecd718d
feat: Port main layout for authenticated pages
flozia afbd995
chore: Get session in layout
flozia 8c596d6
fix: Provide fxa user menu with data
flozia aaee7c3
chore: Format Create Next App template
flozia cea6d03
merge: nextjs -> nextjs-authenticated-layout
flozia 4f08a97
merge: Resolve conflicts
flozia d98c919
fix: Move hr into li element
flozia 129679e
feat: Handle authenticated users
flozia 14ce273
chore: Add todo note
flozia 3b48eeb
chore: Don’t use default exports for SignInButton and UserMenu
flozia b595c3b
chore: Move site navigation to client-side component
flozia 5a5c222
chore: Move components into (nextjs_migration) and remove redundant l…
flozia 5f2509a
chore: Remove redirect landing page -> dashboard
flozia 7f99b0e
chore: Redirect to dashboard upon signin
flozia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
7 changes: 7 additions & 0 deletions
7
src/app/(nextjs_migration)/(authenticated)/user/breaches/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
109
src/app/(nextjs_migration)/(authenticated)/user/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
</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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/app/(nextjs_migration)/components/client/SignInButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 😂
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha! Was wondering why this sounded familiar...
FAQ
in v2 guestLayout and mainLayout? #2933