mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem - www keeps its own copy of the account menu items separate from the shared top nav menu in kb and docs - www header buttons stay hidden until auth loads and the mobile menu shows no account links during that time - on app router page such as the home page sign out does not reload the page ## Solution - moves the www desktop account menu onto the shared top nav menu so www docs and kb show the same account items - fixes "Command Menu" shortcut label to follow the platform, so windows and linux readers see "Ctrl K" - changes the header and the mobile menu to read the signed-in mark while auth loads - moves the mobile menu account links onto the shared mobile actions, so www, docs and kb use one component - changes the desktop "Sign in" links to open the sign-in page, so desktop and mobile open the same page - fixes sign out on app router pages so the page reloads after sign out on every page <!-- ## Preview links If relevant, include links to changed pages for easy review access. Copy the preview base URL from the Vercel bot comment on this PR. Use the following table as an example template. | Site | Live | Preview | Search for | | -------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------- | | WWW | [/blog/your-post](https://supabase.com/blog/your-post) | [/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post) | unique phrase from the change | | Docs | [/docs/guides/your-page](https://supabase.com/docs/guides/your-page) | [/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page) | unique phrase from the change | | Studio | [/dashboard](https://supabase.com/dashboard) | [/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard) | unique phrase from the change | | Design system | [/design-system](https://supabase.com/design-system) | [/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system) | unique phrase from the change | | UI library | [/library](https://supabase.com/library) | [/library](https://ui-library-git-branch-name-supabase.vercel.app/library) | unique phrase from the change | | Knowledge base | [/kb/guides/your-page](https://supabase.com/kb/guides/your-page) | [/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page) | unique phrase from the change | --> <!-- ## Additional context Optionally add any other context or screenshots. --> ## Review instructions 1. visit [homepage](https://zone-www-dot-com-git-antlio-fix-www-shared-account-menu-supabase.vercel.app/) 2. open the browser console, and run this snippet, which stores a fake dashboard session with no real token: ```js const user = { id: 'test', aud: 'authenticated', email: 'you@example.com', user_metadata: { avatar_url: 'https://github.com/supabase.png' } } const key = 'supabase.dashboard.auth.token' localStorage.setItem(key, JSON.stringify({ access_token: 'a.b.c', refresh_token: 'r', token_type: 'bearer', expires_in: 3600, expires_at: Math.floor(Date.now() / 1000) + 3600, user })) localStorage.setItem(`${key}-user`, JSON.stringify({ user }))``` 3. reload the page ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
209 lines
7.3 KiB
TypeScript
209 lines
7.3 KiB
TypeScript
'use client'
|
|
|
|
import { type Menu } from '~/data/nav'
|
|
import { ChevronRight } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { useState, type ComponentProps, type MouseEvent, type RefObject } from 'react'
|
|
import { MobileNavAccountActions } from 'ui-patterns/MobileNav/MobileNavAccountActions'
|
|
import { MobileNavDrawer } from 'ui-patterns/MobileNav/MobileNavDrawer'
|
|
import { MobileNavTabs } from 'ui-patterns/MobileNav/MobileNavTabs'
|
|
import { SignedInSwitch } from 'ui-patterns/SignedInSwitch/SignedInSwitch'
|
|
import { TextLink } from 'ui-patterns/TextLink'
|
|
|
|
import MenuItem from './MenuItem'
|
|
import staticContent from '@/.generated/staticContent/_index.json'
|
|
import ProductModulesData from '@/data/ProductModules'
|
|
import { isCrossZoneHref } from '@/lib/cross-zone'
|
|
import { useSendTelemetryEvent } from '@/lib/telemetry'
|
|
|
|
interface MobileMenuProps {
|
|
open: boolean
|
|
menu: Menu
|
|
toggleRef: RefObject<HTMLElement | null>
|
|
onLinkClick: () => void
|
|
className?: string
|
|
}
|
|
|
|
export const MobileMenu = ({ open, menu, toggleRef, onLinkClick, className }: MobileMenuProps) => {
|
|
const sendTelemetryEvent = useSendTelemetryEvent()
|
|
const [pickedTitle, setPickedTitle] = useState<string>(menu.primaryNav[0].title)
|
|
const pickedItem = menu.primaryNav.find((menuItem) => menuItem.title === pickedTitle)
|
|
|
|
// the tab dropdown renders in a portal, but its react events still reach the drawer
|
|
const handleDrawerClick = (event: MouseEvent<HTMLDivElement>) => {
|
|
if (event.target instanceof Element && event.target.closest('a')) onLinkClick()
|
|
}
|
|
|
|
const handleSignInClick = () =>
|
|
sendTelemetryEvent({
|
|
action: 'sign_in_button_clicked',
|
|
properties: { buttonLocation: 'Mobile Nav' },
|
|
})
|
|
|
|
const handleSignUpClick = () =>
|
|
sendTelemetryEvent({
|
|
action: 'start_project_button_clicked',
|
|
properties: { buttonLocation: 'Mobile Nav' },
|
|
})
|
|
|
|
return (
|
|
<MobileNavDrawer
|
|
open={open}
|
|
toggleRef={toggleRef}
|
|
onClick={handleDrawerClick}
|
|
className={className}
|
|
footer={
|
|
<SignedInSwitch
|
|
signedIn={<MobileNavAccountActions isLoggedIn dashboardHref="/dashboard/projects" />}
|
|
signedOut={
|
|
<MobileNavAccountActions
|
|
isLoggedIn={false}
|
|
onSignInClick={handleSignInClick}
|
|
onSignUpClick={handleSignUpClick}
|
|
/>
|
|
}
|
|
/>
|
|
}
|
|
>
|
|
<nav aria-label="Menu" className="flex flex-col gap-6">
|
|
<MobileNavTabs
|
|
tabs={menu.primaryNav.map((menuItem) => ({
|
|
label: menuItem.title,
|
|
href: menuItem.hasDropdown ? undefined : menuItem.url,
|
|
}))}
|
|
selectedLabel={pickedTitle}
|
|
onTabSelect={setPickedTitle}
|
|
linkAs={NavLink}
|
|
/>
|
|
{pickedItem?.hasDropdown ? <SubMenu menuItem={pickedItem} /> : null}
|
|
</nav>
|
|
</MobileNavDrawer>
|
|
)
|
|
}
|
|
|
|
const NavLink = ({ href = '', ...props }: ComponentProps<'a'>) =>
|
|
isCrossZoneHref(href) ? <a href={href} {...props} /> : <Link href={href} {...props} />
|
|
|
|
const SubMenu = ({ menuItem }: { menuItem: Menu['primaryNav'][number] }) => {
|
|
const { jobsCount } = staticContent
|
|
|
|
return menuItem.title === 'Product' ? (
|
|
<>
|
|
{Object.values(menuItem.subMenu)?.map((component) => (
|
|
<MenuItem
|
|
key={component.name}
|
|
title={component.name}
|
|
href={component.url}
|
|
description={component.description_short}
|
|
icon={component.icon}
|
|
badge={
|
|
component.name === 'Compute'
|
|
? { label: 'Private Alpha', variant: 'default' }
|
|
: undefined
|
|
}
|
|
/>
|
|
))}
|
|
<div>
|
|
<div className="group flex items-center p-2 text-foreground-lighter text-xs uppercase tracking-widest font-mono">
|
|
Modules
|
|
</div>
|
|
<ul className="flex flex-col gap-0">
|
|
{Object.values(ProductModulesData).map((productModule) => (
|
|
<li key={productModule.name}>
|
|
<MenuItem
|
|
title={productModule.name}
|
|
href={productModule.url}
|
|
description={productModule.description_short}
|
|
icon={productModule.icon}
|
|
/>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
<Link
|
|
href="/features"
|
|
className="
|
|
flex items-center justify-between group text-sm
|
|
p-4 mt-4 gap-2
|
|
rounded-lg border
|
|
bg-alternative-200 text-foreground-light
|
|
hover:text-foreground hover:border-foreground-muted
|
|
focus-visible:text-foreground focus-ring
|
|
"
|
|
>
|
|
<div className="flex flex-col gap-1 leading-3!">
|
|
<span>Features</span>
|
|
<span className="text-foreground-lighter text-xs leading-4">
|
|
Explore everything you can do with Supabase.
|
|
</span>
|
|
</div>
|
|
<ChevronRight
|
|
strokeWidth={2}
|
|
className="w-3 -ml-1 transition-all will-change-transform -translate-x-1 opacity-80 group-hover:translate-x-0 group-hover:opacity-100"
|
|
/>
|
|
</Link>
|
|
</>
|
|
) : menuItem.title === 'Developers' ? (
|
|
<div className="px-3 mb-2 flex flex-col gap-6">
|
|
{menuItem.subMenu['navigation'].map((column) => (
|
|
<div key={column.label} className="flex flex-col gap-3">
|
|
{column.label !== 'Developers' && (
|
|
<label className="text-foreground-lighter text-xs uppercase tracking-widest font-mono">
|
|
{column.label}
|
|
</label>
|
|
)}
|
|
{column.links.map((link) => (
|
|
<TextLink
|
|
hasChevron={false}
|
|
key={link.text}
|
|
url={link.url}
|
|
label={link.text}
|
|
counter={link.text === 'Careers' && jobsCount > 0 ? jobsCount : undefined}
|
|
className="focus-visible:ring-offset-4 focus-visible:ring-offset-background-overlay mt-0!"
|
|
/>
|
|
))}
|
|
</div>
|
|
))}
|
|
|
|
<div className="flex flex-col py-2">
|
|
<label className="text-foreground-lighter text-xs uppercase tracking-widest font-mono">
|
|
Troubleshooting
|
|
</label>
|
|
<TextLink
|
|
hasChevron={false}
|
|
url={menuItem.subMenu['footer']['support'].url}
|
|
label={menuItem.subMenu['footer']['support'].text}
|
|
className="focus-visible:ring-offset-4 focus-visible:ring-offset-background-overlay"
|
|
/>
|
|
<TextLink
|
|
hasChevron={false}
|
|
url={menuItem.subMenu['footer']['systemStatus'].url}
|
|
label={menuItem.subMenu['footer']['systemStatus'].text}
|
|
className="focus-visible:ring-offset-4 focus-visible:ring-offset-background-overlay"
|
|
/>
|
|
</div>
|
|
</div>
|
|
) : menuItem.title === 'Solutions' ? (
|
|
<div className="px-3 mb-2 flex flex-col gap-6">
|
|
{menuItem.subMenu['navigation'].map((column) => (
|
|
<div key={column.label} className="flex flex-col gap-3">
|
|
{column.label !== 'Solutions' && (
|
|
<label className="text-foreground-lighter text-xs uppercase tracking-widest font-mono">
|
|
{column.label}
|
|
</label>
|
|
)}
|
|
{column.links.map((link) => (
|
|
<TextLink
|
|
hasChevron={false}
|
|
key={link.text}
|
|
url={link.url}
|
|
label={link.text}
|
|
className="focus-visible:ring-offset-4 focus-visible:ring-offset-background-overlay mt-0!"
|
|
/>
|
|
))}
|
|
</div>
|
|
))}
|
|
</div>
|
|
) : null
|
|
}
|