diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..ad1aa63 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,7 @@ +# AR-Test + +Before changing anything under `app/`, read and follow [docs/FRONTEND_RULES.md](docs/FRONTEND_RULES.md). +Project overview: [docs/PROJECT_OVERVIEW.md](docs/PROJECT_OVERVIEW.md). + +- Local dev: `yarn pb` (PocketBase on port 8099) and `yarn dev` (app on :5173). Both accept connections from the local network, so a phone can open `http://:5173`. +- `yarn typecheck` must pass before any commit. diff --git a/QR_CODE_REUSE_GUIDE.md b/QR_CODE_REUSE_GUIDE.md new file mode 100644 index 0000000..319cafe --- /dev/null +++ b/QR_CODE_REUSE_GUIDE.md @@ -0,0 +1,85 @@ +# Guide: How to Reuse Existing Printed QR Codes for New 3D Assets + +--- + +## 1. Why is the old QR code showing a missing/old asset? + +Every QR code generated by the system embeds a direct AR URL containing a specific **Asset Record ID**: +```text +https://your-domain.com/ar/0gsk2w8h236474u + ^^^^^^^^^^^^^^^ + PocketBase Asset Record ID +``` + +When you delete an asset in PocketBase and create a new one: +* PocketBase automatically generates a **new random 15-character ID** (e.g., `x9y8z7w6v5u4t3s`). +* Your previously printed or saved QR code is still pointing to the **old ID** (`0gsk2w8h236474u`), which no longer exists in the database. + +--- + +## 2. Step-by-Step Fix: Reusing Old QR Codes + +To make an existing physical or saved QR code load a new 3D model, you must ensure the new PocketBase asset record uses the **exact same Record ID** encoded in the old QR code. + +### Step 1: Find the Old Record ID from the QR Code +1. Open your phone camera or any QR scanner app. +2. Scan the old QR code. +3. Look at the URL it opens, for example: `http://localhost:5173/ar/0gsk2w8h236474u` +4. Copy the 15-character ID at the end of the link: **`0gsk2w8h236474u`** + +--- + +### Step 2: Create a New Asset with the Same Record ID + +#### Option A: Via PocketBase Admin UI (Easiest) +1. Open your PocketBase Admin Dashboard: `http://localhost:8090/_/` (or your PocketBase server URL). +2. Go to the **`ar_assets`** collection. +3. Click **"New Record"**. +4. In the **`id`** field at the top, manually paste your old ID (e.g., `0gsk2w8h236474u`). + > ⚠️ **Note**: PocketBase IDs must be exactly **15 characters** consisting of lowercase letters (`a-z`) and digits (`0-9`). +5. Upload your new `.glb`, `.usdz`, or `.png` files and set the asset `name`. +6. Click **Save**. + +Now, scanning the old QR code will immediately load your newly created asset! + +--- + +#### Option B: Via API / Postman / Code + +When sending a `POST` request to PocketBase (`/api/collections/ar_assets/records`), include the `id` field in the payload: + +```json +{ + "id": "0gsk2w8h236474u", + "name": "New Shirt Model 3D" +} +``` + +--- + +#### Option C: Enabling Custom ID in your Thob Admin Dashboard + +If you want to be able to enter an **"Existing / Custom QR ID"** directly inside your application dashboard: + +1. Add a **"Custom ID / Reused QR ID"** input field in the asset creation form. +2. Pass the `id` field in the `formData` sent to PocketBase during asset creation: + +```typescript +const formData = new FormData(); +if (customId) { + formData.append('id', customId); // PocketBase will use this exact ID! +} +formData.append('name', name); +formData.append('glb_file', glbFile); + +await pb.collection('ar_assets').create(formData); +``` + +--- + +## Summary Checklist + +- [x] Scan the old printed QR code to get the 15-character ID at the end of the `/ar/` URL. +- [x] Create a new record in the `ar_assets` PocketBase collection. +- [x] Pass/Set the `id` field to match the old 15-character ID. +- [x] Test by scanning the old QR code — it will now display the new 3D asset! diff --git a/app/app.css b/app/app.css index e29413d..905b821 100644 --- a/app/app.css +++ b/app/app.css @@ -1,70 +1,217 @@ @import 'tailwindcss'; +@import 'tw-animate-css'; @theme { - --font-sans: - 'Inter', ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', - 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; + --font-sans: 'Geist', ui-sans-serif, system-ui, sans-serif; + --font-mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace; + + /* Type scale (design: 26 / 17 / 15 / 14 / 13 / 12 / 11 / 10) */ + --text-3xs: 0.625rem; + --text-3xs--line-height: 0.875rem; + --text-2xs: 0.6875rem; + --text-2xs--line-height: 1rem; + --text-xs: 0.75rem; + --text-xs--line-height: 1.125rem; + --text-sm: 0.8125rem; + --text-sm--line-height: 1.25rem; + --text-base: 0.875rem; + --text-base--line-height: 1.375rem; + --text-md: 0.9375rem; + --text-md--line-height: 1.375rem; + --text-lg: 1.0625rem; + --text-lg--line-height: 1.5rem; + --text-xl: 1.25rem; + --text-xl--line-height: 1.75rem; + --text-display: 1.625rem; + --text-display--line-height: 2.125rem; + /* Login page headings */ + --text-2xl: 1.75rem; + --text-2xl--line-height: 2.125rem; + --text-3xl: 2rem; + --text-3xl--line-height: 2.375rem; + --text-4xl: 2.25rem; + --text-4xl--line-height: 2.5rem; + --text-5xl: 2.75rem; + --text-5xl--line-height: 3rem; + + /* Login layout: side by side from 960px, wide showcase from 1200px */ + --breakpoint-split: 60rem; + --breakpoint-wide: 75rem; + + /* Radii */ + --radius-chip: 5px; + --radius-option: 7px; + --radius-item: 8px; + --radius-control: 9px; + --radius-group: 10px; + --radius-field: 11px; + --radius-card-sm: 12px; + --radius-card: 14px; + --radius-panel: 16px; + --radius-phone-screen: 37px; + --radius-phone: 46px; + + /* Surfaces */ + --color-background: #0b0b0c; + --color-sidebar: #0d0d0e; + --color-surface-sunken: #0d0d0f; + --color-surface-well: #0f0f10; + --color-surface: #121213; + --color-surface-dialog: #121214; + --color-surface-raised: #141416; + --color-surface-control: #161618; + --color-surface-hover-subtle: #18181b; + --color-surface-hover: #1c1c1f; + --color-surface-pressed: #26262a; + --color-overlay: rgb(0 0 0 / 0.62); + --color-shadow: #000000; + + /* Borders */ + --color-border-divider: #1f1f22; + --color-border-subtle: #232326; + --color-border-dialog: #26262a; + --color-border-control: #2a2a2e; + --color-border-dashed: #36363b; + --color-border-strong: #3a3a3f; + + /* Text */ + --color-text-primary: #f4f4f5; + --color-text-emphasis: #d4d4d8; + --color-text-secondary: #a1a1aa; + --color-text-subtle: #8b8b90; + --color-text-muted: #71717a; + --color-text-faint: #6b6b72; + --color-text-placeholder: #5c5c62; + --color-ink: #141414; + + /* Brand */ + --color-primary: #f97316; + --color-primary-hover: #fb8a3c; + --color-primary-foreground: #ffffff; + --color-accent-100: #ffedd5; + --color-accent-200: #fed7aa; + --color-accent-300: #fdba74; + --color-accent-400: #fb923c; + --color-accent-600: #ea580c; + --color-accent-700: #c2410c; + --color-accent-800: #9a3412; + --color-accent-900: #7c2d12; + + /* Status */ + --color-danger: #f87171; + --color-warning: #fbbf24; + --color-success: #22c55e; + --color-success-strong: #16a34a; + --color-note-surface: #18140f; + --color-note-border: #3a2a17; + --color-note-text: #e7c9a4; + + /* Client logos */ + --color-logo-tile-light: #f6f5f3; + --color-logo-tile-dark: #161618; + --color-logo-chip-light: #ffffff; + --color-logo-chip-dark: #151517; + --color-logo-badge: #ebeae7; + + /* Illustration, AR page & phone frame */ + --color-wood-light: #92582f; + --color-wood-dark: #3f2412; + --color-phone-frame: #1a1a1c; + --color-phone-frame-edge: #2c2c30; + --color-camera: #1a1917; + --color-room-wall: #3a3430; + --color-room-floor: #4a423b; + --color-room-floor-near: #544a42; + --color-viewer: #f4f3f0; + --color-viewer-stripe: #ebe9e5; + --color-viewer-stripe-alt: #f1efec; + --color-viewer-caption: #8a8780; + --color-qr-surface: #ffffff; + + /* shadcn/ui compatibility — vendored primitives read these names */ + --color-foreground: var(--color-text-primary); + --color-muted-foreground: var(--color-text-muted); + --color-accent: var(--color-surface-hover); + --color-accent-foreground: var(--color-text-primary); + --color-popover: var(--color-surface-raised); + --color-popover-foreground: var(--color-text-primary); + --color-secondary: var(--color-surface-control); + --color-destructive: var(--color-danger); + --color-border: var(--color-border-subtle); + --color-input: var(--color-border-control); + --color-ring: var(--color-primary); + + /* Motion */ + --animate-fade-up: fade-up 0.5s ease-out; + /* Opacity only, so absolutely placed children keep their containing block while it runs */ + --animate-screen-in: screen-in 0.45s ease-out; + /* Duration comes from the component, which also advances the story when it ends */ + --animate-story-progress: story-progress linear forwards; + /* Moves a full-height box, so the line inside travels from 8% to 92% of the scan frame */ + --animate-scan: scan 2.8s ease-in-out infinite alternate; + --animate-float: float 3.2s ease-in-out infinite; + /* A third-width bar sliding across its track */ + --animate-loading-bar: loading-bar 1.4s ease-in-out infinite; + + @keyframes screen-in { + from { opacity: 0; } + } + + @keyframes story-progress { + from { transform: scaleX(0); } + to { transform: scaleX(1); } + } + + @keyframes float { + 0%, 100% { transform: translateY(0); } + 50% { transform: translateY(-8px); } + } + + @keyframes loading-bar { + from { transform: translateX(-100%); } + to { transform: translateX(300%); } + } + + @keyframes scan { + from { transform: translateY(8%); } + to { transform: translateY(92%); } + } + + @keyframes fade-up { + from { opacity: 0; transform: translateY(12px); } + to { opacity: 1; transform: translateY(0); } + } +} + +@utility eyebrow { + font-size: var(--text-2xs); + line-height: var(--text-2xs--line-height); + font-weight: 500; + letter-spacing: 0.06em; + text-transform: uppercase; + color: var(--color-text-faint); } html, body { - @apply bg-white dark:bg-gray-950; - - @media (prefers-color-scheme: dark) { - color-scheme: dark; - } -} -* { - box-sizing: border-box; -} - -body { - font-family: - 'Inter', - -apple-system, - BlinkMacSystemFont, - 'Segoe UI', - 'Roboto', - sans-serif; - background: #050509; + background-color: var(--color-background); + color: var(--color-text-primary); + color-scheme: dark; margin: 0; - padding: 0; - height: 100vh; + min-height: 100vh; + -webkit-font-smoothing: antialiased; } -.container { - max-width: 1200px; - margin: 0 auto; - padding: 1rem; -} - -model-viewer { - width: 100%; - height: 500px; - background: linear-gradient(to bottom, #e0e7ff, #f3f4f6); - border-radius: 16px; - box-shadow: - 0 20px 25px -5px rgba(0, 0, 0, 0.1), - 0 10px 10px -5px rgba(0, 0, 0, 0.04); - position: relative; -} - -@media (max-width: 768px) { - model-viewer { - height: 400px; - } -} ::placeholder { - color: rgb(156 163 175); /* gray-400 */ + color: var(--color-text-placeholder); opacity: 1; } -@keyframes float { - 0%, 100% { transform: translateY(0); } - 50% { transform: translateY(-12px); } +::selection { + background-color: color-mix(in srgb, var(--color-primary) 25%, transparent); } -@keyframes fade-up { - from { opacity: 0; transform: translateY(12px); } - to { opacity: 1; transform: translateY(0); } +/* Pages that render their own AR launch button hide model-viewer's built-in one */ +model-viewer[data-custom-ar-button]::part(default-ar-button) { + display: none; } diff --git a/app/components/FileOrUrlField.tsx b/app/components/FileOrUrlField.tsx deleted file mode 100644 index 613ca29..0000000 --- a/app/components/FileOrUrlField.tsx +++ /dev/null @@ -1,148 +0,0 @@ -import { Upload, Link, X } from 'lucide-react'; -import { Input } from '~/components/ui/input'; -import { Label } from '~/components/ui/label'; - -export type InputMode = 'url' | 'file'; - -export interface FileOrUrlFieldProps { - label: string; - required?: boolean; - mode: InputMode; - onModeChange: (m: InputMode) => void; - accept: string; - file: File | null; - onFileChange: (f: File | null) => void; - inputRef: React.RefObject; - url: string; - onUrlChange: (u: string) => void; - urlPlaceholder: string; - existingFileName?: string; - onClearExistingFile?: () => void; -} - -export function FileOrUrlField({ - label, required, mode, onModeChange, - accept, file, onFileChange, inputRef, - url, onUrlChange, urlPlaceholder, - existingFileName, onClearExistingFile, -}: FileOrUrlFieldProps) { - return ( -
- {/* Label + toggle */} -
- -
- - -
-
- - {mode === 'file' ? ( -
inputRef.current?.click()} - className={`flex cursor-pointer items-center gap-3 rounded-xl border-2 border-dashed px-4 py-4 transition-all duration-200 ${ - file || existingFileName - ? 'border-orange-500/50 bg-[#161616]' - : 'border-neutral-800 hover:border-neutral-700 bg-[#161616]/40 hover:bg-[#161616]/70' - }`} - > - onFileChange(e.target.files?.[0] ?? null)} - /> - {file ? ( - <> -
-
- -
-
- {file.name} - - {(file.size / 1024 / 1024).toFixed(2)} MB - -
-
- - - ) : existingFileName ? ( - <> -
-
- -
-
- {existingFileName} - - Existing File (Keep) - -
-
- - - ) : ( -
- - - Choose a file ({accept}) - -
- )} -
- ) : ( - onUrlChange(e.target.value)} - /> - )} -
- ); -} diff --git a/app/components/admin/admin-dialogs-provider.tsx b/app/components/admin/admin-dialogs-provider.tsx new file mode 100644 index 0000000..7b8225f --- /dev/null +++ b/app/components/admin/admin-dialogs-provider.tsx @@ -0,0 +1,47 @@ +import { useMemo, useState, type ReactNode } from 'react'; +import { useNavigate } from 'react-router'; +import { AssetFormDialog } from '~/components/assets/form/asset-form-dialog'; +import { DeleteAssetDialog } from '~/components/assets/delete-asset-dialog'; +import { ProjectFormDialog } from '~/components/projects/form/project-form-dialog'; +import { ROUTES } from '~/data/routes'; +import { AdminDialogsContext, type AdminDialogs } from '~/hooks/admin/use-admin-dialogs'; +import type { ArAsset } from '~/types/asset'; +import type { Project } from '~/types/project'; + +// Renders the project / asset dialogs once for the whole admin; pages open them through useAdminDialogs() +export function AdminDialogsProvider({ children }: { children: ReactNode }) { + const navigate = useNavigate(); + const [project, setProject] = useState<{ open: boolean; project: Project | null; key: number }>({ open: false, project: null, key: 0 }); + const [asset, setAsset] = useState<{ open: boolean; asset: ArAsset | null; projectId?: string; key: number }>({ open: false, asset: null, key: 0 }); + const [deleting, setDeleting] = useState<{ asset: ArAsset; onDeleted?: () => void } | null>(null); + + const dialogs = useMemo( + () => ({ + openProject: (target) => setProject((state) => ({ open: true, project: target ?? null, key: state.key + 1 })), + openAsset: (options) => setAsset((state) => ({ open: true, asset: options?.asset ?? null, projectId: options?.projectId, key: state.key + 1 })), + confirmDeleteAsset: (target, onDeleted) => setDeleting({ asset: target, onDeleted }), + }), + [], + ); + + return ( + + {children} + setProject((state) => ({ ...state, open }))} + onCreated={(id) => navigate(ROUTES.project(id))} + /> + setAsset((state) => ({ ...state, open }))} + /> + setDeleting(null)} onDeleted={deleting?.onDeleted} /> + + ); +} diff --git a/app/components/admin/sidebar/admin-sidebar.tsx b/app/components/admin/sidebar/admin-sidebar.tsx new file mode 100644 index 0000000..20a006b --- /dev/null +++ b/app/components/admin/sidebar/admin-sidebar.tsx @@ -0,0 +1,33 @@ +import { useState } from 'react'; +import { Menu } from 'lucide-react'; +import { Button } from '~/components/ui/button'; +import { Sheet, SheetContent, SheetTitle, SheetTrigger } from '~/components/ui/sheet'; +import { SidebarBrand } from '~/components/admin/sidebar/sidebar-brand'; +import { SidebarContent } from '~/components/admin/sidebar/sidebar-content'; + +// Fixed sidebar on desktop; a top bar with a slide-out menu on smaller screens +export function AdminSidebar() { + const [open, setOpen] = useState(false); + + return ( + <> + +
+ + + + + + + Menu + setOpen(false)} /> + + +
+ + ); +} diff --git a/app/components/admin/sidebar/sidebar-brand.tsx b/app/components/admin/sidebar/sidebar-brand.tsx new file mode 100644 index 0000000..1925527 --- /dev/null +++ b/app/components/admin/sidebar/sidebar-brand.tsx @@ -0,0 +1,11 @@ +import { Link } from 'react-router'; +import { BrandLockup } from '~/components/ui/brand-lockup'; +import { ROUTES } from '~/data/routes'; + +export function SidebarBrand({ onNavigate }: { onNavigate?: () => void }) { + return ( + + + + ); +} diff --git a/app/components/admin/sidebar/sidebar-content.tsx b/app/components/admin/sidebar/sidebar-content.tsx new file mode 100644 index 0000000..fbd4d63 --- /dev/null +++ b/app/components/admin/sidebar/sidebar-content.tsx @@ -0,0 +1,61 @@ +import { Plus } from 'lucide-react'; +import { Button } from '~/components/ui/button'; +import { ClientLogo } from '~/components/ui/client-logo'; +import { Text } from '~/components/ui/text'; +import { SidebarBrand } from '~/components/admin/sidebar/sidebar-brand'; +import { SidebarFooter } from '~/components/admin/sidebar/sidebar-footer'; +import { SidebarLink } from '~/components/admin/sidebar/sidebar-link'; +import { ASSET_FILTER } from '~/data/assets/constants'; +import { ROUTES } from '~/data/routes'; +import { useActiveNav, type NavSection } from '~/hooks/admin/use-active-nav'; +import { useAdminData } from '~/hooks/admin/use-admin-data'; +import { useAdminDialogs } from '~/hooks/admin/use-admin-dialogs'; +import { toBrand } from '~/services/asset-media'; + +export function SidebarContent({ onNavigate }: { onNavigate?: () => void }) { + const { projects, counts } = useAdminData(); + const { openProject } = useAdminDialogs(); + const active = useActiveNav(); + const clients = projects.filter((project) => project.status === 'active'); + + const nav: { section: NavSection; label: string; to: string; count: number }[] = [ + { section: 'projects', label: 'Projects', to: ROUTES.projects, count: clients.length }, + { section: 'assets', label: 'All assets', to: ROUTES.assets, count: counts.total }, + { section: 'unassigned', label: 'Unassigned', to: ROUTES.assetsFiltered(ASSET_FILTER.unassigned), count: counts.unassigned }, + ]; + + return ( +
+ + + + +
+
+ Clients + +
+ {clients.map((project) => ( + } + onNavigate={onNavigate} + /> + ))} +
+ + +
+ ); +} diff --git a/app/components/admin/sidebar/sidebar-footer.tsx b/app/components/admin/sidebar/sidebar-footer.tsx new file mode 100644 index 0000000..9a71222 --- /dev/null +++ b/app/components/admin/sidebar/sidebar-footer.tsx @@ -0,0 +1,40 @@ +import { useNavigate } from 'react-router'; +import { LogOut, Settings } from 'lucide-react'; +import { toast } from 'sonner'; +import { Button } from '~/components/ui/button'; +import { Text } from '~/components/ui/text'; +import { SidebarLink } from '~/components/admin/sidebar/sidebar-link'; +import { ROUTES } from '~/data/routes'; +import { useAdminData } from '~/hooks/admin/use-admin-data'; +import { signOut } from '~/services/auth'; + +export function SidebarFooter({ settingsActive, onNavigate }: { settingsActive: boolean; onNavigate?: () => void }) { + const { email } = useAdminData(); + const navigate = useNavigate(); + + return ( +
+ } onNavigate={onNavigate} /> +
+ {email && ( + + {email} + + )} + +
+
+ ); +} diff --git a/app/components/admin/sidebar/sidebar-link.tsx b/app/components/admin/sidebar/sidebar-link.tsx new file mode 100644 index 0000000..5de8b65 --- /dev/null +++ b/app/components/admin/sidebar/sidebar-link.tsx @@ -0,0 +1,43 @@ +import type { ReactNode } from 'react'; +import { Link } from 'react-router'; +import { cva } from 'class-variance-authority'; +import { Text } from '~/components/ui/text'; + +const linkVariants = cva('flex items-center rounded-item text-sm transition-colors duration-150', { + variants: { + size: { + nav: 'h-[34px] gap-2.5 px-2.5 font-medium', + client: 'h-9 gap-2.5 px-2', + }, + active: { + true: 'bg-surface-hover text-text-primary', + false: 'text-text-secondary hover:bg-surface-hover-subtle hover:text-text-primary', + }, + }, +}); + +interface SidebarLinkProps { + to: string; + label: string; + active: boolean; + size: 'nav' | 'client'; + leading?: ReactNode; + count?: number; + onNavigate?: () => void; +} + +export function SidebarLink({ to, label, active, size, leading, count, onNavigate }: SidebarLinkProps) { + return ( + + {leading} + + {label} + + {count !== undefined && ( + + {count} + + )} + + ); +} diff --git a/app/components/ar-viewer/ar-scene.tsx b/app/components/ar-viewer/ar-scene.tsx new file mode 100644 index 0000000..03e461f --- /dev/null +++ b/app/components/ar-viewer/ar-scene.tsx @@ -0,0 +1,45 @@ +import { useRef } from 'react'; +import { ArPage } from '~/components/ui/ar-page'; +import { LoadingScreen } from '~/components/ui/loading-screen'; +import { ModelViewer } from '~/components/ui/model-viewer'; +import { useArLaunch } from '~/hooks/ar-viewer/use-ar-launch'; +import { useModelViewerReady } from '~/hooks/use-model-viewer-ready'; +import { getArPageLayout, getButtonStyle, getGlbUrl, getUsdzUrl, toBrand } from '~/services/asset-media'; +import type { ArAsset } from '~/types/asset'; +import type { AppSettings } from '~/types/settings'; + +export function ArScene({ asset, settings }: { asset: ArAsset; settings: AppSettings }) { + const viewerRef = useRef(null); + const ready = useModelViewerReady(); + const { launch, launching, hint } = useArLaunch(viewerRef); + const project = asset.expand?.project; + + if (!ready) return ; + + return ( + + + + ); +} diff --git a/app/components/assets/asset-qr.tsx b/app/components/assets/asset-qr.tsx new file mode 100644 index 0000000..cc08ea7 --- /dev/null +++ b/app/components/assets/asset-qr.tsx @@ -0,0 +1,32 @@ +import { useMemo } from 'react'; +import { cva } from 'class-variance-authority'; +import { getArUrl, qrLogoFill, qrSvgMarkup } from '~/lib/assets/qr'; +import { cn } from '~/lib/utils'; +import { isBrandedQr, toBrand } from '~/services/asset-media'; +import type { ArAsset } from '~/types/asset'; + +const frameVariants = cva('relative aspect-square w-full overflow-hidden bg-qr-surface [&>svg]:block', { + variants: { + size: { + card: 'rounded-item', + panel: 'max-w-[300px] rounded-card-sm', + }, + }, +}); + +// The asset's QR code; a branded code has the client logo inside it, in a cleared square at the centre +export function AssetQr({ asset, size, className }: { asset: ArAsset; size: 'card' | 'panel'; className?: string }) { + const project = asset.expand?.project; + const brand = isBrandedQr(asset) && project ? toBrand(project) : undefined; + const markup = useMemo( + () => + qrSvgMarkup(getArUrl(asset.id), { + logo: brand?.logoUrl ? { href: brand.logoUrl, fill: qrLogoFill(brand) } : undefined, + label: `QR code for ${asset.name}`, + }), + [asset.id, asset.name, brand?.logoUrl, brand?.logoBg, brand?.logoBgColor], + ); + + // Markup built by qrSvgMarkup from our own data, with attribute values escaped + return
; +} diff --git a/app/components/assets/delete-asset-dialog.tsx b/app/components/assets/delete-asset-dialog.tsx new file mode 100644 index 0000000..4e0573d --- /dev/null +++ b/app/components/assets/delete-asset-dialog.tsx @@ -0,0 +1,34 @@ +import { useFetcher } from 'react-router'; +import { ConfirmDialog } from '~/components/ui/confirm-dialog'; +import { ASSET_INTENT, type AssetIntent } from '~/data/assets/constants'; +import { ROUTES } from '~/data/routes'; +import { useActionToast } from '~/hooks/use-action-toast'; +import type { ActionResult } from '~/types/action'; +import type { ArAsset } from '~/types/asset'; + +interface DeleteAssetDialogProps { + asset: ArAsset | null; + onClose: () => void; + onDeleted?: () => void; +} + +export function DeleteAssetDialog({ asset, onClose, onDeleted }: DeleteAssetDialogProps) { + const fetcher = useFetcher>(); + + useActionToast(fetcher.data, () => { + onClose(); + onDeleted?.(); + }); + + return ( + !open && onClose()} + title='Delete asset?' + description={`"${asset?.name ?? ''}" will be permanently deleted and its QR code will stop working.`} + confirmLabel='Delete' + pending={fetcher.state !== 'idle'} + onConfirm={() => asset && fetcher.submit({ intent: ASSET_INTENT.delete, id: asset.id }, { method: 'post', action: ROUTES.assets })} + /> + ); +} diff --git a/app/components/assets/detail/asset-detail-list.tsx b/app/components/assets/detail/asset-detail-list.tsx new file mode 100644 index 0000000..464c215 --- /dev/null +++ b/app/components/assets/detail/asset-detail-list.tsx @@ -0,0 +1,24 @@ +import { Text } from '~/components/ui/text'; +import { getModelFileName, isBrandedQr } from '~/services/asset-media'; +import type { ArAsset } from '~/types/asset'; + +export function AssetDetailList({ asset }: { asset: ArAsset }) { + const rows = [ + { label: 'Project', value: asset.expand?.project?.name ?? 'Unassigned', mono: false }, + { label: 'QR style', value: isBrandedQr(asset) ? 'Branded · client logo' : 'Standard', mono: false }, + { label: 'Model file', value: getModelFileName(asset), mono: true }, + ]; + + return ( +
+ {rows.map((row) => ( +
+ {row.label} + + {row.value} + +
+ ))} +
+ ); +} diff --git a/app/components/assets/detail/asset-preview-header.tsx b/app/components/assets/detail/asset-preview-header.tsx new file mode 100644 index 0000000..2709103 --- /dev/null +++ b/app/components/assets/detail/asset-preview-header.tsx @@ -0,0 +1,46 @@ +import { Link } from 'react-router'; +import { Button } from '~/components/ui/button'; +import { ClientLogo } from '~/components/ui/client-logo'; +import { PageBreadcrumb } from '~/components/ui/page-breadcrumb'; +import { Text } from '~/components/ui/text'; +import { ASSET_FILTER } from '~/data/assets/constants'; +import { ROUTES } from '~/data/routes'; +import { formatDate } from '~/lib/format'; +import { toBrand } from '~/services/asset-media'; +import type { ArAsset } from '~/types/asset'; + +interface AssetPreviewHeaderProps { + asset: ArAsset; + onEdit: () => void; + onDelete: () => void; +} + +export function AssetPreviewHeader({ asset, onEdit, onDelete }: AssetPreviewHeaderProps) { + const project = asset.expand?.project; + const parent = project + ? { label: project.name, to: ROUTES.project(project.id) } + : { label: 'Unassigned', to: ROUTES.assetsFiltered(ASSET_FILTER.unassigned) }; + + return ( + <> + +
+
+ {asset.name} +
+ {project && } + + {parent.label} + + · + Created {formatDate(asset.created)} +
+
+
+ + +
+
+ + ); +} diff --git a/app/components/assets/detail/asset-qr-panel.tsx b/app/components/assets/detail/asset-qr-panel.tsx new file mode 100644 index 0000000..a8fbf38 --- /dev/null +++ b/app/components/assets/detail/asset-qr-panel.tsx @@ -0,0 +1,40 @@ +import { Download } from 'lucide-react'; +import { Button } from '~/components/ui/button'; +import { Card } from '~/components/ui/card'; +import { CopyField } from '~/components/ui/copy-field'; +import { AssetQr } from '~/components/assets/asset-qr'; +import { AssetDetailList } from '~/components/assets/detail/asset-detail-list'; +import { UnassignedNote } from '~/components/assets/detail/unassigned-note'; +import { getArUrl } from '~/lib/assets/qr'; +import { downloadQr } from '~/lib/assets/qr-export'; +import { toFileName } from '~/lib/format'; +import { isBrandedQr, toBrand } from '~/services/asset-media'; +import type { ArAsset } from '~/types/asset'; + +export function AssetQrPanel({ asset }: { asset: ArAsset }) { + const arUrl = getArUrl(asset.id); + const project = asset.expand?.project; + const brand = project && isBrandedQr(asset) ? toBrand(project) : undefined; + const fileName = `${toFileName(asset.name)}_qr`; + const formats = [ + { format: 'png', label: 'QR · PNG', variant: 'default' }, + { format: 'svg', label: 'QR · SVG', variant: 'secondary' }, + ] as const; + + return ( + + + +
+ {formats.map(({ format, label, variant }) => ( + + ))} +
+ + {!project && } +
+ ); +} diff --git a/app/components/assets/detail/customer-view.tsx b/app/components/assets/detail/customer-view.tsx new file mode 100644 index 0000000..9cec1b7 --- /dev/null +++ b/app/components/assets/detail/customer-view.tsx @@ -0,0 +1,36 @@ +import { ArPagePreview } from '~/components/ui/ar-page-preview'; +import { Card } from '~/components/ui/card'; +import { ModelViewer } from '~/components/ui/model-viewer'; +import { Text } from '~/components/ui/text'; +import { useAdminData } from '~/hooks/admin/use-admin-data'; +import { useModelViewerReady } from '~/hooks/use-model-viewer-ready'; +import { getArPageLayout, getButtonStyle, getGlbUrl, getUsdzUrl, toBrand } from '~/services/asset-media'; +import type { ArAsset } from '~/types/asset'; + +// What a customer sees after scanning the QR, with the real 3D model +export function CustomerView({ asset }: { asset: ArAsset }) { + const { settings } = useAdminData(); + const ready = useModelViewerReady(); + const project = asset.expand?.project; + const glbUrl = getGlbUrl(asset); + + return ( + +
+ Customer view + After scanning the QR +
+ + {ready && glbUrl ? ( + + ) : undefined} + +
+ ); +} diff --git a/app/components/assets/detail/scan-qr-dialog.tsx b/app/components/assets/detail/scan-qr-dialog.tsx new file mode 100644 index 0000000..34e6956 --- /dev/null +++ b/app/components/assets/detail/scan-qr-dialog.tsx @@ -0,0 +1,29 @@ +import { AssetQr } from '~/components/assets/asset-qr'; +import { CopyField } from '~/components/ui/copy-field'; +import { Dialog, DialogBody, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '~/components/ui/dialog'; +import { getArUrl } from '~/lib/assets/qr'; +import type { ArAsset } from '~/types/asset'; + +interface ScanQrDialogProps { + asset: ArAsset; + open: boolean; + onOpenChange: (open: boolean) => void; +} + +// AR needs a phone camera, so "View in your space" in the admin preview offers the QR code to scan instead +export function ScanQrDialog({ asset, open, onOpenChange }: ScanQrDialogProps) { + return ( + + + + View in AR + Scan this QR code with your phone’s camera to open {asset.name} and place it in your room. + + + + + + + + ); +} diff --git a/app/components/assets/detail/unassigned-note.tsx b/app/components/assets/detail/unassigned-note.tsx new file mode 100644 index 0000000..7b2369b --- /dev/null +++ b/app/components/assets/detail/unassigned-note.tsx @@ -0,0 +1,9 @@ +import { Text } from '~/components/ui/text'; + +export function UnassignedNote() { + return ( + + Not in a project yet — its AR page shows only the thob logo. Moving it into a project adds the client logo; the printed QR keeps working. + + ); +} diff --git a/app/components/assets/form/asset-form-dialog.tsx b/app/components/assets/form/asset-form-dialog.tsx new file mode 100644 index 0000000..5399977 --- /dev/null +++ b/app/components/assets/form/asset-form-dialog.tsx @@ -0,0 +1,79 @@ +import { FormProvider, useForm } from 'react-hook-form'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useFetcher } from 'react-router'; +import { Dialog, DialogBody, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '~/components/ui/dialog'; +import { DialogActions } from '~/components/ui/dialog-actions'; +import { Field } from '~/components/ui/field'; +import { Input } from '~/components/ui/input'; +import { BrandedQrField } from '~/components/assets/form/branded-qr-field'; +import { ModelSourceField } from '~/components/assets/form/model-source-field'; +import { ProjectSelectField } from '~/components/assets/form/project-select-field'; +import { ASSET_INTENT, type AssetIntent } from '~/data/assets/constants'; +import { ROUTES } from '~/data/routes'; +import { useActionToast } from '~/hooks/use-action-toast'; +import { useAdminData } from '~/hooks/admin/use-admin-data'; +import { toAssetFormData } from '~/lib/assets/form-data'; +import { assetFormSchema, toAssetFormValues, type AssetFormValues } from '~/schemas/assets/asset-form'; +import type { ActionResult } from '~/types/action'; +import type { ArAsset } from '~/types/asset'; + +interface AssetFormDialogProps { + open: boolean; + asset: ArAsset | null; + projectId?: string; + onOpenChange: (open: boolean) => void; +} + +export function AssetFormDialog({ open, asset, projectId, onOpenChange }: AssetFormDialogProps) { + const { settings } = useAdminData(); + const fetcher = useFetcher>(); + const form = useForm({ + resolver: zodResolver(assetFormSchema), + defaultValues: toAssetFormValues(asset, { projectId, brandedQr: settings.branded_qr_default }), + }); + const { errors } = form.formState; + const intent = asset ? ASSET_INTENT.update : ASSET_INTENT.create; + + useActionToast(fetcher.data, () => onOpenChange(false)); + + return ( + + + + {asset ? 'Edit asset' : 'New asset'} + {asset ? asset.name : 'Add a 3D model and get a QR code for it.'} + + +
+ fetcher.submit(toAssetFormData(intent, values), { method: 'post', action: ROUTES.assets, encType: 'multipart/form-data' }), + )} + > + + + + + + + + + {!asset && ( + + + + )} + + + +
+
+
+ ); +} diff --git a/app/components/assets/form/branded-qr-field.tsx b/app/components/assets/form/branded-qr-field.tsx new file mode 100644 index 0000000..1476c87 --- /dev/null +++ b/app/components/assets/form/branded-qr-field.tsx @@ -0,0 +1,25 @@ +import { useFormContext, useWatch } from 'react-hook-form'; +import { SwitchRow } from '~/components/ui/switch-row'; +import { useAdminData } from '~/hooks/admin/use-admin-data'; +import type { AssetFormValues } from '~/schemas/assets/asset-form'; + +// Only offered when the chosen project has a logo to put on the QR code +export function BrandedQrField() { + const { projects } = useAdminData(); + const { control, setValue } = useFormContext(); + const [projectId, brandedQr] = useWatch({ control, name: ['project', 'brandedQr'] }); + const project = projects.find((item) => item.id === projectId); + + if (!project?.logo) return null; + + return ( + setValue('brandedQr', checked, { shouldDirty: true })} + /> + ); +} diff --git a/app/components/assets/form/file-picker.tsx b/app/components/assets/form/file-picker.tsx new file mode 100644 index 0000000..5cfd1b0 --- /dev/null +++ b/app/components/assets/form/file-picker.tsx @@ -0,0 +1,35 @@ +import { UploadCloud } from 'lucide-react'; +import { DropZone } from '~/components/ui/drop-zone'; +import { Text } from '~/components/ui/text'; +import { SelectedFile } from '~/components/assets/form/selected-file'; +import { formatFileSize } from '~/lib/format'; + +interface FilePickerProps { + id?: string; + accept: string; + file: File | null; + existing: string; + invalid?: boolean; + onFileChange: (file: File | null) => void; + onClearExisting: () => void; +} + +export function FilePicker({ id, accept, file, existing, invalid, onFileChange, onClearExisting }: FilePickerProps) { + return ( + + {file ? ( + onFileChange(null)} /> + ) : existing ? ( + + ) : ( +
+ + + Click to upload or drag a file here{' '} + ({accept}) + +
+ )} +
+ ); +} diff --git a/app/components/assets/form/model-source-field.tsx b/app/components/assets/form/model-source-field.tsx new file mode 100644 index 0000000..a7a69ee --- /dev/null +++ b/app/components/assets/form/model-source-field.tsx @@ -0,0 +1,64 @@ +import { useFormContext, useWatch } from 'react-hook-form'; +import { Link2 } from 'lucide-react'; +import { Field } from '~/components/ui/field'; +import { IconInput } from '~/components/ui/icon-input'; +import { SegmentedControl } from '~/components/ui/segmented-control'; +import { FilePicker } from '~/components/assets/form/file-picker'; +import { MODEL_FIELDS, MODEL_SOURCE_OPTIONS, type ModelFieldName } from '~/data/assets/constants'; +import type { AssetFormValues } from '~/schemas/assets/asset-form'; + +export function ModelSourceField({ name, required }: { name: ModelFieldName; required?: boolean }) { + const { control, register, setValue, trigger, formState } = useFormContext(); + const source = useWatch({ control, name }); + const config = MODEL_FIELDS[name]; + const fieldErrors = formState.errors[name]; + const error = fieldErrors?.file?.message ?? fieldErrors?.url?.message; + const inputId = `${name}-source`; + + // Re-validates the whole source once the form has been submitted, so errors for the other mode clear + const update = (patch: Partial) => { + setValue(name, { ...source, ...patch }); + if (formState.isSubmitted) trigger(name); + }; + + return ( + update({ mode })} + /> + } + > + {source.mode === 'file' ? ( + update({ file })} + onClearExisting={() => update({ existing: '' })} + /> + ) : ( + + )} + + ); +} diff --git a/app/components/assets/form/project-select-field.tsx b/app/components/assets/form/project-select-field.tsx new file mode 100644 index 0000000..d050792 --- /dev/null +++ b/app/components/assets/form/project-select-field.tsx @@ -0,0 +1,35 @@ +import { useFormContext, useWatch } from 'react-hook-form'; +import { ClientLogo } from '~/components/ui/client-logo'; +import { Field } from '~/components/ui/field'; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '~/components/ui/select'; +import { NO_PROJECT } from '~/data/assets/constants'; +import { useAdminData } from '~/hooks/admin/use-admin-data'; +import type { AssetFormValues } from '~/schemas/assets/asset-form'; +import { toBrand } from '~/services/asset-media'; + +export function ProjectSelectField() { + const { projects } = useAdminData(); + const { control, setValue } = useFormContext(); + const value = useWatch({ control, name: 'project' }); + // Archived projects are only listed when the asset already belongs to one + const options = projects.filter((project) => project.status === 'active' || project.id === value); + + return ( + + + + ); +} diff --git a/app/components/assets/form/selected-file.tsx b/app/components/assets/form/selected-file.tsx new file mode 100644 index 0000000..1574699 --- /dev/null +++ b/app/components/assets/form/selected-file.tsx @@ -0,0 +1,31 @@ +import { FileBox, X } from 'lucide-react'; +import { Button } from '~/components/ui/button'; +import { IconTile } from '~/components/ui/icon-tile'; +import { TextPair } from '~/components/ui/text-pair'; + +interface SelectedFileProps { + name: string; + meta: string; + onRemove: () => void; +} + +export function SelectedFile({ name, meta, onRemove }: SelectedFileProps) { + return ( +
+ + + +
+ ); +} diff --git a/app/components/assets/list/asset-card.tsx b/app/components/assets/list/asset-card.tsx new file mode 100644 index 0000000..995cd54 --- /dev/null +++ b/app/components/assets/list/asset-card.tsx @@ -0,0 +1,41 @@ +import { memo } from 'react'; +import { Link } from 'react-router'; +import { Pencil, Trash2 } from 'lucide-react'; +import { Button } from '~/components/ui/button'; +import { Card } from '~/components/ui/card'; +import { TextPair } from '~/components/ui/text-pair'; +import { AssetQr } from '~/components/assets/asset-qr'; +import { AssetProjectChip } from '~/components/assets/list/asset-project-chip'; +import { ROUTES } from '~/data/routes'; +import { formatDate } from '~/lib/format'; +import type { ArAsset } from '~/types/asset'; + +interface AssetCardProps { + asset: ArAsset; + showProject: boolean; + onEdit: (asset: ArAsset) => void; + onDelete: (asset: ArAsset) => void; +} + +export const AssetCard = memo(function AssetCard({ asset, showProject, onEdit, onDelete }: AssetCardProps) { + const name = asset.name || 'Untitled'; + return ( + + +
+ + + +
+ + +
+
+ {showProject && } +
+ ); +}); diff --git a/app/components/assets/list/asset-filter-chips.tsx b/app/components/assets/list/asset-filter-chips.tsx new file mode 100644 index 0000000..13de961 --- /dev/null +++ b/app/components/assets/list/asset-filter-chips.tsx @@ -0,0 +1,22 @@ +import { FilterChip } from '~/components/ui/filter-chip'; +import { ASSET_FILTER } from '~/data/assets/constants'; +import { ROUTES } from '~/data/routes'; +import type { ProjectSummary } from '~/types/project'; + +export function AssetFilterChips({ filter, projects }: { filter: string; projects: ProjectSummary[] }) { + const chips = [ + { value: ASSET_FILTER.all, label: 'All', to: ROUTES.assets }, + ...projects.map((project) => ({ value: project.id, label: project.name, to: ROUTES.assetsFiltered(project.id) })), + { value: ASSET_FILTER.unassigned, label: 'Unassigned', to: ROUTES.assetsFiltered(ASSET_FILTER.unassigned) }, + ]; + + return ( + + ); +} diff --git a/app/components/assets/list/asset-list.tsx b/app/components/assets/list/asset-list.tsx new file mode 100644 index 0000000..9b460d5 --- /dev/null +++ b/app/components/assets/list/asset-list.tsx @@ -0,0 +1,37 @@ +import { useCallback } from 'react'; +import { EmptyState } from '~/components/ui/empty-state'; +import { AssetCard } from '~/components/assets/list/asset-card'; +import { AssetPagination } from '~/components/assets/list/asset-pagination'; +import { useAdminDialogs } from '~/hooks/admin/use-admin-dialogs'; +import type { ArAsset, AssetPage } from '~/types/asset'; + +interface AssetListProps { + assets: AssetPage; + showProject: boolean; + emptyTitle: string; + emptyMessage?: string; +} + +export function AssetList({ assets, showProject, emptyTitle, emptyMessage }: AssetListProps) { + const { openAsset, confirmDeleteAsset } = useAdminDialogs(); + const editAsset = useCallback((asset: ArAsset) => openAsset({ asset }), [openAsset]); + + if (assets.items.length === 0) return ; + + return ( +
+
+ {assets.items.map((asset) => ( + + ))} +
+ +
+ ); +} diff --git a/app/components/assets/list/asset-pagination.tsx b/app/components/assets/list/asset-pagination.tsx new file mode 100644 index 0000000..01bdbf5 --- /dev/null +++ b/app/components/assets/list/asset-pagination.tsx @@ -0,0 +1,44 @@ +import { ChevronLeft, ChevronRight } from 'lucide-react'; +import { Text } from '~/components/ui/text'; +import { PaginationLink } from '~/components/assets/list/pagination-link'; +import { ASSETS_PAGE_SIZE } from '~/data/assets/constants'; +import { getPaginationRange } from '~/lib/pagination'; + +interface AssetPaginationProps { + page: number; + totalPages: number; + totalItems: number; +} + +export function AssetPagination({ page, totalPages, totalItems }: AssetPaginationProps) { + if (totalItems === 0) return null; + const first = (page - 1) * ASSETS_PAGE_SIZE + 1; + const last = Math.min(page * ASSETS_PAGE_SIZE, totalItems); + + return ( + + ); +} diff --git a/app/components/assets/list/asset-project-chip.tsx b/app/components/assets/list/asset-project-chip.tsx new file mode 100644 index 0000000..e84d3db --- /dev/null +++ b/app/components/assets/list/asset-project-chip.tsx @@ -0,0 +1,15 @@ +import { ClientLogo } from '~/components/ui/client-logo'; +import { Text } from '~/components/ui/text'; +import { toBrand } from '~/services/asset-media'; +import type { Project } from '~/types/project'; + +export function AssetProjectChip({ project }: { project?: Project }) { + return ( +
+ {project && } + + {project?.name ?? 'Unassigned'} + +
+ ); +} diff --git a/app/components/assets/list/pagination-link.tsx b/app/components/assets/list/pagination-link.tsx new file mode 100644 index 0000000..c9249da --- /dev/null +++ b/app/components/assets/list/pagination-link.tsx @@ -0,0 +1,33 @@ +import type { ReactNode } from 'react'; +import { Link, useLocation } from 'react-router'; +import { Button } from '~/components/ui/button'; +import { cn } from '~/lib/utils'; + +interface PaginationLinkProps { + page: number; + active?: boolean; + disabled?: boolean; + label?: string; + children: ReactNode; +} + +// Links to another page of the current list, keeping its other search params (e.g. the filter) +export function PaginationLink({ page, active, disabled, label, children }: PaginationLinkProps) { + const { search } = useLocation(); + const params = new URLSearchParams(search); + params.set('page', String(page)); + + return ( + + ); +} diff --git a/app/components/auth/ar-illustration.tsx b/app/components/auth/ar-illustration.tsx deleted file mode 100644 index d038cf5..0000000 --- a/app/components/auth/ar-illustration.tsx +++ /dev/null @@ -1,129 +0,0 @@ -import { Armchair } from '~/components/auth/armchair'; - -export function ArIllustration() { - return ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {/* Phone body */} - - - - - {/* Wall / floor horizon */} - - - {/* Perspective floor seen through the camera */} - - {[240, 262, 290, 326, 372].map((y) => ( - - ))} - {[-260, -170, -90, -30, 30, 90, 170, 260].map((dx) => ( - - ))} - - - - - {/* Placement reticle */} - - - - - - - - - - {/* Camera scan brackets */} - - - - - - - - {/* AR badge */} - - AR - - {/* Shutter */} - - - - - {/* Notch */} - - - {/* Floating particles */} - {[ - { cx: 70, cy: 120, r: 3, d: '3s' }, - { cx: 330, cy: 90, r: 2, d: '4s' }, - { cx: 345, cy: 260, r: 3, d: '3.6s' }, - { cx: 55, cy: 300, r: 2, d: '4.4s' }, - { cx: 95, cy: 210, r: 1.5, d: '2.8s' }, - ].map((p) => ( - - - - ))} - - ); -} diff --git a/app/components/auth/armchair.tsx b/app/components/auth/armchair.tsx deleted file mode 100644 index cc8ec78..0000000 --- a/app/components/auth/armchair.tsx +++ /dev/null @@ -1,43 +0,0 @@ -// SVG armchair drawn in the coordinate space of ; relies on its gradient/filter defs. -export function Armchair() { - return ( - - {/* Contact shadow */} - - - {/* Back legs */} - - - - {/* Backrest */} - - - - {/* Tufting */} - - {[[184, 210], [200, 206], [216, 210], [192, 230], [208, 230]].map(([cx, cy]) => ( - - ))} - - - - - - {/* Seat base */} - - {/* Seat cushion */} - - - - {/* Armrests */} - - - - - - {/* Front legs */} - - - - ); -} diff --git a/app/components/auth/auth-brand-panel.tsx b/app/components/auth/auth-brand-panel.tsx deleted file mode 100644 index 5ca808a..0000000 --- a/app/components/auth/auth-brand-panel.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { LogoMark } from '~/components/logo-mark'; -import { ArIllustration } from '~/components/auth/ar-illustration'; - -export function AuthBrandPanel() { - return ( - - ); -} diff --git a/app/components/auth/form/access-note.tsx b/app/components/auth/form/access-note.tsx new file mode 100644 index 0000000..3fe67d4 --- /dev/null +++ b/app/components/auth/form/access-note.tsx @@ -0,0 +1,12 @@ +import { Text } from '~/components/ui/text'; + +export function AccessNote({ className }: { className?: string }) { + return ( + + Need access?{' '} + + Ask your workspace admin + + + ); +} diff --git a/app/components/auth/form/login-form.tsx b/app/components/auth/form/login-form.tsx new file mode 100644 index 0000000..3c449b3 --- /dev/null +++ b/app/components/auth/form/login-form.tsx @@ -0,0 +1,106 @@ +import { useState } from 'react'; +import { Controller, useForm } from 'react-hook-form'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useNavigation, useSubmit } from 'react-router'; +import { Mail, Shield } from 'lucide-react'; +import { toast } from 'sonner'; +import { AccessNote } from '~/components/auth/form/access-note'; +import { PasswordInput } from '~/components/auth/form/password-input'; +import { SignInButton } from '~/components/auth/form/sign-in-button'; +import { Alert } from '~/components/ui/alert'; +import { Button } from '~/components/ui/button'; +import { Checkbox } from '~/components/ui/checkbox'; +import { Field } from '~/components/ui/field'; +import { IconInput } from '~/components/ui/icon-input'; +import { Text } from '~/components/ui/text'; +import { ROUTES } from '~/data/routes'; +import { loginSchema, type LoginValues } from '~/schemas/auth/login'; +import type { LoginFailure } from '~/types/auth'; + +type TextField = 'email' | 'password'; + +export function LoginForm({ failure }: { failure?: LoginFailure }) { + const submit = useSubmit(); + const navigation = useNavigation(); + const busy = navigation.state !== 'idle'; + // Loading a page other than /login means the sign-in worked and the admin is on its way + const signedIn = navigation.state === 'loading' && navigation.location.pathname !== ROUTES.login; + // The failure the user has typed since; its banner and red borders are hidden + const [dismissed, setDismissed] = useState(); + const shown = failure === dismissed ? undefined : failure; + const { + register, + control, + clearErrors, + handleSubmit, + formState: { errors }, + } = useForm({ resolver: zodResolver(loginSchema), reValidateMode: 'onSubmit', defaultValues: { email: '', password: '', remember: true } }); + + // Typing clears that field's error and the banner + const textField = (name: TextField) => ({ + ...register(name, { + onChange: () => { + clearErrors(name); + setDismissed(failure); + }, + }), + 'aria-invalid': !!errors[name] || !!shown?.invalidCredentials, + }); + + return ( +
submit(values, { method: 'post', encType: 'application/json' }))} + noValidate + className='flex w-full max-w-[372px] flex-col gap-7.5' + > +
+ Admin portal + Welcome back + Sign in to manage client projects, 3D assets and QR codes. +
+ + {shown && {shown.error}} + +
+ + + + + toast.info('Ask your workspace admin to reset your password.')}> + Forgot password? + + } + > + + + + ( +
+ onChange(checked === true)} /> + + Keep me signed in for 30 days + +
+ )} + /> +
+ +
+ + + + Access is restricted to authorised team members. + + +
+
+ ); +} diff --git a/app/components/auth/form/login-panel.tsx b/app/components/auth/form/login-panel.tsx new file mode 100644 index 0000000..184ff02 --- /dev/null +++ b/app/components/auth/form/login-panel.tsx @@ -0,0 +1,26 @@ +import { AccessNote } from '~/components/auth/form/access-note'; +import { LoginForm } from '~/components/auth/form/login-form'; +import { BrandLockup } from '~/components/ui/brand-lockup'; +import { Text } from '~/components/ui/text'; +import { BRAND } from '~/data/brand'; +import type { LoginFailure } from '~/types/auth'; + +// Full height on phones; natural height above the showcase on tablets; a fixed column beside it from 960px +export function LoginPanel({ failure }: { failure?: LoginFailure }) { + return ( +
+
+ + +
+ +
+ +
+ + + © {new Date().getFullYear()} {BRAND.name} + +
+ ); +} diff --git a/app/components/auth/form/password-input.tsx b/app/components/auth/form/password-input.tsx new file mode 100644 index 0000000..71cd84b --- /dev/null +++ b/app/components/auth/form/password-input.tsx @@ -0,0 +1,39 @@ +import { useState } from 'react'; +import { Lock } from 'lucide-react'; +import { Button } from '~/components/ui/button'; +import { IconInput } from '~/components/ui/icon-input'; +import { InlineMessage } from '~/components/ui/inline-message'; +import type { InputProps } from '~/components/ui/input'; + +export function PasswordInput(props: Omit) { + const [visible, setVisible] = useState(false); + const [capsLock, setCapsLock] = useState(false); + + return ( + <> + setCapsLock(e.getModifierState('CapsLock'))} + trailing={ + + } + {...props} + onBlur={(e) => { + setCapsLock(false); + props.onBlur?.(e); + }} + /> + {capsLock && Caps Lock is on} + + ); +} diff --git a/app/components/auth/form/sign-in-button.tsx b/app/components/auth/form/sign-in-button.tsx new file mode 100644 index 0000000..36922e5 --- /dev/null +++ b/app/components/auth/form/sign-in-button.tsx @@ -0,0 +1,22 @@ +import { ArrowRight, Loader2 } from 'lucide-react'; +import { Button } from '~/components/ui/button'; +import { BRAND } from '~/data/brand'; + +export type SignInState = 'idle' | 'busy' | 'done'; + +const LABELS: Record = { + idle: 'Sign in', + busy: 'Signing in…', + done: `Signed in. Opening ${BRAND.product}`, +}; + +export function SignInButton({ state }: { state: SignInState }) { + const working = state !== 'idle'; + return ( + + ); +} diff --git a/app/components/auth/showcase/armchair.tsx b/app/components/auth/showcase/armchair.tsx new file mode 100644 index 0000000..997cb70 --- /dev/null +++ b/app/components/auth/showcase/armchair.tsx @@ -0,0 +1,68 @@ +import { useId } from 'react'; + +// Gradient direction (x2, y2) and colour stops, spread evenly +const GRADIENTS = { + back: { x2: 1, y2: 1, stops: ['accent-400', 'accent-700', 'accent-900'] }, + backInner: { x2: 0, y2: 1, stops: ['primary', 'accent-800'] }, + cushion: { x2: 0, y2: 1, stops: ['accent-300', 'accent-600'] }, + base: { x2: 0, y2: 1, stops: ['accent-700', 'accent-900'] }, + armLeft: { x2: 1, y2: 0, stops: ['accent-800', 'accent-600'] }, + armRight: { x2: 1, y2: 0, stops: ['primary', 'accent-800'] }, + wood: { x2: 0, y2: 1, stops: ['wood-light', 'wood-dark'] }, +} as const; + +const TUFTS = [[184, 210], [200, 206], [216, 210], [192, 230], [208, 230]] as const; + +// An orange armchair, the stand-in 3D model in the login story. Its contact shadow sits at 86% of the height; +// the view box leaves room around it so the blur isn't clipped. +export function Armchair({ className }: { className?: string }) { + const id = useId(); + const fill = (name: keyof typeof GRADIENTS) => `url(#${id}${name})`; + + return ( + + ); +} diff --git a/app/components/auth/showcase/login-showcase.tsx b/app/components/auth/showcase/login-showcase.tsx new file mode 100644 index 0000000..90bd751 --- /dev/null +++ b/app/components/auth/showcase/login-showcase.tsx @@ -0,0 +1,54 @@ +import { useId, useState } from 'react'; +import { StoryPhone } from '~/components/auth/showcase/story-phone'; +import { StorySteps } from '~/components/auth/showcase/story-steps'; +import { BrandLockup } from '~/components/ui/brand-lockup'; +import { Glow } from '~/components/ui/glow'; +import { Text } from '~/components/ui/text'; +import { LOGIN_STORY } from '~/data/auth/constants'; + +const fadeUp = 'linear-gradient(to top, black, transparent)'; +const floorGrid = { + backgroundImage: + 'linear-gradient(var(--color-border-divider) 1px, transparent 1px), linear-gradient(90deg, var(--color-border-divider) 1px, transparent 1px)', + backgroundSize: '64px 64px', + maskImage: fadeUp, + WebkitMaskImage: fadeUp, +}; + +// Hidden on phones; under the form on tablets; the left side from 960px, with the text beside the phone from 1200px +export function LoginShowcase() { + const headingId = useId(); + const [story, setStory] = useState({ step: 0, cycle: 0 }); + // A new cycle restarts the progress bar, even when the current step is picked again + const select = (step: number) => setStory((s) => ({ step, cycle: s.cycle + 1 })); + const steps = { active: story.step, cycle: story.cycle, onSelect: select, onComplete: () => select((story.step + 1) % LOGIN_STORY.length) }; + + return ( + + ); +} diff --git a/app/components/auth/showcase/open-screen.tsx b/app/components/auth/showcase/open-screen.tsx new file mode 100644 index 0000000..ff6cc72 --- /dev/null +++ b/app/components/auth/showcase/open-screen.tsx @@ -0,0 +1,13 @@ +import { ArPage } from '~/components/ui/ar-page'; +import { DEMO_CLIENT, DEMO_MODEL_IMAGE, DEMO_MODEL_NAME } from '~/data/auth/constants'; + +// Step 2: the customer AR page, with the client logo next to thob's +export function OpenScreen() { + return ( + +
+ +
+
+ ); +} diff --git a/app/components/auth/showcase/place-screen.tsx b/app/components/auth/showcase/place-screen.tsx new file mode 100644 index 0000000..1023b21 --- /dev/null +++ b/app/components/auth/showcase/place-screen.tsx @@ -0,0 +1,32 @@ +import { ClientLogo } from '~/components/ui/client-logo'; +import { LogoMark } from '~/components/ui/logo-mark'; +import { Text } from '~/components/ui/text'; +import { DEMO_CLIENT, DEMO_MODEL_IMAGE } from '~/data/auth/constants'; + +const room = 'linear-gradient(180deg, var(--color-room-wall) 50%, var(--color-room-floor) 50%, var(--color-room-floor-near))'; + +// Step 3: the model placed on the floor of the customer's room +export function PlaceScreen() { + return ( + <> +
+
+ + +
+ + Live camera · your room + + + {/* Standing on the floor, just below the horizon */} + + + Placed · 1:1 scale + + + + + + + ); +} diff --git a/app/components/auth/showcase/scan-screen.tsx b/app/components/auth/showcase/scan-screen.tsx new file mode 100644 index 0000000..6e48ab2 --- /dev/null +++ b/app/components/auth/showcase/scan-screen.tsx @@ -0,0 +1,47 @@ +import { ClientLogo } from '~/components/ui/client-logo'; +import { Text } from '~/components/ui/text'; +import { DEMO_CLIENT_MARK, DEMO_QR_CODE } from '~/data/auth/constants'; +import { getFrontendHost } from '~/lib/assets/qr'; +import { cn } from '~/lib/utils'; + +const CORNERS = [ + 'top-0 left-0 rounded-tl-card-sm border-t-3 border-l-3', + 'top-0 right-0 rounded-tr-card-sm border-t-3 border-r-3', + 'bottom-0 left-0 rounded-bl-card-sm border-b-3 border-l-3', + 'bottom-0 right-0 rounded-br-card-sm border-b-3 border-r-3', +]; + +// Step 1: the camera finds the printed QR code (the phone's dark screen is the camera view) +export function ScanScreen() { + return ( +
+ + Camera + + +
+
+ {CORNERS.map((corner) => ( + + ))} + {/* The code is 33 squares across: 132px keeps every square exactly 4px, so it renders sharp */} +
+ + +
+ {/* Thin, softly lit scan line; moved with transform only, and hidden with reduced motion */} + + + +
+
+ +
+ + + Open “{getFrontendHost()}” in Safari + +
+
+ ); +} diff --git a/app/components/auth/showcase/story-phone.tsx b/app/components/auth/showcase/story-phone.tsx new file mode 100644 index 0000000..fda4e66 --- /dev/null +++ b/app/components/auth/showcase/story-phone.tsx @@ -0,0 +1,26 @@ +import { OpenScreen } from '~/components/auth/showcase/open-screen'; +import { PlaceScreen } from '~/components/auth/showcase/place-screen'; +import { ScanScreen } from '~/components/auth/showcase/scan-screen'; +import { PhoneFrame } from '~/components/ui/phone-frame'; + +// One screen per LOGIN_STORY step, in the same order +const SCREENS = [ + { Screen: ScanScreen, tone: 'dark' }, + { Screen: OpenScreen, tone: 'light' }, + { Screen: PlaceScreen, tone: 'dark' }, +] as const; + +// Decorative: hidden from assistive tech and never focusable. Tilted only in the wide layout. +export function StoryPhone({ step }: { step: number }) { + const { Screen, tone } = SCREENS[step] ?? SCREENS[0]; + return ( + + ); +} diff --git a/app/components/auth/showcase/story-step.tsx b/app/components/auth/showcase/story-step.tsx new file mode 100644 index 0000000..bf22a69 --- /dev/null +++ b/app/components/auth/showcase/story-step.tsx @@ -0,0 +1,61 @@ +import { cva } from 'class-variance-authority'; +import { Text } from '~/components/ui/text'; +import { LOGIN_STORY_STEP_MS, type LoginStoryStep } from '~/data/auth/constants'; +import { cn } from '~/lib/utils'; + +const shell = cva('relative flex cursor-pointer overflow-hidden text-left ring-1 ring-inset transition-colors duration-200', { + variants: { + layout: { + card: 'w-full gap-4 rounded-card-sm px-4 pt-3.5 pb-4 hover:bg-surface-dialog', + pill: 'h-[38px] items-center gap-2 whitespace-nowrap rounded-full px-3.5', + }, + active: { true: 'bg-surface', false: '' }, + }, + compoundVariants: [ + { layout: 'card', active: true, className: 'ring-border-dialog' }, + { layout: 'card', active: false, className: 'ring-transparent' }, + { layout: 'pill', active: true, className: 'ring-border-control' }, + { layout: 'pill', active: false, className: 'ring-border-divider' }, + ], +}); + +interface StoryStepProps { + step: LoginStoryStep; + // card: number, title and description (wide layout); pill: number and title + layout: 'card' | 'pill'; + active: boolean; + // Restarts the progress bar + cycle: number; + onSelect: () => void; + onComplete: () => void; +} + +export function StoryStep({ step, layout, active, cycle, onSelect, onComplete }: StoryStepProps) { + const card = layout === 'card'; + return ( + + ); +} diff --git a/app/components/auth/showcase/story-steps.tsx b/app/components/auth/showcase/story-steps.tsx new file mode 100644 index 0000000..d20f9c6 --- /dev/null +++ b/app/components/auth/showcase/story-steps.tsx @@ -0,0 +1,24 @@ +import { StoryStep } from '~/components/auth/showcase/story-step'; +import { LOGIN_STORY } from '~/data/auth/constants'; +import { cn } from '~/lib/utils'; + +interface StoryStepsProps { + layout: 'card' | 'pill'; + active: number; + cycle: number; + onSelect: (step: number) => void; + onComplete: () => void; + className?: string; +} + +export function StorySteps({ layout, active, cycle, onSelect, onComplete, className }: StoryStepsProps) { + return ( +
    + {LOGIN_STORY.map((step, i) => ( +
  1. + onSelect(i)} onComplete={onComplete} /> +
  2. + ))} +
+ ); +} diff --git a/app/components/logo-mark.tsx b/app/components/logo-mark.tsx deleted file mode 100644 index 1236eca..0000000 --- a/app/components/logo-mark.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { cn } from '~/lib/utils'; - -export function LogoMark({ className }: { className?: string }) { - return ( -
- t. -
- ); -} diff --git a/app/components/projects/detail/project-header.tsx b/app/components/projects/detail/project-header.tsx new file mode 100644 index 0000000..a97c00a --- /dev/null +++ b/app/components/projects/detail/project-header.tsx @@ -0,0 +1,40 @@ +import { Pencil } from 'lucide-react'; +import { AddButton } from '~/components/ui/add-button'; +import { Button } from '~/components/ui/button'; +import { LogoTile } from '~/components/ui/logo-tile'; +import { PageBreadcrumb } from '~/components/ui/page-breadcrumb'; +import { Text } from '~/components/ui/text'; +import { ProjectMeta } from '~/components/projects/detail/project-meta'; +import { ROUTES } from '~/data/routes'; +import { toBrand } from '~/services/asset-media'; +import type { Project } from '~/types/project'; + +interface ProjectHeaderProps { + project: Project; + assetCount: number; + onEdit: () => void; + onNewAsset: () => void; +} + +export function ProjectHeader({ project, assetCount, onEdit, onNewAsset }: ProjectHeaderProps) { + return ( + <> + +
+ +
+ {project.name} + {project.description && {project.description}} + +
+
+ + +
+
+ + ); +} diff --git a/app/components/projects/detail/project-meta.tsx b/app/components/projects/detail/project-meta.tsx new file mode 100644 index 0000000..76dc68d --- /dev/null +++ b/app/components/projects/detail/project-meta.tsx @@ -0,0 +1,40 @@ +import { ColorTag } from '~/components/ui/color-tag'; +import { Text } from '~/components/ui/text'; +import { AR_BUTTON_LABEL } from '~/data/ar-viewer/constants'; +import { DEFAULT_BRAND_COLOR, LOGO_BACKGROUND_PRESETS } from '~/data/projects/constants'; +import { useAdminData } from '~/hooks/admin/use-admin-data'; +import { formatDate } from '~/lib/format'; +import { cn } from '~/lib/utils'; +import { getButtonStyle } from '~/services/asset-media'; +import type { Project } from '~/types/project'; + +export function ProjectMeta({ project, assetCount }: { project: Project; assetCount: number }) { + const { settings } = useAdminData(); + const archived = project.status === 'archived'; + const button = getButtonStyle(project, settings); + const preset = LOGO_BACKGROUND_PRESETS[project.logo_bg]; + + return ( +
+ + + {archived ? 'Archived' : 'Active'} + + + {assetCount} {assetCount === 1 ? 'asset' : 'assets'} + + Created {formatDate(project.created)} + + Logo backing + + + {settings.brand_button && ( + + Button + + “{button.label ?? AR_BUTTON_LABEL}” + + )} +
+ ); +} diff --git a/app/components/projects/form/ar-page-fields.tsx b/app/components/projects/form/ar-page-fields.tsx new file mode 100644 index 0000000..50431dd --- /dev/null +++ b/app/components/projects/form/ar-page-fields.tsx @@ -0,0 +1,32 @@ +import { useId } from 'react'; +import { useFormContext, useWatch } from 'react-hook-form'; +import { SwitchRow } from '~/components/ui/switch-row'; +import { Text } from '~/components/ui/text'; +import { AR_PAGE_TOGGLES } from '~/data/projects/constants'; +import type { ProjectFormValues } from '~/schemas/projects/project-form'; + +// What the client's AR page shows around the model +export function ArPageFields() { + const headingId = useId(); + const { control, setValue } = useFormContext(); + const arPage = useWatch({ control, name: 'arPage' }); + + return ( +
+ + AR page + + {AR_PAGE_TOGGLES.map(({ key, label, hint }) => ( + setValue(`arPage.${key}`, checked, { shouldDirty: true })} + /> + ))} +
+ ); +} diff --git a/app/components/projects/form/button-custom-fields.tsx b/app/components/projects/form/button-custom-fields.tsx new file mode 100644 index 0000000..c7f2d2b --- /dev/null +++ b/app/components/projects/form/button-custom-fields.tsx @@ -0,0 +1,59 @@ +import { useFormContext, useWatch } from 'react-hook-form'; +import { ColorPicker } from '~/components/ui/color-picker'; +import { Field } from '~/components/ui/field'; +import { Input } from '~/components/ui/input'; +import { BUTTON_CUSTOM_LIMITS, BUTTON_TEXT_COLORS } from '~/data/projects/constants'; +import type { ProjectFormValues } from '~/schemas/projects/project-form'; + +type Measurement = keyof typeof BUTTON_CUSTOM_LIMITS; +const MEASUREMENTS = Object.keys(BUTTON_CUSTOM_LIMITS) as Measurement[]; + +// An empty box is "not set": no width means the button fits its label; anything else must be filled in. +// The form also passes stored values through here (a saved empty width is null), not only typed text. +const toNumber = (optional: boolean) => (value: unknown) => { + if (value === '' || value === null || value === undefined) return optional ? null : Number.NaN; + return Number(value); +}; + +// Exact button measurements for the "Custom" size +export function ButtonCustomFields() { + const { register, control, setValue, formState } = useFormContext(); + const [borderWidth, borderColor] = useWatch({ control, name: ['arPage.buttonCustom.borderWidth', 'arPage.buttonCustom.borderColor'] }); + const errors = formState.errors.arPage?.buttonCustom; + + return ( +
+
+ {MEASUREMENTS.map((key) => { + const { label, min, max } = BUTTON_CUSTOM_LIMITS[key]; + const optional = key === 'width'; + return ( + + + + ); + })} +
+ {borderWidth > 0 && ( + + setValue('arPage.buttonCustom.borderColor', hex, { shouldDirty: true })} + /> + + )} +
+ ); +} diff --git a/app/components/projects/form/button-style-fields.tsx b/app/components/projects/form/button-style-fields.tsx new file mode 100644 index 0000000..8e3cd8c --- /dev/null +++ b/app/components/projects/form/button-style-fields.tsx @@ -0,0 +1,58 @@ +import { useFormContext, useWatch } from 'react-hook-form'; +import { Field } from '~/components/ui/field'; +import { Input } from '~/components/ui/input'; +import { SegmentedControl } from '~/components/ui/segmented-control'; +import { ButtonCustomFields } from '~/components/projects/form/button-custom-fields'; +import { ColorField } from '~/components/projects/form/color-field'; +import { AR_BUTTON_LABEL } from '~/data/ar-viewer/constants'; +import { BRAND_COLORS, BUTTON_LABEL_MAX, BUTTON_SIZE_OPTIONS, BUTTON_SIZES, BUTTON_TEXT_COLORS } from '~/data/projects/constants'; +import type { ProjectFormValues } from '~/schemas/projects/project-form'; +import type { ButtonSize } from '~/types/project'; + +// The client's "View in your space" button: colour, text colour, label and size +export function ButtonStyleFields() { + const { register, control, setValue, formState } = useFormContext(); + const [size, custom] = useWatch({ control, name: ['arPage.buttonSize', 'arPage.buttonCustom'] }); + + // Custom starts from the preset that was selected, so the button doesn't jump + const changeSize = (next: ButtonSize) => { + if (next === 'custom' && size !== 'custom') { + const preset = BUTTON_SIZES[size === 'full' ? 'md' : size]; + setValue('arPage.buttonCustom', { ...custom, height: preset.height, paddingX: preset.paddingX, radius: preset.height / 2, width: null }, { shouldDirty: true }); + } + setValue('arPage.buttonSize', next, { shouldDirty: true }); + }; + + return ( + <> + + + + + + + + + {size === 'custom' && } + + ); +} diff --git a/app/components/projects/form/color-field.tsx b/app/components/projects/form/color-field.tsx new file mode 100644 index 0000000..37d2ab8 --- /dev/null +++ b/app/components/projects/form/color-field.tsx @@ -0,0 +1,24 @@ +import { useFormContext, useWatch } from 'react-hook-form'; +import { ColorPicker } from '~/components/ui/color-picker'; +import { Field } from '~/components/ui/field'; +import type { ProjectFormValues } from '~/schemas/projects/project-form'; +import type { ColorPreset } from '~/types/project'; + +interface ColorFieldProps { + name: 'brandColor' | 'buttonTextColor'; + label: string; + presets: ColorPreset[]; +} + +// A project form colour bound straight to one form value +export function ColorField({ name, label, presets }: ColorFieldProps) { + const { control, setValue, formState } = useFormContext(); + const value = useWatch({ control, name }); + const id = `project-${name}`; + + return ( + + setValue(name, hex, { shouldDirty: true })} /> + + ); +} diff --git a/app/components/projects/form/logo-background-field.tsx b/app/components/projects/form/logo-background-field.tsx new file mode 100644 index 0000000..ff3d7c3 --- /dev/null +++ b/app/components/projects/form/logo-background-field.tsx @@ -0,0 +1,38 @@ +import { useFormContext, useWatch } from 'react-hook-form'; +import { ColorPicker } from '~/components/ui/color-picker'; +import { Field } from '~/components/ui/field'; +import { LOGO_BACKGROUND_PRESETS } from '~/data/projects/constants'; +import { isDarkColor } from '~/lib/color'; +import type { ProjectFormValues } from '~/schemas/projects/project-form'; +import type { LogoBackground } from '~/types/project'; + +const PRESET_KEYS = Object.keys(LOGO_BACKGROUND_PRESETS) as LogoBackground[]; +const PRESETS = PRESET_KEYS.map((key) => LOGO_BACKGROUND_PRESETS[key]); + +// Light / Dark presets or any custom colour; a custom colour also decides light vs dark for contrast +export function LogoBackgroundField() { + const { control, setValue } = useFormContext(); + const [logoBg, logoBgColor] = useWatch({ control, name: ['logoBg', 'logoBgColor'] }); + + const onChange = (hex: string) => { + const preset = PRESET_KEYS.find((key) => LOGO_BACKGROUND_PRESETS[key].value === hex); + setValue('logoBg', preset ?? (isDarkColor(hex) ? 'dark' : 'light'), { shouldDirty: true }); + setValue('logoBgColor', preset ? '' : hex, { shouldDirty: true }); + }; + + return ( + + + + ); +} diff --git a/app/components/projects/form/logo-field.tsx b/app/components/projects/form/logo-field.tsx new file mode 100644 index 0000000..cf872ac --- /dev/null +++ b/app/components/projects/form/logo-field.tsx @@ -0,0 +1,79 @@ +import { useState } from 'react'; +import { useFormContext, useWatch } from 'react-hook-form'; +import { Upload } from 'lucide-react'; +import { Button } from '~/components/ui/button'; +import { DropZone } from '~/components/ui/drop-zone'; +import { Field } from '~/components/ui/field'; +import { LogoTile } from '~/components/ui/logo-tile'; +import { Text } from '~/components/ui/text'; +import { TextPair } from '~/components/ui/text-pair'; +import { useAdminData } from '~/hooks/admin/use-admin-data'; +import { fileTypeLabel, formatFileSize } from '~/lib/format'; +import { logoAccept, logoFormatsLabel, prepareLogoFile } from '~/lib/projects/logo-file'; +import type { ProjectFormValues } from '~/schemas/projects/project-form'; +import type { BrandIdentity } from '~/types/project'; + +export function LogoField({ brand }: { brand: BrandIdentity }) { + const { settings } = useAdminData(); + const { control, setValue, trigger, formState } = useFormContext(); + const logo = useWatch({ control, name: 'logo' }); + const [fileError, setFileError] = useState(); + const hasLogo = !!logo.file || !!logo.existing; + + const update = (next: ProjectFormValues['logo']) => { + setValue('logo', next, { shouldDirty: true }); + if (formState.isSubmitted) trigger('logo'); + }; + + const onFile = async (file: File) => { + setFileError(undefined); + const result = await prepareLogoFile(file, settings.allow_svg_logos); + if ('error' in result) setFileError(result.error); + else update({ file: result.file, existing: logo.existing }); + }; + + return ( + + + {hasLogo ? ( +
+ + + + +
+ ) : ( + <> + + + Click to upload or drag a file here + + {logoFormatsLabel(settings.allow_svg_logos)} · up to 2 MB · transparent background recommended + + )} +
+
+ ); +} diff --git a/app/components/projects/form/project-form-dialog.tsx b/app/components/projects/form/project-form-dialog.tsx new file mode 100644 index 0000000..e9b774d --- /dev/null +++ b/app/components/projects/form/project-form-dialog.tsx @@ -0,0 +1,74 @@ +import { FormProvider, useForm, useWatch } from 'react-hook-form'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useFetcher } from 'react-router'; +import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '~/components/ui/dialog'; +import { DialogActions } from '~/components/ui/dialog-actions'; +import { ProjectFormFields } from '~/components/projects/form/project-form-fields'; +import { ProjectPreview } from '~/components/projects/form/project-preview'; +import { PROJECT_INTENT, type ProjectIntent } from '~/data/projects/constants'; +import { ROUTES } from '~/data/routes'; +import { useActionToast } from '~/hooks/use-action-toast'; +import { useAdminData } from '~/hooks/admin/use-admin-data'; +import { useProjectFormBrand } from '~/hooks/projects/use-project-form-brand'; +import { toProjectFormData } from '~/lib/projects/form-data'; +import { toProjectFormValues, withLogoRule, type ProjectFormValues } from '~/schemas/projects/project-form'; +import type { ActionResult } from '~/types/action'; +import type { Project } from '~/types/project'; + +interface ProjectFormDialogProps { + open: boolean; + project: Project | null; + onOpenChange: (open: boolean) => void; + onCreated: (id: string) => void; +} + +export function ProjectFormDialog({ open, project, onOpenChange, onCreated }: ProjectFormDialogProps) { + const { settings } = useAdminData(); + const fetcher = useFetcher>(); + const form = useForm({ resolver: zodResolver(withLogoRule(settings.logo_required)), defaultValues: toProjectFormValues(project) }); + const { brand, button, layout } = useProjectFormBrand(form.control, project); + const [name, logo] = useWatch({ control: form.control, name: ['name', 'logo'] }); + const canSave = !!name.trim() && (!settings.logo_required || !!logo.file || !!logo.existing); + const intent = project ? PROJECT_INTENT.update : PROJECT_INTENT.create; + + useActionToast(fetcher.data, (result) => { + onOpenChange(false); + if (result.intent === PROJECT_INTENT.create && result.id) onCreated(result.id); + }); + + return ( + + + + {project ? 'Edit project' : 'New project'} + A project is a client company. Its logo appears on every AR page in it. + + +
+ fetcher.submit(toProjectFormData(intent, project?.id, values), { + method: 'post', + action: ROUTES.projects, + encType: 'multipart/form-data', + }), + )} + > + {/* Only the form column scrolls; the title, preview and buttons stay in place */} +
+ + +
+ + +
+
+
+ ); +} diff --git a/app/components/projects/form/project-form-fields.tsx b/app/components/projects/form/project-form-fields.tsx new file mode 100644 index 0000000..83cbe41 --- /dev/null +++ b/app/components/projects/form/project-form-fields.tsx @@ -0,0 +1,55 @@ +import { useFormContext, useWatch } from 'react-hook-form'; +import { DialogBody } from '~/components/ui/dialog'; +import { Field } from '~/components/ui/field'; +import { Input } from '~/components/ui/input'; +import { SegmentedControl } from '~/components/ui/segmented-control'; +import { Textarea } from '~/components/ui/textarea'; +import { ArPageFields } from '~/components/projects/form/ar-page-fields'; +import { ButtonStyleFields } from '~/components/projects/form/button-style-fields'; +import { LogoBackgroundField } from '~/components/projects/form/logo-background-field'; +import { LogoField } from '~/components/projects/form/logo-field'; +import { PROJECT_STATUS_OPTIONS } from '~/data/projects/constants'; +import { useAdminData } from '~/hooks/admin/use-admin-data'; +import type { ProjectFormValues } from '~/schemas/projects/project-form'; +import type { BrandIdentity } from '~/types/project'; + +export function ProjectFormFields({ isEdit, brand }: { isEdit: boolean; brand: BrandIdentity }) { + const { settings } = useAdminData(); + const { register, control, setValue, formState } = useFormContext(); + const status = useWatch({ control, name: 'status' }); + const { errors } = formState; + + // relative: the switches' hidden inputs are positioned, and must stay inside this scroll area + return ( + + + + + + + + + {settings.brand_button && } + + +