feat(app): identity screens and /app shell — auth store, login/signup/reset flows, dashboard, account

- state/authStore: session subscription (initialize + onAuthStateChange), profile + roles load, recovery flag, URL failure; services/localeSync: profiles.locale <-> localeStore
- routes: /login, /signup, /forgot-password, /reset-password, /auth/callback; guards RequireAuth (next=) and RedirectIfSignedIn; /app (dashboard), /app/account behind the guard
- shell: AppLayout (desktop sidebar, light top bar, mobile drawer), SidebarNav, UserBadge, SignOutButton
- account: personal / professional / preferences / security sections, one save each, Zod validation with i18n keys
- ui: Icon, FormField, Notice, ButtonLink (buttonClassName shared), PasswordField, OAuthButtons (config-driven)
- Home header: Mon espace / Se connecter when Supabase is configured; local tool routes untouched
- i18n: auth.*, shell.*, dashboard.*, account.*, home.space.* in fr + en
This commit is contained in:
bchanot committed 2026-10-11 23:29:13 +02:00
1 parent 0f7292f9b3
commit c517ea267b
46 files changed
+2798 -11

No files matched your search

@@ -0,0 +1,77 @@
import { useState } from 'react'
import { Link, Outlet, useLocation } from 'react-router-dom'
import Brand from '@/components/brand/Brand'
import LanguageSwitcher from '@/components/brand/LanguageSwitcher'
import Icon from '@/components/ui/Icon'
import MobileDrawer from './MobileDrawer'
import SidebarNav, { NAV_ITEMS } from './SidebarNav'
import SignOutButton from './SignOutButton'
import UserBadge from './UserBadge'
import { useT } from '@/i18n/useT'
/** Title of the current /app page for the top bar, from the nav table. */
function pageTitleKey(pathname: string): string {
const match = NAV_ITEMS.find((item) =>
item.end ? item.to === pathname : pathname.startsWith(item.to) && item.to !== '/',
)
return match?.labelKey ?? 'shell.nav.dashboard'
}
/**
* Authenticated shell: fixed sidebar on large screens, light top bar with a
* drawer button below. The page content scrolls on its own.
*/
export default function AppLayout() {
const t = useT()
const location = useLocation()
const [drawerOpen, setDrawerOpen] = useState(false)
return (
<div className="flex min-h-dvh bg-[var(--color-bg)]">
<aside className="hidden lg:flex lg:w-64 lg:shrink-0 lg:flex-col border-r border-[var(--color-border)] bg-[var(--color-surface)]">
<div className="px-5 py-5">
<Link to="/app" aria-label={t('shell.nav.dashboard')} className="inline-block">
<Brand size="md" />
</Link>
</div>
<div className="flex-1 px-3">
<SidebarNav />
</div>
<div className="space-y-3 border-t border-[var(--color-border)] px-4 py-4">
<UserBadge />
<SignOutButton className="w-full" />
</div>
</aside>
<div className="flex min-w-0 flex-1 flex-col">
<header className="sticky top-0 z-30 flex h-14 items-center gap-3 border-b border-[var(--color-border)] bg-[var(--color-surface)]/95 px-3 backdrop-blur-sm sm:px-6 pt-[env(safe-area-inset-top)]">
<button
type="button"
onClick={() => setDrawerOpen(true)}
aria-label={t('shell.open_menu')}
aria-expanded={drawerOpen}
className="grid h-11 w-11 place-items-center rounded-lg text-[var(--color-ink)] hover:bg-[var(--color-surface-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] lg:hidden"
>
<Icon name="menu" />
</button>
<Link to="/app" className="lg:hidden" aria-label={t('shell.nav.dashboard')}>
<Brand size="sm" />
</Link>
<h1 className="hidden lg:block text-sm font-medium text-[var(--color-ink-muted)]">
{t(pageTitleKey(location.pathname))}
</h1>
<div className="ml-auto flex items-center gap-2">
<LanguageSwitcher />
</div>
</header>
<main className="flex-1 px-4 py-6 sm:px-8 sm:py-8">
<div className="mx-auto w-full max-w-4xl">
<Outlet />
</div>
</main>
</div>
<MobileDrawer open={drawerOpen} onClose={() => setDrawerOpen(false)} />
</div>
)
}
@@ -0,0 +1,74 @@
import { useEffect } from 'react'
import { Link } from 'react-router-dom'
import { AnimatePresence, motion } from 'motion/react'
import Brand from '@/components/brand/Brand'
import Icon from '@/components/ui/Icon'
import SidebarNav from './SidebarNav'
import SignOutButton from './SignOutButton'
import UserBadge from './UserBadge'
import { useT } from '@/i18n/useT'
export interface MobileDrawerProps {
open: boolean
onClose: () => void
}
/** Left-side navigation drawer for small screens (transform + opacity only). */
export default function MobileDrawer({ open, onClose }: MobileDrawerProps) {
const t = useT()
useEffect(() => {
if (!open) return
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose()
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [open, onClose])
return (
<AnimatePresence>
{open && (
<div className="fixed inset-0 z-50 lg:hidden">
<motion.div
data-testid="drawer-backdrop"
className="absolute inset-0 bg-black/40"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.15 }}
onClick={onClose}
/>
<motion.aside
role="dialog"
aria-modal="true"
aria-label={t('shell.nav_label')}
initial={{ x: '-100%' }}
animate={{ x: 0 }}
exit={{ x: '-100%' }}
transition={{ duration: 0.2, ease: 'easeOut' }}
className="absolute inset-y-0 left-0 flex w-[min(20rem,85vw)] flex-col bg-[var(--color-surface)] shadow-xl pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]"
>
<div className="flex items-center justify-between px-4 py-3 border-b border-[var(--color-border)]">
<Link to="/app" onClick={onClose} aria-label={t('shell.nav.dashboard')}>
<Brand size="md" />
</Link>
<button
type="button"
onClick={onClose}
aria-label={t('shell.close_menu')}
className="grid h-11 w-11 place-items-center rounded-lg text-[var(--color-ink-muted)] hover:bg-[var(--color-surface-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
>
<Icon name="close" />
</button>
</div>
<div className="flex-1 overflow-y-auto px-3 py-4">
<SidebarNav onNavigate={onClose} />
</div>
<div className="space-y-3 border-t border-[var(--color-border)] px-4 py-4">
<UserBadge />
<SignOutButton className="w-full" />
</div>
</motion.aside>
</div>
)}
</AnimatePresence>
)
}
@@ -0,0 +1,60 @@
import { NavLink } from 'react-router-dom'
import Icon, { type IconName } from '@/components/ui/Icon'
import { useT } from '@/i18n/useT'
interface NavItem {
to: string
icon: IconName
labelKey: string
hintKey?: string
end?: boolean
}
export const NAV_ITEMS: readonly NavItem[] = [
{ to: '/app', icon: 'dashboard', labelKey: 'shell.nav.dashboard', end: true },
{ to: '/app/account', icon: 'user', labelKey: 'shell.nav.account' },
{
to: '/',
icon: 'tool',
labelKey: 'shell.nav.local_tool',
hintKey: 'shell.nav.local_tool_hint',
},
]
function linkClass(active: boolean): string {
return [
'relative flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm transition-colors min-h-11',
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]',
active
? 'bg-[var(--color-surface-strong)] text-[var(--color-ink)] font-medium before:absolute before:left-0 before:top-2 before:bottom-2 before:w-0.5 before:rounded-full before:bg-[var(--color-accent)]'
: 'text-[var(--color-ink-muted)] hover:bg-[var(--color-surface-strong)] hover:text-[var(--color-ink)]',
].join(' ')
}
/** The three destinations of the shell; `onNavigate` closes the mobile drawer. */
export default function SidebarNav({ onNavigate }: { onNavigate?: () => void }) {
const t = useT()
return (
<nav aria-label={t('shell.nav_label')} className="space-y-1">
{NAV_ITEMS.map((item) => (
<NavLink
key={item.to}
to={item.to}
end={item.end}
onClick={onNavigate}
className={({ isActive }) => linkClass(isActive)}
>
<Icon name={item.icon} size={20} className="shrink-0" />
<span className="flex min-w-0 flex-col leading-tight">
<span className="truncate">{t(item.labelKey)}</span>
{item.hintKey && (
<span className="truncate text-xs font-normal text-[var(--color-ink-muted)]">
{t(item.hintKey)}
</span>
)}
</span>
</NavLink>
))}
</nav>
)
}
@@ -0,0 +1,36 @@
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import Button from '@/components/ui/Button'
import Icon from '@/components/ui/Icon'
import { useAuthStore } from '@/state/authStore'
import { useT } from '@/i18n/useT'
export default function SignOutButton({ className = '' }: { className?: string }) {
const t = useT()
const navigate = useNavigate()
const signOut = useAuthStore((s) => s.signOut)
const [busy, setBusy] = useState(false)
async function onClick() {
setBusy(true)
try {
await signOut()
} finally {
// The guard would redirect anyway; going home keeps the local tool one step away.
navigate('/', { replace: true })
}
}
return (
<Button
type="button"
variant="ghost"
onClick={onClick}
disabled={busy}
className={`justify-start gap-3 text-[var(--color-ink-muted)] hover:text-[var(--color-ink)] ${className}`}
>
<Icon name="logout" size={20} />
{busy ? t('shell.signing_out') : t('shell.sign_out')}
</Button>
)
}
@@ -0,0 +1,38 @@
import { useAuthStore } from '@/state/authStore'
/** Two-letter monogram from the display name, else the email. */
export function monogram(name: string | undefined, email: string | undefined) {
const source = (name ?? '').trim() || (email ?? '').trim()
if (!source) return '?'
const parts = source.split(/\s+/).filter(Boolean)
const letters =
parts.length >= 2 ? parts[0][0] + parts[1][0] : source.slice(0, 2)
return letters.toUpperCase()
}
/** Avatar monogram + display name + email, as shown at the bottom of the sidebar. */
export default function UserBadge() {
const profile = useAuthStore((s) => s.profile)
const user = useAuthStore((s) => s.user)
const name = profile?.display_name ?? user?.email ?? ''
return (
<div className="flex items-center gap-3 min-w-0">
<span
aria-hidden="true"
className="grid h-9 w-9 shrink-0 place-items-center rounded-full bg-[var(--color-accent)] text-sm font-semibold text-white"
>
{monogram(profile?.display_name, user?.email)}
</span>
<span className="flex min-w-0 flex-col leading-tight">
<span className="truncate text-sm font-medium text-[var(--color-ink)]">
{name}
</span>
{user?.email && profile?.display_name && (
<span className="truncate text-xs text-[var(--color-ink-muted)]">
{user.email}
</span>
)}
</span>
</div>
)
}