feat(app): profile photo — avatar upload in Mon compte, photo in the sidebar, drawer and top bar

packages/supabase assets module: closed AssetFailure kinds, begin / quarantine
upload (upsert off) / confirm / remove, own-row state read with an explicit
column list, download under the SELECT policy. App: client transport (magic
byte sniff, never SVG, createImageBitmap, canvas 1024 px, JPEG 0.9, 5 MiB
cap), AvatarSection (preview, save, 1 s polling up to 30 s, rejection and
failure messages per closed code, removal with confirmation, in-flight row
resumed at mount), auth store blob URL revoked on change and sign-out,
AvatarCircle in UserBadge and the top bar link to Mon compte (D3), FR/EN
strings, fake client extended, 27 new tests (app 300).
This commit is contained in:
bchanot committed 2026-10-13 19:32:37 +02:00
1 parent 614887470c
commit 926dd7df8c
18 files changed
+1550 -31

No files matched your search

+15 -2
View File
@@ -6,7 +6,8 @@ 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 UserBadge, { AvatarCircle } from './UserBadge'
import { useAuthStore } from '@/state/authStore'
import { useT } from '@/i18n/useT'
/** Title of the current /app page for the top bar, from the nav table. */
@@ -25,6 +26,9 @@ export default function AppLayout() {
const t = useT()
const location = useLocation()
const [drawerOpen, setDrawerOpen] = useState(false)
const profile = useAuthStore((s) => s.profile)
const user = useAuthStore((s) => s.user)
const displayName = profile?.display_name ?? user?.email ?? ''
return (
<div className="flex min-h-dvh bg-[var(--color-bg)]">
@@ -60,8 +64,17 @@ export default function AppLayout() {
<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">
<div className="ml-auto flex items-center gap-2 sm:gap-3">
<LanguageSwitcher />
<Link
to="/app/account"
aria-label={t('shell.nav.account')}
data-testid="topbar-account"
className="flex min-h-11 items-center gap-2 rounded-full pr-1 pl-1 text-sm text-[var(--color-ink)] hover:bg-[var(--color-surface-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] sm:pr-3"
>
<AvatarCircle size="sm" />
<span className="hidden max-w-[12rem] truncate sm:inline">{displayName}</span>
</Link>
</div>
</header>
<main className="flex-1 px-4 py-6 sm:px-8 sm:py-8">
+27 -7
View File
@@ -1,4 +1,5 @@
import { useAuthStore } from '@/state/authStore'
import { useT } from '@/i18n/useT'
/** Two-letter monogram from the display name, else the email. */
export function monogram(name: string | undefined, email: string | undefined) {
@@ -10,19 +11,38 @@ export function monogram(name: string | undefined, email: string | undefined) {
return letters.toUpperCase()
}
/** Avatar monogram + display name + email, as shown at the bottom of the sidebar. */
const CIRCLE =
'grid shrink-0 place-items-center overflow-hidden rounded-full bg-[var(--color-accent)] font-semibold text-white'
/** The photo when the store holds one, the monogram otherwise; decorative. */
export function AvatarCircle({ size = 'md' }: { size?: 'sm' | 'md' }) {
const t = useT()
const avatarUrl = useAuthStore((s) => s.avatarUrl)
const profile = useAuthStore((s) => s.profile)
const user = useAuthStore((s) => s.user)
const dims = size === 'sm' ? 'h-8 w-8 text-xs' : 'h-9 w-9 text-sm'
if (avatarUrl) {
return (
<span className={`${CIRCLE} ${dims}`}>
<img src={avatarUrl} alt={t('account.avatar.alt')} className="h-full w-full object-cover" />
</span>
)
}
return (
<span aria-hidden="true" className={`${CIRCLE} ${dims}`}>
{monogram(profile?.display_name, user?.email)}
</span>
)
}
/** Avatar + 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>
<AvatarCircle />
<span className="flex min-w-0 flex-col leading-tight">
<span className="truncate text-sm font-medium text-[var(--color-ink)]">
{name}