feat(app): clients list, page, create, edit, archive and restore
Routes /app/clients, /new, /:clientId, /:clientId/edit behind a workspace gate that remounts per workspace; debounced POST search, archived toggle and « Afficher plus » pages; form on field-limits (D-R7) with the phone entry rule and ISO countries; request id per creation intent; conflict shows the saved values; archive confirmation with the sole-owner preview; animals read-only; leave guard on in-app links; Clients entry after the dashboard.
This commit is contained in:
1 parent
ff028ec071
commit
b38e62770e
25 files changed
+2744
-5
No files matched your search
@@ -1,13 +1,16 @@
|
||||
import { useState } from 'react'
|
||||
import { Link, Outlet, useLocation } from 'react-router-dom'
|
||||
import { useState, type MouseEvent } from 'react'
|
||||
import { Link, Outlet, useLocation, useNavigate } from 'react-router-dom'
|
||||
import Brand from '@/components/brand/Brand'
|
||||
import LanguageSwitcher from '@/components/brand/LanguageSwitcher'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Dialog from '@/components/ui/Dialog'
|
||||
import Icon from '@/components/ui/Icon'
|
||||
import MobileDrawer from './MobileDrawer'
|
||||
import SidebarNav, { NAV_ITEMS } from './SidebarNav'
|
||||
import SignOutButton from './SignOutButton'
|
||||
import UserBadge, { AvatarCircle } from './UserBadge'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useLeaveGuardStore } from '@/state/leaveGuardStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/** Title of the current /app page for the top bar, from the nav table. */
|
||||
@@ -18,20 +21,53 @@ function pageTitleKey(pathname: string): string {
|
||||
return match?.labelKey ?? 'shell.nav.dashboard'
|
||||
}
|
||||
|
||||
/** An in-app link a plain click would follow: same origin, same tab, no modifier key. */
|
||||
function followedLink(event: MouseEvent): HTMLAnchorElement | null {
|
||||
if (event.defaultPrevented || event.button !== 0) return null
|
||||
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return null
|
||||
const anchor = (event.target as Element).closest('a[href]') as HTMLAnchorElement | null
|
||||
if (!anchor || anchor.target === '_blank' || anchor.origin !== window.location.origin) return null
|
||||
return anchor
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticated shell: fixed sidebar on large screens, light top bar with a
|
||||
* drawer button below. The page content scrolls on its own.
|
||||
* drawer button below. The page content scrolls on its own. While a page
|
||||
* holds unsaved changes (useLeaveGuard), following any link of the shell or
|
||||
* of the page asks first; staying is the default.
|
||||
*/
|
||||
export default function AppLayout() {
|
||||
const t = useT()
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const [drawerOpen, setDrawerOpen] = useState(false)
|
||||
const guarded = useLeaveGuardStore((s) => s.armed)
|
||||
const arm = useLeaveGuardStore((s) => s.arm)
|
||||
const [leaveTo, setLeaveTo] = useState<string | null>(null)
|
||||
|
||||
function askBeforeLeaving(event: MouseEvent) {
|
||||
if (!guarded) return
|
||||
const anchor = followedLink(event)
|
||||
if (!anchor) return
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
setLeaveTo(anchor.pathname + anchor.search + anchor.hash)
|
||||
}
|
||||
|
||||
function leave() {
|
||||
const to = leaveTo
|
||||
if (!to) return
|
||||
arm(false)
|
||||
setLeaveTo(null)
|
||||
setDrawerOpen(false)
|
||||
navigate(to)
|
||||
}
|
||||
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)]">
|
||||
<div className="flex min-h-dvh bg-[var(--color-bg)]" onClickCapture={askBeforeLeaving}>
|
||||
<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">
|
||||
@@ -85,6 +121,22 @@ export default function AppLayout() {
|
||||
</div>
|
||||
|
||||
<MobileDrawer open={drawerOpen} onClose={() => setDrawerOpen(false)} />
|
||||
<Dialog
|
||||
open={leaveTo !== null}
|
||||
onClose={() => setLeaveTo(null)}
|
||||
title={t('leave.title')}
|
||||
description={<p className="text-sm text-[var(--color-ink-muted)]">{t('leave.body')}</p>}
|
||||
size="sm"
|
||||
>
|
||||
<div className="mt-4 flex flex-wrap justify-end gap-2">
|
||||
<Button type="button" variant="ghost" onClick={() => setLeaveTo(null)}>
|
||||
{t('leave.stay')}
|
||||
</Button>
|
||||
<Button type="button" variant="danger" onClick={leave}>
|
||||
{t('leave.confirm')}
|
||||
</Button>
|
||||
</div>
|
||||
</Dialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user