Add GRV Summit admin portal
Vite + React 19 + TypeScript staff/admin SPA built against GRV-Backend/API.md: email OTP login (staff/admin only, 401 -> login), dashboard stats and leaderboard, application review (filters, bulk status, CSV export, scoring), inquiries by intent, orders and ticket check-in, tiers, discount codes, merch items and pickup queue, QR checkpoints with printable A6 cards, startup badges, raffles with draw, and attendees. Shell and UI primitives adapted from the Booking platform admin; theme, fonts, logo and topography pattern match the public GRVSummit site. Static deploy to Cloudflare Pages via public/_redirects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f08d05a9bc
commit
408b707437
1
.env.example
Normal file
1
.env.example
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
VITE_API_URL=http://localhost:4000
|
||||||
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
*.log
|
||||||
|
.DS_Store
|
||||||
80
README.md
80
README.md
|
|
@ -0,0 +1,80 @@
|
||||||
|
# GRV Summit Admin
|
||||||
|
|
||||||
|
Staff/admin portal for the GRV Summit: application review, inquiries, orders and ticket check-in,
|
||||||
|
tiers, discount codes, merch pickup, QR checkpoints (with printable A6 cards), startup badges,
|
||||||
|
raffles and attendees.
|
||||||
|
|
||||||
|
It is a static Vite + React 19 SPA that talks to the NestJS backend in `../GRV-Backend`. The API
|
||||||
|
contract it is built against is `../GRV-Backend/API.md`; all admin calls go to `/admin/*` with a
|
||||||
|
Bearer token.
|
||||||
|
|
||||||
|
Stack: React 19, TypeScript (strict), Tailwind CSS 4, Radix/shadcn-style components, TanStack Query
|
||||||
|
and Table, react-router, `qrcode`, cmdk, sonner. Theme tokens and fonts (Antebas headings, DM Sans
|
||||||
|
body) match the public site (`GRVSummit/app/globals.css`).
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pnpm install
|
||||||
|
cp .env.example .env # then edit if the API is not on localhost:4000
|
||||||
|
pnpm dev # http://localhost:5175
|
||||||
|
```
|
||||||
|
|
||||||
|
| Env var | Default | Meaning |
|
||||||
|
| -------------- | ----------------------- | ------------------------------- |
|
||||||
|
| `VITE_API_URL` | `http://localhost:4000` | Base URL of the GRV backend API |
|
||||||
|
|
||||||
|
`VITE_*` values are baked in at build time, so set it before `pnpm build`. The backend must allow
|
||||||
|
this origin in CORS.
|
||||||
|
|
||||||
|
## Scripts
|
||||||
|
|
||||||
|
- `pnpm dev`: dev server
|
||||||
|
- `pnpm build`: typecheck + production build into `dist/`
|
||||||
|
- `pnpm typecheck`: `tsc --noEmit`
|
||||||
|
- `pnpm check`: money-conversion self-check (`src/lib/utils.check.ts`)
|
||||||
|
- `pnpm preview`: serve the built `dist/`
|
||||||
|
|
||||||
|
## How login works
|
||||||
|
|
||||||
|
1. Enter your email; the portal calls `POST /auth/otp/request`, and the backend emails a 6-digit code.
|
||||||
|
**In dev the code is printed in the backend console** (the login page shows this hint in dev builds).
|
||||||
|
2. Enter the code; `POST /auth/otp/verify` returns `{ accessToken, user }`.
|
||||||
|
3. The role comes from the backend's `ADMIN_EMAILS` / `STAFF_EMAILS` allowlists. `ATTENDEE`
|
||||||
|
accounts are refused with a message. STAFF and ADMIN get in.
|
||||||
|
4. The token and user are kept in `localStorage`. Tokens last 12 hours and can't be refreshed: any
|
||||||
|
401 clears the session and sends you back to `/login`.
|
||||||
|
|
||||||
|
STAFF can do day-to-day operations (review, statuses, orders, check-in, pickup). Create/edit
|
||||||
|
buttons for ADMIN-only endpoints (★ in API.md: tiers, discounts, merch items, checkpoints,
|
||||||
|
raffles and draws) are hidden from STAFF. The backend enforces this too.
|
||||||
|
|
||||||
|
## Printing QR cards
|
||||||
|
|
||||||
|
Checkpoints → select rows → **Print selected** (or the printer icon on a row, or **Print badges**
|
||||||
|
on the Startups page) opens `/checkpoints/print?ids=…`. Each card is A6 (105 × 148 mm), one per
|
||||||
|
page. Use the browser's print dialog; on A4 paper choose "4 pages per sheet" and cut. Mystery
|
||||||
|
investee cards print only "?" and the QR.
|
||||||
|
|
||||||
|
## Deploy (Cloudflare Pages)
|
||||||
|
|
||||||
|
- Build command: `pnpm build`
|
||||||
|
- Output directory: `dist`
|
||||||
|
- Environment variable: `VITE_API_URL=https://<api host>`
|
||||||
|
|
||||||
|
`public/_redirects` (`/* /index.html 200`) makes client-side routes work on refresh.
|
||||||
|
|
||||||
|
## Layout
|
||||||
|
|
||||||
|
```
|
||||||
|
src/
|
||||||
|
main.tsx, router.tsx, index.css entry, routes, theme tokens + fonts
|
||||||
|
lib/api.ts fetch wrapper (bearer, JSON, errors, 401 → login), session, CSV download
|
||||||
|
lib/types.ts types hand-written from API.md
|
||||||
|
lib/utils.ts cn, money / minor-unit helpers, dates, useDebounced
|
||||||
|
components/ui/ shadcn-style primitives (from the Booking platform admin)
|
||||||
|
components/layout/ AppLayout + PageShell, Sidebar, CommandPalette (⌘K), nav
|
||||||
|
components/DataTable.tsx TanStack Table: sorting, row selection, expandable rows
|
||||||
|
components/common.tsx StatCard, QrImage, FormDialog, useSave, AdminOnly, badges
|
||||||
|
pages/ one file per screen
|
||||||
|
```
|
||||||
15
index.html
Normal file
15
index.html
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" href="/favicon.ico" />
|
||||||
|
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<meta name="robots" content="noindex" />
|
||||||
|
<title>GRV Summit Admin</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
46
package.json
Normal file
46
package.json
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
"name": "grv-admin",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.1.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "tsc --noEmit && vite build",
|
||||||
|
"typecheck": "tsc --noEmit",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"check": "node src/lib/utils.check.ts"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@fontsource-variable/dm-sans": "^5.3.0",
|
||||||
|
"@radix-ui/react-checkbox": "^1.4.1",
|
||||||
|
"@radix-ui/react-dialog": "^1.3.1",
|
||||||
|
"@radix-ui/react-dropdown-menu": "^2.2.1",
|
||||||
|
"@radix-ui/react-label": "^2.1.17",
|
||||||
|
"@radix-ui/react-slot": "^1.5.0",
|
||||||
|
"@radix-ui/react-switch": "^1.4.1",
|
||||||
|
"@radix-ui/react-tabs": "^1.2.1",
|
||||||
|
"@tanstack/react-query": "^5.108.0",
|
||||||
|
"@tanstack/react-table": "^8.21.3",
|
||||||
|
"class-variance-authority": "^0.7.1",
|
||||||
|
"clsx": "^2.1.1",
|
||||||
|
"cmdk": "^1.1.1",
|
||||||
|
"lucide-react": "^1.74.0",
|
||||||
|
"qrcode": "^1.5.4",
|
||||||
|
"react": "^19.3.1",
|
||||||
|
"react-dom": "^19.3.1",
|
||||||
|
"react-router": "^7.18.5",
|
||||||
|
"sonner": "^2.0.8",
|
||||||
|
"tailwind-merge": "^3.7.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@tailwindcss/vite": "^4.3.5",
|
||||||
|
"@types/node": "^24.19.2",
|
||||||
|
"@types/qrcode": "^1.5.6",
|
||||||
|
"@types/react": "^19.3.0",
|
||||||
|
"@types/react-dom": "^19.3.0",
|
||||||
|
"@vitejs/plugin-react": "^6.3.0",
|
||||||
|
"tailwindcss": "^4.3.5",
|
||||||
|
"typescript": "^6.0.3",
|
||||||
|
"vite": "^8.3.8"
|
||||||
|
}
|
||||||
|
}
|
||||||
2062
pnpm-lock.yaml
Normal file
2062
pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load Diff
BIN
public/GRVLogo.png
Normal file
BIN
public/GRVLogo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
1
public/_redirects
Normal file
1
public/_redirects
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/* /index.html 200
|
||||||
BIN
public/apple-touch-icon.png
Normal file
BIN
public/apple-touch-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
BIN
public/favicon.ico
Normal file
BIN
public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
BIN
public/fonts/Fontspring-DEMO-antebas-black.otf
Normal file
BIN
public/fonts/Fontspring-DEMO-antebas-black.otf
Normal file
Binary file not shown.
BIN
public/fonts/Fontspring-DEMO-antebas-bold.otf
Normal file
BIN
public/fonts/Fontspring-DEMO-antebas-bold.otf
Normal file
Binary file not shown.
BIN
public/fonts/Fontspring-DEMO-antebas-light.otf
Normal file
BIN
public/fonts/Fontspring-DEMO-antebas-light.otf
Normal file
Binary file not shown.
BIN
public/fonts/Fontspring-DEMO-antebas-medium.otf
Normal file
BIN
public/fonts/Fontspring-DEMO-antebas-medium.otf
Normal file
Binary file not shown.
BIN
public/fonts/Fontspring-DEMO-antebas-regular.otf
Normal file
BIN
public/fonts/Fontspring-DEMO-antebas-regular.otf
Normal file
Binary file not shown.
736
public/patterns/main.svg
Normal file
736
public/patterns/main.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 486 KiB |
1159
public/patterns/mainwhite.svg
Normal file
1159
public/patterns/mainwhite.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 432 KiB |
140
src/components/DataTable.tsx
Normal file
140
src/components/DataTable.tsx
Normal file
|
|
@ -0,0 +1,140 @@
|
||||||
|
import { useState, type ReactNode } from 'react';
|
||||||
|
import {
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
useReactTable,
|
||||||
|
type ColumnDef,
|
||||||
|
type RowSelectionState,
|
||||||
|
type SortingState,
|
||||||
|
} from '@tanstack/react-table';
|
||||||
|
import { ArrowDown, ArrowUp, ArrowUpDown } from 'lucide-react';
|
||||||
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||||
|
import { Checkbox } from '@/components/ui/checkbox';
|
||||||
|
import { SkeletonRows } from '@/components/ui/skeleton';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export type { ColumnDef };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sortable table. Pass `selection` to get a checkbox column; selection is keyed by `getRowId`.
|
||||||
|
* `enableSorting: false` on a column def opts it out.
|
||||||
|
*/
|
||||||
|
export function DataTable<T>({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
getRowId,
|
||||||
|
loading,
|
||||||
|
empty,
|
||||||
|
selection,
|
||||||
|
canSelect,
|
||||||
|
renderExpanded,
|
||||||
|
}: {
|
||||||
|
data: T[] | undefined;
|
||||||
|
columns: ColumnDef<T, any>[];
|
||||||
|
getRowId: (row: T) => string;
|
||||||
|
loading?: boolean;
|
||||||
|
empty?: ReactNode;
|
||||||
|
selection?: [RowSelectionState, (s: RowSelectionState) => void];
|
||||||
|
canSelect?: (row: T) => boolean;
|
||||||
|
/** extra full-width row under a row (return null to hide) */
|
||||||
|
renderExpanded?: (row: T) => ReactNode;
|
||||||
|
}) {
|
||||||
|
const [sorting, setSorting] = useState<SortingState>([]);
|
||||||
|
const selectCol: ColumnDef<T, unknown> = {
|
||||||
|
id: '_select',
|
||||||
|
enableSorting: false,
|
||||||
|
header: ({ table }) => (
|
||||||
|
<Checkbox
|
||||||
|
aria-label="Select all"
|
||||||
|
checked={table.getIsAllRowsSelected() ? true : table.getIsSomeRowsSelected() ? 'indeterminate' : false}
|
||||||
|
onCheckedChange={(v) => table.toggleAllRowsSelected(v === true)}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<Checkbox
|
||||||
|
aria-label="Select row"
|
||||||
|
disabled={!row.getCanSelect()}
|
||||||
|
checked={row.getIsSelected()}
|
||||||
|
onCheckedChange={(v) => row.toggleSelected(v === true)}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data: data ?? [],
|
||||||
|
columns: selection ? [selectCol, ...columns] : columns,
|
||||||
|
getRowId,
|
||||||
|
state: { sorting, ...(selection ? { rowSelection: selection[0] } : {}) },
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
enableRowSelection: selection ? (row) => canSelect?.(row.original) ?? true : false,
|
||||||
|
onRowSelectionChange: (updater) => {
|
||||||
|
if (!selection) return;
|
||||||
|
selection[1](typeof updater === 'function' ? updater(selection[0]) : updater);
|
||||||
|
},
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (loading) return <SkeletonRows rows={6} />;
|
||||||
|
const colCount = table.getVisibleLeafColumns().length;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="overflow-hidden rounded-xl border border-primary/12 bg-surface">
|
||||||
|
<Table>
|
||||||
|
<TableHeader className="bg-surface-muted">
|
||||||
|
{table.getHeaderGroups().map((hg) => (
|
||||||
|
<TableRow key={hg.id}>
|
||||||
|
{hg.headers.map((h) => {
|
||||||
|
const sortable = h.column.getCanSort();
|
||||||
|
const dir = h.column.getIsSorted();
|
||||||
|
const content = flexRender(h.column.columnDef.header, h.getContext());
|
||||||
|
return (
|
||||||
|
<TableHead key={h.id} className={cn('text-primary', h.column.id === '_select' && 'w-10')}>
|
||||||
|
{sortable ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={h.column.getToggleSortingHandler()}
|
||||||
|
className="inline-flex items-center gap-1 uppercase hover:text-fg"
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
{dir === 'asc' ? <ArrowUp className="h-3 w-3" /> : dir === 'desc' ? <ArrowDown className="h-3 w-3" /> : <ArrowUpDown className="h-3 w-3 opacity-40" />}
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
content
|
||||||
|
)}
|
||||||
|
</TableHead>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{table.getRowModel().rows.length === 0 ? (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={colCount} className="py-12 text-center text-muted">
|
||||||
|
{empty ?? 'Nothing here yet.'}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
) : (
|
||||||
|
table.getRowModel().rows.flatMap((row) => {
|
||||||
|
const extra = renderExpanded?.(row.original);
|
||||||
|
return [
|
||||||
|
<TableRow key={row.id} data-state={row.getIsSelected() ? 'selected' : undefined}>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>,
|
||||||
|
extra ? (
|
||||||
|
<TableRow key={`${row.id}-x`} className="bg-canvas hover:bg-canvas">
|
||||||
|
<TableCell colSpan={colCount}>{extra}</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
) : null,
|
||||||
|
];
|
||||||
|
})
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
178
src/components/common.tsx
Normal file
178
src/components/common.tsx
Normal file
|
|
@ -0,0 +1,178 @@
|
||||||
|
import { useEffect, useState, type ReactNode } from 'react';
|
||||||
|
import QRCode from 'qrcode';
|
||||||
|
import type { LucideIcon } from 'lucide-react';
|
||||||
|
import { AlertTriangle } from 'lucide-react';
|
||||||
|
import { Badge, type BadgeTone } from '@/components/ui/badge';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { api, isAdmin } from '@/lib/api';
|
||||||
|
import { errorMessage, humanize } from '@/lib/utils';
|
||||||
|
|
||||||
|
export function StatCard({
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
hint,
|
||||||
|
icon: Icon,
|
||||||
|
}: {
|
||||||
|
label: string;
|
||||||
|
value: ReactNode;
|
||||||
|
hint?: ReactNode;
|
||||||
|
icon?: LucideIcon;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-xl border border-primary/12 bg-surface p-5 shadow-card">
|
||||||
|
<div className="flex items-start justify-between gap-3">
|
||||||
|
<p className="text-xs font-semibold uppercase tracking-widest text-primary">{label}</p>
|
||||||
|
{Icon ? (
|
||||||
|
<span className="flex h-9 w-9 items-center justify-center rounded-lg bg-surface-muted text-primary">
|
||||||
|
<Icon className="h-4 w-4" aria-hidden />
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
<p className="mt-2 text-3xl font-bold tabular">{value}</p>
|
||||||
|
{hint ? <p className="mt-1 text-xs text-muted">{hint}</p> : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** QR rendered client-side from the URL the backend encodes (checkpoint or ticket). */
|
||||||
|
export function QrImage({ value, size = 96, className }: { value: string; size?: number; className?: string }) {
|
||||||
|
const [src, setSrc] = useState<string>();
|
||||||
|
useEffect(() => {
|
||||||
|
let live = true;
|
||||||
|
QRCode.toDataURL(value, { width: size * 2, margin: 1, color: { dark: '#1a4034', light: '#ffffff' } }).then(
|
||||||
|
(url) => live && setSrc(url),
|
||||||
|
() => live && setSrc(undefined),
|
||||||
|
);
|
||||||
|
return () => {
|
||||||
|
live = false;
|
||||||
|
};
|
||||||
|
}, [value, size]);
|
||||||
|
return src ? (
|
||||||
|
<img src={src} alt={`QR code for ${value}`} width={size} height={size} className={className} />
|
||||||
|
) : (
|
||||||
|
<div style={{ width: size, height: size }} className={className} aria-hidden />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function QueryError({ error, retry }: { error: unknown; retry?: () => void }) {
|
||||||
|
return (
|
||||||
|
<div role="alert" className="flex items-center gap-3 rounded-xl border border-danger/30 bg-danger-soft p-4 text-sm text-danger">
|
||||||
|
<AlertTriangle className="h-4 w-4 shrink-0" aria-hidden />
|
||||||
|
<span className="flex-1">{errorMessage(error)}</span>
|
||||||
|
{retry ? (
|
||||||
|
<Button size="sm" variant="danger-outline" onClick={retry}>
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Empty state on the brand topography pattern. */
|
||||||
|
export function PatternEmpty({ title, description, action }: { title: string; description?: string; action?: ReactNode }) {
|
||||||
|
return (
|
||||||
|
<div className="relative overflow-hidden rounded-xl border border-primary/12 bg-surface px-6 py-14 text-center">
|
||||||
|
<img src="/patterns/mainwhite.svg" alt="" aria-hidden className="pattern-on-light pointer-events-none absolute inset-0 h-full w-full object-cover" />
|
||||||
|
<div className="relative">
|
||||||
|
<p className="font-display text-xl font-bold">{title}</p>
|
||||||
|
{description ? <p className="mx-auto mt-1 max-w-md text-sm text-muted">{description}</p> : null}
|
||||||
|
{action ? <div className="mt-4">{action}</div> : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const statusTones: Record<string, BadgeTone> = {
|
||||||
|
// applications
|
||||||
|
DRAFT: 'outline',
|
||||||
|
SUBMITTED: 'primary',
|
||||||
|
UNDER_REVIEW: 'warning',
|
||||||
|
SHORTLISTED: 'info',
|
||||||
|
FINALIST: 'solid',
|
||||||
|
ACCEPTED: 'success',
|
||||||
|
REJECTED: 'neutral',
|
||||||
|
// orders
|
||||||
|
PENDING: 'warning',
|
||||||
|
PAID: 'info',
|
||||||
|
FULFILLED: 'success',
|
||||||
|
CANCELLED: 'neutral',
|
||||||
|
// inquiries
|
||||||
|
NEW: 'warning',
|
||||||
|
CONTACTED: 'info',
|
||||||
|
CLOSED: 'neutral',
|
||||||
|
};
|
||||||
|
|
||||||
|
export function StatusBadge({ status }: { status: string }) {
|
||||||
|
return <Badge tone={statusTones[status] ?? 'neutral'}>{humanize(status)}</Badge>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ActiveBadge({ active }: { active: boolean }) {
|
||||||
|
return <Badge tone={active ? 'success' : 'outline'}>{active ? 'Active' : 'Inactive'}</Badge>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Dialog wrapping a <form>; submit runs `onSubmit`, the dialog stays open on error. */
|
||||||
|
export function FormDialog({
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
title,
|
||||||
|
submitLabel = 'Save',
|
||||||
|
loading,
|
||||||
|
onSubmit,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (o: boolean) => void;
|
||||||
|
title: string;
|
||||||
|
submitLabel?: string;
|
||||||
|
loading?: boolean;
|
||||||
|
onSubmit: () => void;
|
||||||
|
children: ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="max-w-xl">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{title}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<form
|
||||||
|
className="grid gap-4"
|
||||||
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
onSubmit();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="button" variant="secondary" onClick={() => onOpenChange(false)}>
|
||||||
|
Back
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" loading={loading}>
|
||||||
|
{submitLabel}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Create (POST `path`) or update (PATCH `path/:id`), then refetch `key` and toast. */
|
||||||
|
export function useSave<B>(path: string, key: string, onDone?: () => void) {
|
||||||
|
const qc = useQueryClient();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ id, body }: { id?: string; body: B }) =>
|
||||||
|
id ? api(`${path}/${id}`, { method: 'PATCH', body }) : api(path, { body }),
|
||||||
|
onSuccess: (_, v) => {
|
||||||
|
toast.success(v.id ? 'Saved' : 'Created');
|
||||||
|
qc.invalidateQueries({ queryKey: [key] });
|
||||||
|
onDone?.();
|
||||||
|
},
|
||||||
|
onError: (e) => toast.error(errorMessage(e)),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Renders children only for ADMIN (★ endpoints in API.md). */
|
||||||
|
export const AdminOnly = ({ children }: { children: ReactNode }) => (isAdmin() ? <>{children}</> : null);
|
||||||
92
src/components/layout/AppLayout.tsx
Normal file
92
src/components/layout/AppLayout.tsx
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
import { useEffect, useState, type ReactNode } from 'react';
|
||||||
|
import { Navigate, Outlet, useLocation } from 'react-router';
|
||||||
|
import { LogOut, Menu } from 'lucide-react';
|
||||||
|
import { Sidebar } from './Sidebar';
|
||||||
|
import { CommandPalette } from './CommandPalette';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { getToken, getUser, signOut } from '@/lib/api';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
const COLLAPSE_KEY = 'grv_admin_sidebar_collapsed';
|
||||||
|
|
||||||
|
export function AppLayout() {
|
||||||
|
const location = useLocation();
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const [collapsed, setCollapsed] = useState(() => localStorage.getItem(COLLAPSE_KEY) === '1');
|
||||||
|
useEffect(() => setOpen(false), [location.pathname]);
|
||||||
|
|
||||||
|
const user = getUser();
|
||||||
|
if (!getToken() || !user || user.role === 'ATTENDEE') return <Navigate to="/login" replace />;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-canvas">
|
||||||
|
<a
|
||||||
|
href="#main"
|
||||||
|
className="sr-only focus:not-sr-only focus:fixed focus:left-3 focus:top-3 focus:z-[60] focus:rounded-md focus:bg-surface focus:px-3 focus:py-2"
|
||||||
|
>
|
||||||
|
Skip to content
|
||||||
|
</a>
|
||||||
|
<Sidebar
|
||||||
|
open={open}
|
||||||
|
collapsed={collapsed}
|
||||||
|
onClose={() => setOpen(false)}
|
||||||
|
onToggleCollapse={() => {
|
||||||
|
localStorage.setItem(COLLAPSE_KEY, collapsed ? '0' : '1');
|
||||||
|
setCollapsed(!collapsed);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
inert={open ? true : undefined}
|
||||||
|
className={cn('flex min-h-screen min-w-0 flex-col transition-[margin] duration-300', collapsed ? 'md:ml-[76px]' : 'md:ml-[264px]')}
|
||||||
|
>
|
||||||
|
<header className="no-print sticky top-0 z-30 flex h-16 items-center gap-2 border-b border-border bg-surface/95 px-3 backdrop-blur sm:px-6">
|
||||||
|
<Button variant="ghost" size="icon" className="md:hidden" onClick={() => setOpen(true)} aria-label="Menu">
|
||||||
|
<Menu aria-hidden />
|
||||||
|
</Button>
|
||||||
|
<CommandPalette />
|
||||||
|
<div className="ml-auto flex items-center gap-3">
|
||||||
|
<div className="hidden text-right sm:block">
|
||||||
|
<p className="text-sm font-medium leading-tight">{user.name ?? user.email}</p>
|
||||||
|
<p className="text-xs text-muted">{user.email}</p>
|
||||||
|
</div>
|
||||||
|
<Badge tone={user.role === 'ADMIN' ? 'solid' : 'primary'}>{user.role}</Badge>
|
||||||
|
<Button variant="ghost" size="icon" onClick={signOut} aria-label="Sign out" title="Sign out">
|
||||||
|
<LogOut aria-hidden />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<main id="main" tabIndex={-1} className="flex-1 px-4 py-6 focus:outline-none sm:px-6 lg:px-8">
|
||||||
|
<Outlet />
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Title block + actions, Booking admin's PageShell with the GRV eyebrow treatment. */
|
||||||
|
export function PageShell({
|
||||||
|
title,
|
||||||
|
subtitle,
|
||||||
|
actions,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
title: ReactNode;
|
||||||
|
subtitle?: ReactNode;
|
||||||
|
actions?: ReactNode;
|
||||||
|
children: ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="mx-auto w-full max-w-7xl min-w-0 space-y-5">
|
||||||
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<div className="mb-2 h-1 w-10 rounded-full bg-primary" aria-hidden />
|
||||||
|
<h1 className="font-display text-3xl font-bold">{title}</h1>
|
||||||
|
{subtitle ? <p className="mt-1 text-sm text-muted">{subtitle}</p> : null}
|
||||||
|
</div>
|
||||||
|
{actions ? <div className="no-print flex shrink-0 flex-wrap items-center gap-2">{actions}</div> : null}
|
||||||
|
</div>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
83
src/components/layout/CommandPalette.tsx
Normal file
83
src/components/layout/CommandPalette.tsx
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useNavigate } from 'react-router';
|
||||||
|
import { LogOut, Search } from 'lucide-react';
|
||||||
|
import {
|
||||||
|
CommandDialog,
|
||||||
|
CommandEmpty,
|
||||||
|
CommandGroup,
|
||||||
|
CommandInput,
|
||||||
|
CommandItem,
|
||||||
|
CommandList,
|
||||||
|
} from '@/components/ui/command';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { navEntries, navGroups } from './nav';
|
||||||
|
import { signOut } from '@/lib/api';
|
||||||
|
|
||||||
|
export function CommandPalette() {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const isMac = /Mac|iPhone|iPad/.test(navigator.userAgent);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function onKey(e: KeyboardEvent) {
|
||||||
|
if (e.key?.toLowerCase() === 'k' && (e.metaKey || e.ctrlKey)) {
|
||||||
|
e.preventDefault();
|
||||||
|
setOpen((p) => !p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.addEventListener('keydown', onKey);
|
||||||
|
return () => window.removeEventListener('keydown', onKey);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const go = (path: string) => {
|
||||||
|
setOpen(false);
|
||||||
|
navigate(path);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => setOpen(true)}
|
||||||
|
className="hidden h-9 items-center gap-2 border border-border bg-surface px-3 text-xs text-muted hover:text-fg md:flex"
|
||||||
|
aria-label="Search"
|
||||||
|
>
|
||||||
|
<Search className="h-3.5 w-3.5" aria-hidden />
|
||||||
|
<span>Jump to…</span>
|
||||||
|
<kbd className="ml-2 rounded border border-border bg-canvas px-1.5 py-0.5 font-mono text-xs">
|
||||||
|
{isMac ? '⌘K' : 'Ctrl+K'}
|
||||||
|
</kbd>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<CommandDialog open={open} onOpenChange={setOpen} label="Search" description="Jump to a page">
|
||||||
|
<CommandInput placeholder="Go to page…" />
|
||||||
|
<CommandList>
|
||||||
|
<CommandEmpty>No matches.</CommandEmpty>
|
||||||
|
{navGroups.map((group) => (
|
||||||
|
<CommandGroup key={group} heading={group}>
|
||||||
|
{navEntries
|
||||||
|
.filter((e) => e.group === group)
|
||||||
|
.map((item) => (
|
||||||
|
<CommandItem
|
||||||
|
key={item.path}
|
||||||
|
value={`${item.label} ${item.keywords ?? ''}`}
|
||||||
|
onSelect={() => go(item.path)}
|
||||||
|
>
|
||||||
|
<item.icon className="h-4 w-4 text-muted" aria-hidden />
|
||||||
|
<span>{item.label}</span>
|
||||||
|
<span className="ml-auto text-xs text-muted">{item.path}</span>
|
||||||
|
</CommandItem>
|
||||||
|
))}
|
||||||
|
</CommandGroup>
|
||||||
|
))}
|
||||||
|
<CommandGroup heading="Account">
|
||||||
|
<CommandItem value="sign out logout" onSelect={signOut}>
|
||||||
|
<LogOut className="h-4 w-4 text-muted" aria-hidden />
|
||||||
|
Sign out
|
||||||
|
</CommandItem>
|
||||||
|
</CommandGroup>
|
||||||
|
</CommandList>
|
||||||
|
</CommandDialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
144
src/components/layout/Sidebar.tsx
Normal file
144
src/components/layout/Sidebar.tsx
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
import { useEffect, useRef } from 'react';
|
||||||
|
import { NavLink } from 'react-router';
|
||||||
|
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
||||||
|
import { navEntries, navGroups, type NavEntry } from './nav';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
const FOCUSABLE = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
|
||||||
|
|
||||||
|
export function Sidebar({
|
||||||
|
open,
|
||||||
|
collapsed,
|
||||||
|
onToggleCollapse,
|
||||||
|
onClose,
|
||||||
|
}: {
|
||||||
|
open: boolean;
|
||||||
|
collapsed: boolean;
|
||||||
|
onToggleCollapse: () => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}) {
|
||||||
|
const asideRef = useRef<HTMLElement>(null);
|
||||||
|
|
||||||
|
// Mobile drawer: focus trap + Escape, focus returns to the trigger on close.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
const trigger = document.activeElement as HTMLElement | null;
|
||||||
|
asideRef.current?.querySelector<HTMLElement>(FOCUSABLE)?.focus();
|
||||||
|
function onKey(e: KeyboardEvent) {
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
e.preventDefault();
|
||||||
|
onClose();
|
||||||
|
} else if (e.key === 'Tab') {
|
||||||
|
const els = asideRef.current?.querySelectorAll<HTMLElement>(FOCUSABLE);
|
||||||
|
if (!els?.length) return;
|
||||||
|
const first = els[0]!;
|
||||||
|
const last = els[els.length - 1]!;
|
||||||
|
if (e.shiftKey && document.activeElement === first) {
|
||||||
|
e.preventDefault();
|
||||||
|
last.focus();
|
||||||
|
} else if (!e.shiftKey && document.activeElement === last) {
|
||||||
|
e.preventDefault();
|
||||||
|
first.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.addEventListener('keydown', onKey);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('keydown', onKey);
|
||||||
|
trigger?.focus?.();
|
||||||
|
};
|
||||||
|
}, [open, onClose]);
|
||||||
|
|
||||||
|
const narrow = collapsed && !open;
|
||||||
|
|
||||||
|
function renderItem(item: NavEntry) {
|
||||||
|
const Icon = item.icon;
|
||||||
|
return (
|
||||||
|
<NavLink
|
||||||
|
key={item.path}
|
||||||
|
to={item.path}
|
||||||
|
end={item.path === '/'}
|
||||||
|
onClick={onClose}
|
||||||
|
title={narrow ? item.label : undefined}
|
||||||
|
aria-label={narrow ? item.label : undefined}
|
||||||
|
className={({ isActive }) =>
|
||||||
|
cn(
|
||||||
|
'group flex h-10 items-center gap-3 rounded-full px-3 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-secondary',
|
||||||
|
isActive ? 'bg-nav-active text-nav-active-fg' : 'text-nav-fg/90 hover:bg-nav-hover',
|
||||||
|
narrow && 'md:justify-center md:px-0',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{({ isActive }) => (
|
||||||
|
<>
|
||||||
|
<Icon
|
||||||
|
className={cn('h-[18px] w-[18px] shrink-0', isActive ? 'text-nav-active-fg' : 'text-nav-muted group-hover:text-nav-fg')}
|
||||||
|
aria-hidden
|
||||||
|
/>
|
||||||
|
<span className={cn('min-w-0 flex-1 truncate', narrow && 'md:hidden')}>{item.label}</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</NavLink>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
className={cn('no-print fixed inset-0 z-40 bg-overlay md:hidden', open ? 'block' : 'hidden')}
|
||||||
|
onClick={onClose}
|
||||||
|
aria-hidden
|
||||||
|
/>
|
||||||
|
<aside
|
||||||
|
ref={asideRef}
|
||||||
|
role={open ? 'dialog' : undefined}
|
||||||
|
aria-modal={open ? 'true' : undefined}
|
||||||
|
aria-label="GRV Summit Admin"
|
||||||
|
className={cn(
|
||||||
|
'no-print fixed inset-y-0 left-0 z-50 flex w-[280px] flex-col overflow-hidden bg-nav text-nav-fg transition-[transform,width] duration-300',
|
||||||
|
open ? 'translate-x-0' : '-translate-x-full md:translate-x-0',
|
||||||
|
narrow ? 'md:w-[76px]' : 'md:w-[264px]',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{/* Brand pattern as a quiet accent at the foot of the rail */}
|
||||||
|
<img
|
||||||
|
src="/patterns/main.svg"
|
||||||
|
alt=""
|
||||||
|
aria-hidden
|
||||||
|
className="pattern-on-dark pattern-fade-up pointer-events-none absolute inset-x-0 bottom-0 h-80 w-full object-cover"
|
||||||
|
/>
|
||||||
|
<div className={cn('relative flex h-16 items-center gap-3 px-4', narrow && 'md:justify-center md:px-0')}>
|
||||||
|
<span className={cn('flex h-11 shrink-0 items-center overflow-hidden rounded-xl bg-white px-2.5', narrow && 'md:w-11 md:px-1')}>
|
||||||
|
<img src="/GRVLogo.png" alt="GRV Summit" className={cn('h-8 w-auto max-w-none', narrow && 'md:h-9 md:object-cover md:object-left')} />
|
||||||
|
</span>
|
||||||
|
<p className={cn('text-xs font-semibold uppercase tracking-widest text-nav-muted', narrow && 'md:hidden')}>Admin</p>
|
||||||
|
</div>
|
||||||
|
<nav className="relative flex-1 space-y-5 overflow-y-auto px-3 pb-4 pt-2">
|
||||||
|
{navGroups.map((group) => (
|
||||||
|
<div key={group} className="space-y-1">
|
||||||
|
<p
|
||||||
|
className={cn(
|
||||||
|
'px-3 pb-1 text-xs font-semibold uppercase tracking-wider text-nav-muted',
|
||||||
|
narrow && 'md:sr-only',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{group}
|
||||||
|
</p>
|
||||||
|
{navEntries.filter((e) => e.group === group).map(renderItem)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</nav>
|
||||||
|
<div className="relative hidden border-t border-nav-border p-3 md:block">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={onToggleCollapse}
|
||||||
|
className="flex h-9 w-full items-center justify-center rounded-full text-nav-muted hover:bg-nav-hover hover:text-nav-fg"
|
||||||
|
aria-label={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
|
||||||
|
>
|
||||||
|
{collapsed ? <ChevronRight className="h-4 w-4" /> : <ChevronLeft className="h-4 w-4" />}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
33
src/components/layout/nav.ts
Normal file
33
src/components/layout/nav.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
import {
|
||||||
|
ClipboardList,
|
||||||
|
Gift,
|
||||||
|
Inbox,
|
||||||
|
LayoutDashboard,
|
||||||
|
QrCode,
|
||||||
|
Rocket,
|
||||||
|
Shirt,
|
||||||
|
ShoppingCart,
|
||||||
|
Tag,
|
||||||
|
Ticket,
|
||||||
|
Users,
|
||||||
|
type LucideIcon,
|
||||||
|
} from 'lucide-react';
|
||||||
|
|
||||||
|
export type NavEntry = { label: string; path: string; icon: LucideIcon; group: string; keywords?: string };
|
||||||
|
|
||||||
|
export const navEntries: NavEntry[] = [
|
||||||
|
{ label: 'Dashboard', path: '/', icon: LayoutDashboard, group: 'Overview', keywords: 'stats home' },
|
||||||
|
{ label: 'Applications', path: '/applications', icon: ClipboardList, group: 'Pitch', keywords: 'review startups score' },
|
||||||
|
{ label: 'Startups', path: '/startups', icon: Rocket, group: 'Pitch', keywords: 'badges members' },
|
||||||
|
{ label: 'Inquiries', path: '/inquiries', icon: Inbox, group: 'Pitch', keywords: 'sponsor exhibitor press' },
|
||||||
|
{ label: 'Orders & tickets', path: '/orders', icon: ShoppingCart, group: 'Sales', keywords: 'check-in pay' },
|
||||||
|
{ label: 'Tiers', path: '/tiers', icon: Ticket, group: 'Sales', keywords: 'pricing passes' },
|
||||||
|
{ label: 'Discounts', path: '/discounts', icon: Tag, group: 'Sales', keywords: 'codes promo' },
|
||||||
|
{ label: 'Merch', path: '/merch', icon: Shirt, group: 'Sales', keywords: 'pickup shop' },
|
||||||
|
{ label: 'Checkpoints', path: '/checkpoints', icon: QrCode, group: 'Event', keywords: 'qr booth print mystery' },
|
||||||
|
{ label: 'Raffles', path: '/raffles', icon: Gift, group: 'Event', keywords: 'draw prize' },
|
||||||
|
{ label: 'Attendees', path: '/attendees', icon: Users, group: 'Event', keywords: 'points leaderboard' },
|
||||||
|
];
|
||||||
|
|
||||||
|
export const navGroups = [...new Set(navEntries.map((e) => e.group))];
|
||||||
|
|
||||||
32
src/components/ui/badge.tsx
Normal file
32
src/components/ui/badge.tsx
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
import type * as React from 'react';
|
||||||
|
import { cva, type VariantProps } from 'class-variance-authority';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export const badgeVariants = cva(
|
||||||
|
'inline-flex w-fit items-center gap-1 whitespace-nowrap rounded-full px-2 py-0.5 text-xs font-semibold [&_svg]:size-3 [&_svg]:shrink-0',
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
tone: {
|
||||||
|
neutral: 'bg-surface-muted text-muted',
|
||||||
|
primary: 'bg-primary-soft text-primary-soft-fg',
|
||||||
|
success: 'bg-success-soft text-success',
|
||||||
|
warning: 'bg-warning-soft text-warning',
|
||||||
|
danger: 'bg-danger-soft text-danger',
|
||||||
|
info: 'bg-info-soft text-info',
|
||||||
|
outline: 'border border-border text-muted',
|
||||||
|
solid: 'bg-accent text-accent-fg',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { tone: 'neutral' },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export type BadgeTone = NonNullable<VariantProps<typeof badgeVariants>['tone']>;
|
||||||
|
|
||||||
|
export function Badge({
|
||||||
|
className,
|
||||||
|
tone,
|
||||||
|
...props
|
||||||
|
}: React.HTMLAttributes<HTMLSpanElement> & VariantProps<typeof badgeVariants>) {
|
||||||
|
return <span className={cn(badgeVariants({ tone }), className)} {...props} />;
|
||||||
|
}
|
||||||
65
src/components/ui/button.tsx
Normal file
65
src/components/ui/button.tsx
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import { Slot } from '@radix-ui/react-slot';
|
||||||
|
import { cva, type VariantProps } from 'class-variance-authority';
|
||||||
|
import { Loader2 } from 'lucide-react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export const buttonVariants = cva(
|
||||||
|
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-full text-sm font-semibold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus focus-visible:ring-offset-2 focus-visible:ring-offset-canvas disabled:pointer-events-none disabled:opacity-40 active:scale-[0.98] [&_svg]:size-4 [&_svg]:shrink-0',
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
primary: 'bg-primary text-primary-fg hover:bg-primary-hover',
|
||||||
|
secondary: 'border border-primary text-primary bg-surface hover:bg-surface-muted',
|
||||||
|
outline: 'border border-border bg-surface text-fg hover:bg-surface-muted',
|
||||||
|
ghost: 'text-fg hover:bg-surface-muted',
|
||||||
|
danger: 'bg-danger text-surface hover:opacity-90',
|
||||||
|
'danger-outline': 'border border-border bg-surface text-danger hover:bg-danger-soft',
|
||||||
|
link: 'h-auto px-0 text-primary-soft-fg underline-offset-4 hover:underline',
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
sm: 'h-9 px-3.5 coarse:min-h-11',
|
||||||
|
md: 'h-10 px-5',
|
||||||
|
lg: 'h-12 px-6 text-base',
|
||||||
|
icon: 'h-10 w-10 coarse:min-h-11 coarse:min-w-11',
|
||||||
|
'icon-sm': 'h-8 w-8 coarse:min-h-11 coarse:min-w-11',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { variant: 'primary', size: 'md' },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export interface ButtonProps
|
||||||
|
extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
||||||
|
asChild?: boolean;
|
||||||
|
loading?: boolean;
|
||||||
|
fullWidth?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||||
|
(
|
||||||
|
{ className, variant, size, asChild = false, loading, fullWidth, children, disabled, ...props },
|
||||||
|
ref,
|
||||||
|
) => {
|
||||||
|
const Comp = asChild ? Slot : 'button';
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
ref={ref}
|
||||||
|
className={cn(buttonVariants({ variant, size }), fullWidth && 'w-full', className)}
|
||||||
|
disabled={asChild ? undefined : disabled || loading}
|
||||||
|
aria-busy={loading || undefined}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{asChild ? (
|
||||||
|
children
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{loading ? <Loader2 className="animate-spin" aria-hidden /> : null}
|
||||||
|
{children}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Comp>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
Button.displayName = 'Button';
|
||||||
44
src/components/ui/card.tsx
Normal file
44
src/components/ui/card.tsx
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export function Card({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn('rounded-xl border border-primary/12 bg-surface text-fg shadow-card', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CardHeader({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
|
return <div className={cn('flex flex-col gap-1.5 p-5 pb-3', className)} {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CardTitle({ className, ...props }: React.HTMLAttributes<HTMLHeadingElement>) {
|
||||||
|
return (
|
||||||
|
<h3 className={cn('font-display text-base font-semibold leading-snug', className)} {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CardDescription({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.HTMLAttributes<HTMLParagraphElement>) {
|
||||||
|
return <p className={cn('text-sm text-muted', className)} {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CardContent({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
|
return <div className={cn('p-5 pt-0', className)} {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CardFooter({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'flex flex-wrap items-center gap-2 border-t border-border px-5 py-3',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
27
src/components/ui/checkbox.tsx
Normal file
27
src/components/ui/checkbox.tsx
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
||||||
|
import { Check, Minus } from 'lucide-react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export const Checkbox = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CheckboxPrimitive.Root>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<CheckboxPrimitive.Root
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
'hit-44 peer h-5 w-5 shrink-0 rounded-[6px] border border-input bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus focus-visible:ring-offset-2 focus-visible:ring-offset-canvas disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-fg data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-fg',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
|
||||||
|
{props.checked === 'indeterminate' ? (
|
||||||
|
<Minus className="h-3.5 w-3.5" />
|
||||||
|
) : (
|
||||||
|
<Check className="h-3.5 w-3.5" strokeWidth={3} />
|
||||||
|
)}
|
||||||
|
</CheckboxPrimitive.Indicator>
|
||||||
|
</CheckboxPrimitive.Root>
|
||||||
|
));
|
||||||
|
Checkbox.displayName = 'Checkbox';
|
||||||
119
src/components/ui/command.tsx
Normal file
119
src/components/ui/command.tsx
Normal file
|
|
@ -0,0 +1,119 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
||||||
|
import { Command as CommandPrimitive } from 'cmdk';
|
||||||
|
import { Search } from 'lucide-react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export const Command = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CommandPrimitive>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<CommandPrimitive
|
||||||
|
ref={ref}
|
||||||
|
className={cn('flex h-full w-full flex-col overflow-hidden bg-surface text-fg', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
Command.displayName = 'Command';
|
||||||
|
|
||||||
|
export function CommandDialog({
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
label,
|
||||||
|
description,
|
||||||
|
shouldFilter = true,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
label: string;
|
||||||
|
description: string;
|
||||||
|
shouldFilter?: boolean;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DialogPrimitive.Root open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogPrimitive.Portal>
|
||||||
|
<DialogPrimitive.Overlay className="fixed inset-0 z-50 bg-overlay" />
|
||||||
|
<DialogPrimitive.Content className="fixed left-1/2 top-4 z-50 w-[calc(100vw-2rem)] max-w-xl -translate-x-1/2 overflow-hidden rounded-xl border border-border bg-surface shadow-pop sm:top-[12vh]">
|
||||||
|
<DialogPrimitive.Title className="sr-only">{label}</DialogPrimitive.Title>
|
||||||
|
<DialogPrimitive.Description className="sr-only">
|
||||||
|
{description}
|
||||||
|
</DialogPrimitive.Description>
|
||||||
|
<Command
|
||||||
|
loop
|
||||||
|
shouldFilter={shouldFilter}
|
||||||
|
className="[&_[cmdk-group-heading]]:px-3 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-semibold [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wide [&_[cmdk-group-heading]]:text-subtle [&_[cmdk-group]]:px-2 [&_[cmdk-item]]:px-3 [&_[cmdk-item]]:py-2.5"
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Command>
|
||||||
|
</DialogPrimitive.Content>
|
||||||
|
</DialogPrimitive.Portal>
|
||||||
|
</DialogPrimitive.Root>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CommandInput = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CommandPrimitive.Input>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<div className="flex items-center gap-2 border-b border-border px-4" cmdk-input-wrapper="">
|
||||||
|
<Search className="h-4 w-4 shrink-0 text-muted" aria-hidden />
|
||||||
|
<CommandPrimitive.Input
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
'flex h-12 w-full bg-transparent py-3 text-sm outline-none placeholder:text-subtle focus-visible:ring-0',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
));
|
||||||
|
CommandInput.displayName = 'CommandInput';
|
||||||
|
|
||||||
|
export const CommandList = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CommandPrimitive.List>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<CommandPrimitive.List
|
||||||
|
ref={ref}
|
||||||
|
className={cn('max-h-[min(60vh,420px)] overflow-y-auto overflow-x-hidden py-2', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
CommandList.displayName = 'CommandList';
|
||||||
|
|
||||||
|
export const CommandEmpty = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CommandPrimitive.Empty>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<CommandPrimitive.Empty
|
||||||
|
ref={ref}
|
||||||
|
className={cn('px-4 py-10 text-center text-sm text-muted', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
CommandEmpty.displayName = 'CommandEmpty';
|
||||||
|
|
||||||
|
export const CommandGroup = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CommandPrimitive.Group>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<CommandPrimitive.Group ref={ref} className={cn('overflow-hidden py-1', className)} {...props} />
|
||||||
|
));
|
||||||
|
CommandGroup.displayName = 'CommandGroup';
|
||||||
|
|
||||||
|
export const CommandItem = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CommandPrimitive.Item>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<CommandPrimitive.Item
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
'relative flex cursor-pointer select-none items-center gap-3 rounded-md text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-primary-soft data-[selected=true]:text-fg data-[disabled=true]:opacity-50',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
CommandItem.displayName = 'CommandItem';
|
||||||
91
src/components/ui/confirm-dialog.tsx
Normal file
91
src/components/ui/confirm-dialog.tsx
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
import { useState, type ReactNode } from 'react';
|
||||||
|
import { Button } from './button';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from './dialog';
|
||||||
|
import { Textarea } from './input';
|
||||||
|
import { Label } from './label';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructive / consequential confirmation (SPEC §5): states the consequence and the confirm
|
||||||
|
* button repeats the action. Optional reason field (reject / cancel with reason).
|
||||||
|
*/
|
||||||
|
export function ConfirmDialog({
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
confirmLabel,
|
||||||
|
tone = 'primary',
|
||||||
|
onConfirm,
|
||||||
|
loading,
|
||||||
|
reason,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
title: ReactNode;
|
||||||
|
description?: ReactNode;
|
||||||
|
confirmLabel: string;
|
||||||
|
tone?: 'primary' | 'danger';
|
||||||
|
onConfirm: (reason?: string) => void | Promise<unknown>;
|
||||||
|
loading?: boolean;
|
||||||
|
/** show a reason textarea with this label */
|
||||||
|
reason?: { label: string; required?: boolean; placeholder?: string };
|
||||||
|
children?: ReactNode;
|
||||||
|
}) {
|
||||||
|
const [text, setText] = useState('');
|
||||||
|
const disabled = Boolean(reason?.required && !text.trim());
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
open={open}
|
||||||
|
onOpenChange={(o) => {
|
||||||
|
if (!o) setText('');
|
||||||
|
onOpenChange(o);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{title}</DialogTitle>
|
||||||
|
{description ? <DialogDescription>{description}</DialogDescription> : null}
|
||||||
|
</DialogHeader>
|
||||||
|
{children}
|
||||||
|
{reason ? (
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="confirm-reason">
|
||||||
|
{reason.label}
|
||||||
|
{reason.required ? null : (
|
||||||
|
<span className="ml-1 font-normal text-subtle">(optional)</span>
|
||||||
|
)}
|
||||||
|
</Label>
|
||||||
|
<Textarea
|
||||||
|
id="confirm-reason"
|
||||||
|
value={text}
|
||||||
|
placeholder={reason.placeholder}
|
||||||
|
onChange={(e) => setText(e.target.value)}
|
||||||
|
maxLength={500}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="secondary" onClick={() => onOpenChange(false)}>
|
||||||
|
Back
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant={tone === 'danger' ? 'danger' : 'primary'}
|
||||||
|
loading={loading}
|
||||||
|
disabled={disabled}
|
||||||
|
onClick={() => void onConfirm(reason ? text.trim() || undefined : undefined)}
|
||||||
|
>
|
||||||
|
{confirmLabel}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
75
src/components/ui/dialog.tsx
Normal file
75
src/components/ui/dialog.tsx
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
||||||
|
import { X } from 'lucide-react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export const Dialog = DialogPrimitive.Root;
|
||||||
|
export const DialogTrigger = DialogPrimitive.Trigger;
|
||||||
|
export const DialogClose = DialogPrimitive.Close;
|
||||||
|
|
||||||
|
export const DialogContent = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & { hideClose?: boolean }
|
||||||
|
>(({ className, children, hideClose, ...props }, ref) => {
|
||||||
|
return (
|
||||||
|
<DialogPrimitive.Portal>
|
||||||
|
<DialogPrimitive.Overlay className="fixed inset-0 z-50 bg-overlay" />
|
||||||
|
<DialogPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
'fixed left-1/2 top-1/2 z-50 grid max-h-[calc(100dvh-2rem)] w-[calc(100vw-2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 overflow-y-auto rounded-xl border border-border bg-surface p-6 text-fg shadow-pop focus:outline-none',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
{hideClose ? null : (
|
||||||
|
<DialogPrimitive.Close
|
||||||
|
className="absolute right-3 top-3 rounded-md p-2 text-muted hover:bg-surface-muted hover:text-fg"
|
||||||
|
aria-label="Close"
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
</DialogPrimitive.Close>
|
||||||
|
)}
|
||||||
|
</DialogPrimitive.Content>
|
||||||
|
</DialogPrimitive.Portal>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
DialogContent.displayName = 'DialogContent';
|
||||||
|
|
||||||
|
export function DialogHeader({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
|
return <div className={cn('flex flex-col gap-1.5 pr-8 text-left', className)} {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DialogTitle = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DialogPrimitive.Title>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<DialogPrimitive.Title
|
||||||
|
ref={ref}
|
||||||
|
className={cn('font-display text-lg font-semibold', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
DialogTitle.displayName = 'DialogTitle';
|
||||||
|
|
||||||
|
export const DialogDescription = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DialogPrimitive.Description>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<DialogPrimitive.Description
|
||||||
|
ref={ref}
|
||||||
|
className={cn('text-sm text-muted', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
DialogDescription.displayName = 'DialogDescription';
|
||||||
|
|
||||||
|
export function DialogFooter({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn('flex flex-col-reverse gap-2 sm:flex-row sm:justify-end', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
137
src/components/ui/dropdown-menu.tsx
Normal file
137
src/components/ui/dropdown-menu.tsx
Normal file
|
|
@ -0,0 +1,137 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
|
||||||
|
import { Check, ChevronRight } from 'lucide-react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export const DropdownMenu = DropdownMenuPrimitive.Root;
|
||||||
|
export const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
|
||||||
|
export const DropdownMenuGroup = DropdownMenuPrimitive.Group;
|
||||||
|
export const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
||||||
|
export const DropdownMenuSub = DropdownMenuPrimitive.Sub;
|
||||||
|
|
||||||
|
const itemClass =
|
||||||
|
'relative flex min-h-9 cursor-pointer select-none items-center gap-2 rounded-sm px-2.5 py-2 text-sm text-fg outline-none transition-colors focus:bg-surface-muted data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-muted';
|
||||||
|
|
||||||
|
export const DropdownMenuContent = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
|
||||||
|
>(({ className, sideOffset = 6, ...props }, ref) => (
|
||||||
|
<DropdownMenuPrimitive.Portal>
|
||||||
|
<DropdownMenuPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
className={cn(
|
||||||
|
'z-50 max-h-[var(--radix-dropdown-menu-content-available-height)] min-w-[12rem] overflow-y-auto rounded-md border border-border bg-surface p-1 text-fg shadow-pop',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</DropdownMenuPrimitive.Portal>
|
||||||
|
));
|
||||||
|
DropdownMenuContent.displayName = 'DropdownMenuContent';
|
||||||
|
|
||||||
|
export const DropdownMenuItem = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & { destructive?: boolean }
|
||||||
|
>(({ className, destructive, ...props }, ref) => (
|
||||||
|
<DropdownMenuPrimitive.Item
|
||||||
|
ref={ref}
|
||||||
|
className={cn(itemClass, destructive && 'text-danger [&_svg]:text-danger', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
DropdownMenuItem.displayName = 'DropdownMenuItem';
|
||||||
|
|
||||||
|
export const DropdownMenuCheckboxItem = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
|
||||||
|
>(({ className, children, ...props }, ref) => (
|
||||||
|
<DropdownMenuPrimitive.CheckboxItem
|
||||||
|
ref={ref}
|
||||||
|
className={cn(itemClass, 'pl-8', className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="absolute left-2.5 flex h-4 w-4 items-center justify-center">
|
||||||
|
<DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
<Check className="!text-fg" />
|
||||||
|
</DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
{children}
|
||||||
|
</DropdownMenuPrimitive.CheckboxItem>
|
||||||
|
));
|
||||||
|
DropdownMenuCheckboxItem.displayName = 'DropdownMenuCheckboxItem';
|
||||||
|
|
||||||
|
export const DropdownMenuRadioItem = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
|
||||||
|
>(({ className, children, ...props }, ref) => (
|
||||||
|
<DropdownMenuPrimitive.RadioItem
|
||||||
|
ref={ref}
|
||||||
|
className={cn(itemClass, 'pl-8', className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="absolute left-2.5 flex h-4 w-4 items-center justify-center">
|
||||||
|
<DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
<Check className="!text-primary-soft-fg" />
|
||||||
|
</DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
{children}
|
||||||
|
</DropdownMenuPrimitive.RadioItem>
|
||||||
|
));
|
||||||
|
DropdownMenuRadioItem.displayName = 'DropdownMenuRadioItem';
|
||||||
|
|
||||||
|
export const DropdownMenuSubTrigger = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger>
|
||||||
|
>(({ className, children, ...props }, ref) => (
|
||||||
|
<DropdownMenuPrimitive.SubTrigger
|
||||||
|
ref={ref}
|
||||||
|
className={cn(itemClass, 'data-[state=open]:bg-surface-muted', className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<ChevronRight className="ml-auto" />
|
||||||
|
</DropdownMenuPrimitive.SubTrigger>
|
||||||
|
));
|
||||||
|
DropdownMenuSubTrigger.displayName = 'DropdownMenuSubTrigger';
|
||||||
|
|
||||||
|
export const DropdownMenuSubContent = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<DropdownMenuPrimitive.Portal>
|
||||||
|
<DropdownMenuPrimitive.SubContent
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
'z-50 min-w-[10rem] overflow-hidden rounded-md border border-border bg-surface p-1 text-fg shadow-pop',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</DropdownMenuPrimitive.Portal>
|
||||||
|
));
|
||||||
|
DropdownMenuSubContent.displayName = 'DropdownMenuSubContent';
|
||||||
|
|
||||||
|
export function DropdownMenuLabel({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'px-2.5 py-1.5 text-xs font-semibold uppercase tracking-wider text-subtle',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DropdownMenuSeparator = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<DropdownMenuPrimitive.Separator
|
||||||
|
ref={ref}
|
||||||
|
className={cn('-mx-1 my-1 h-px bg-border', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
DropdownMenuSeparator.displayName = 'DropdownMenuSeparator';
|
||||||
51
src/components/ui/empty-state.tsx
Normal file
51
src/components/ui/empty-state.tsx
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
import type { ReactNode } from 'react';
|
||||||
|
import type { LucideIcon } from 'lucide-react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export function EmptyState({
|
||||||
|
icon: Icon,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
action,
|
||||||
|
variant = 'inline',
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
icon?: LucideIcon;
|
||||||
|
title: string;
|
||||||
|
description?: string;
|
||||||
|
/** one primary action that fills the empty state */
|
||||||
|
action?: ReactNode;
|
||||||
|
variant?: 'inline' | 'dashed' | 'page';
|
||||||
|
className?: string;
|
||||||
|
}) {
|
||||||
|
const isPage = variant === 'page';
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'flex flex-col items-center justify-center gap-2 px-6 text-center',
|
||||||
|
variant === 'inline' && 'py-8',
|
||||||
|
variant === 'dashed' && 'rounded-lg border border-dashed border-border-strong py-10',
|
||||||
|
isPage && 'py-14',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{Icon ? (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'mb-1 flex items-center justify-center rounded-full bg-primary-soft text-primary-soft-fg',
|
||||||
|
isPage ? 'h-14 w-14' : 'h-10 w-10',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Icon className={isPage ? 'h-6 w-6' : 'h-5 w-5'} aria-hidden />
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{isPage ? (
|
||||||
|
<h1 className="font-display text-lg font-semibold text-fg">{title}</h1>
|
||||||
|
) : (
|
||||||
|
<p className="text-sm font-semibold text-fg">{title}</p>
|
||||||
|
)}
|
||||||
|
{description ? <p className="max-w-md text-sm text-muted">{description}</p> : null}
|
||||||
|
{action ? <div className="mt-2">{action}</div> : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
57
src/components/ui/field.tsx
Normal file
57
src/components/ui/field.tsx
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
import { cloneElement, isValidElement, useId, type ReactElement, type ReactNode } from 'react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import { Label } from './label';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label above the control, optional hint, error under it (SPEC §5 forms pattern).
|
||||||
|
* Wires id / aria-describedby / aria-invalid into the single child control.
|
||||||
|
*/
|
||||||
|
export function Field({
|
||||||
|
label,
|
||||||
|
hint,
|
||||||
|
error,
|
||||||
|
optional,
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
id: idProp,
|
||||||
|
}: {
|
||||||
|
label: ReactNode;
|
||||||
|
hint?: ReactNode;
|
||||||
|
error?: ReactNode;
|
||||||
|
optional?: boolean;
|
||||||
|
children: ReactElement<Record<string, unknown>>;
|
||||||
|
className?: string;
|
||||||
|
id?: string;
|
||||||
|
}) {
|
||||||
|
const auto = useId();
|
||||||
|
const id = idProp ?? auto;
|
||||||
|
const hintId = hint ? `${id}-hint` : undefined;
|
||||||
|
const errorId = error ? `${id}-error` : undefined;
|
||||||
|
const describedBy = [hintId, errorId].filter(Boolean).join(' ') || undefined;
|
||||||
|
const control = isValidElement(children)
|
||||||
|
? cloneElement(children, {
|
||||||
|
id,
|
||||||
|
'aria-describedby': describedBy,
|
||||||
|
'aria-invalid': error ? true : undefined,
|
||||||
|
})
|
||||||
|
: children;
|
||||||
|
return (
|
||||||
|
<div className={cn('space-y-1.5', className)}>
|
||||||
|
<Label htmlFor={id}>
|
||||||
|
{label}
|
||||||
|
{optional ? <span className="ml-1 font-normal text-subtle">(optional)</span> : null}
|
||||||
|
</Label>
|
||||||
|
{control}
|
||||||
|
{hint ? (
|
||||||
|
<p id={hintId} className="text-xs text-muted">
|
||||||
|
{hint}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
{error ? (
|
||||||
|
<p id={errorId} role="alert" className="text-xs font-medium text-danger">
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
30
src/components/ui/input.tsx
Normal file
30
src/components/ui/input.tsx
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export const inputClass =
|
||||||
|
'flex h-10 w-full rounded-lg border border-primary/20 bg-surface px-3 py-2 text-sm text-fg placeholder:text-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus focus-visible:ring-offset-1 focus-visible:ring-offset-surface disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-danger';
|
||||||
|
|
||||||
|
export const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<'input'>>(
|
||||||
|
({ className, type, ...props }, ref) => (
|
||||||
|
<input ref={ref} type={type} className={cn(inputClass, className)} {...props} />
|
||||||
|
),
|
||||||
|
);
|
||||||
|
Input.displayName = 'Input';
|
||||||
|
|
||||||
|
export const Textarea = React.forwardRef<HTMLTextAreaElement, React.ComponentProps<'textarea'>>(
|
||||||
|
({ className, ...props }, ref) => (
|
||||||
|
<textarea
|
||||||
|
ref={ref}
|
||||||
|
className={cn(inputClass, 'min-h-[88px] h-auto py-2.5 leading-relaxed', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
);
|
||||||
|
Textarea.displayName = 'Textarea';
|
||||||
|
|
||||||
|
export const SelectNative = React.forwardRef<HTMLSelectElement, React.ComponentProps<'select'>>(
|
||||||
|
({ className, ...props }, ref) => (
|
||||||
|
<select ref={ref} className={cn(inputClass, 'pr-8', className)} {...props} />
|
||||||
|
),
|
||||||
|
);
|
||||||
|
SelectNative.displayName = 'SelectNative';
|
||||||
15
src/components/ui/label.tsx
Normal file
15
src/components/ui/label.tsx
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as LabelPrimitive from '@radix-ui/react-label';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export const Label = React.forwardRef<
|
||||||
|
React.ElementRef<typeof LabelPrimitive.Root>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<LabelPrimitive.Root
|
||||||
|
ref={ref}
|
||||||
|
className={cn('text-sm font-medium text-fg peer-disabled:opacity-60', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
Label.displayName = 'Label';
|
||||||
15
src/components/ui/skeleton.tsx
Normal file
15
src/components/ui/skeleton.tsx
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export function Skeleton({ className }: { className?: string }) {
|
||||||
|
return <div aria-hidden className={cn('animate-pulse rounded-md bg-surface-muted', className)} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SkeletonRows({ rows = 5, className }: { rows?: number; className?: string }) {
|
||||||
|
return (
|
||||||
|
<div className={cn('space-y-2', className)} aria-busy="true">
|
||||||
|
{Array.from({ length: rows }, (_, i) => (
|
||||||
|
<Skeleton key={i} className="h-12 w-full" />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
51
src/components/ui/switch.tsx
Normal file
51
src/components/ui/switch.tsx
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as SwitchPrimitive from '@radix-ui/react-switch';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export const Switch = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SwitchPrimitive.Root>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SwitchPrimitive.Root>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<SwitchPrimitive.Root
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
'hit-44 peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus focus-visible:ring-offset-2 focus-visible:ring-offset-canvas disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<SwitchPrimitive.Thumb className="pointer-events-none block h-5 w-5 rounded-full bg-surface shadow-card transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0" />
|
||||||
|
</SwitchPrimitive.Root>
|
||||||
|
));
|
||||||
|
Switch.displayName = 'Switch';
|
||||||
|
|
||||||
|
/** Switch with a label and optional description, the whole row clickable. */
|
||||||
|
export function SwitchRow({
|
||||||
|
label,
|
||||||
|
description,
|
||||||
|
checked,
|
||||||
|
onCheckedChange,
|
||||||
|
disabled,
|
||||||
|
id,
|
||||||
|
}: {
|
||||||
|
label: React.ReactNode;
|
||||||
|
description?: React.ReactNode;
|
||||||
|
checked: boolean;
|
||||||
|
onCheckedChange: (v: boolean) => void;
|
||||||
|
disabled?: boolean;
|
||||||
|
id?: string;
|
||||||
|
}) {
|
||||||
|
const auto = React.useId();
|
||||||
|
const sid = id ?? auto;
|
||||||
|
return (
|
||||||
|
<div className="flex items-start justify-between gap-4 py-2">
|
||||||
|
<label htmlFor={sid} className="min-w-0 cursor-pointer">
|
||||||
|
<span className="block text-sm font-medium text-fg">{label}</span>
|
||||||
|
{description ? (
|
||||||
|
<span className="mt-0.5 block text-xs text-muted">{description}</span>
|
||||||
|
) : null}
|
||||||
|
</label>
|
||||||
|
<Switch id={sid} checked={checked} onCheckedChange={onCheckedChange} disabled={disabled} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
51
src/components/ui/table.tsx
Normal file
51
src/components/ui/table.tsx
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
import type * as React from 'react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export function Table({ className, ...props }: React.HTMLAttributes<HTMLTableElement>) {
|
||||||
|
return (
|
||||||
|
<div className="relative w-full overflow-x-auto">
|
||||||
|
<table className={cn('w-full caption-bottom text-sm', className)} {...props} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TableHeader({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.HTMLAttributes<HTMLTableSectionElement>) {
|
||||||
|
return (
|
||||||
|
<thead className={cn('[&_tr]:border-b [&_tr]:hover:bg-transparent', className)} {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TableBody({ className, ...props }: React.HTMLAttributes<HTMLTableSectionElement>) {
|
||||||
|
return <tbody className={cn('[&_tr:last-child]:border-0', className)} {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TableRow({ className, ...props }: React.HTMLAttributes<HTMLTableRowElement>) {
|
||||||
|
return (
|
||||||
|
<tr
|
||||||
|
className={cn(
|
||||||
|
'border-b border-border transition-colors hover:bg-surface-muted data-[state=selected]:bg-primary-soft',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TableHead({ className, ...props }: React.ThHTMLAttributes<HTMLTableCellElement>) {
|
||||||
|
return (
|
||||||
|
<th
|
||||||
|
className={cn(
|
||||||
|
'h-11 whitespace-nowrap px-4 text-left align-middle text-xs font-semibold uppercase tracking-[0.04em] text-muted',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TableCell({ className, ...props }: React.TdHTMLAttributes<HTMLTableCellElement>) {
|
||||||
|
return <td className={cn('px-4 py-3 align-middle text-sm', className)} {...props} />;
|
||||||
|
}
|
||||||
47
src/components/ui/tabs.tsx
Normal file
47
src/components/ui/tabs.tsx
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as TabsPrimitive from '@radix-ui/react-tabs';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
export const Tabs = TabsPrimitive.Root;
|
||||||
|
|
||||||
|
export const TabsList = React.forwardRef<
|
||||||
|
React.ElementRef<typeof TabsPrimitive.List>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<TabsPrimitive.List
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
'inline-flex h-11 max-w-full items-center gap-1 overflow-x-auto rounded-md bg-surface-muted p-1 text-muted',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TabsList.displayName = 'TabsList';
|
||||||
|
|
||||||
|
export const TabsTrigger = React.forwardRef<
|
||||||
|
React.ElementRef<typeof TabsPrimitive.Trigger>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<TabsPrimitive.Trigger
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
'inline-flex h-9 items-center justify-center gap-1.5 whitespace-nowrap rounded-sm px-3 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus data-[state=active]:bg-surface data-[state=active]:text-fg data-[state=active]:shadow-card',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TabsTrigger.displayName = 'TabsTrigger';
|
||||||
|
|
||||||
|
export const TabsContent = React.forwardRef<
|
||||||
|
React.ElementRef<typeof TabsPrimitive.Content>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<TabsPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
className={cn('mt-4 focus-visible:outline-none', className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TabsContent.displayName = 'TabsContent';
|
||||||
153
src/index.css
Normal file
153
src/index.css
Normal file
|
|
@ -0,0 +1,153 @@
|
||||||
|
@import 'tailwindcss';
|
||||||
|
@import '@fontsource-variable/dm-sans/wght.css';
|
||||||
|
|
||||||
|
/* Antebas (Fontspring DEMO) is letters only, same setup as GRVSummit/app/antebas.css.
|
||||||
|
Demo numerals are watermarks, so DM Sans covers digits and punctuation. */
|
||||||
|
@font-face {
|
||||||
|
font-family: Antebas;
|
||||||
|
src: url('/fonts/Fontspring-DEMO-antebas-light.otf') format('opentype');
|
||||||
|
font-weight: 300;
|
||||||
|
font-display: swap;
|
||||||
|
unicode-range: U+0041-005A, U+0061-007A, U+00C0-00D6, U+00D8-00F6, U+00F8-00FF, U+0100-017F;
|
||||||
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: Antebas;
|
||||||
|
src: url('/fonts/Fontspring-DEMO-antebas-regular.otf') format('opentype');
|
||||||
|
font-weight: 400;
|
||||||
|
font-display: swap;
|
||||||
|
unicode-range: U+0041-005A, U+0061-007A, U+00C0-00D6, U+00D8-00F6, U+00F8-00FF, U+0100-017F;
|
||||||
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: Antebas;
|
||||||
|
src: url('/fonts/Fontspring-DEMO-antebas-medium.otf') format('opentype');
|
||||||
|
font-weight: 500;
|
||||||
|
font-display: swap;
|
||||||
|
unicode-range: U+0041-005A, U+0061-007A, U+00C0-00D6, U+00D8-00F6, U+00F8-00FF, U+0100-017F;
|
||||||
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: Antebas;
|
||||||
|
src: url('/fonts/Fontspring-DEMO-antebas-bold.otf') format('opentype');
|
||||||
|
font-weight: 700;
|
||||||
|
font-display: swap;
|
||||||
|
unicode-range: U+0041-005A, U+0061-007A, U+00C0-00D6, U+00D8-00F6, U+00F8-00FF, U+0100-017F;
|
||||||
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: Antebas;
|
||||||
|
src: url('/fonts/Fontspring-DEMO-antebas-black.otf') format('opentype');
|
||||||
|
font-weight: 900;
|
||||||
|
font-display: swap;
|
||||||
|
unicode-range: U+0041-005A, U+0061-007A, U+00C0-00D6, U+00D8-00F6, U+00F8-00FF, U+0100-017F;
|
||||||
|
}
|
||||||
|
|
||||||
|
@custom-variant coarse (@media (pointer: coarse));
|
||||||
|
|
||||||
|
/* GRV brand tokens (GRVSummit/app/globals.css), mapped to the semantic names the shell uses. */
|
||||||
|
@theme {
|
||||||
|
--font-sans: 'DM Sans Variable', system-ui, sans-serif;
|
||||||
|
--font-display: Antebas, 'DM Sans Variable', system-ui, sans-serif;
|
||||||
|
|
||||||
|
--color-brand-primary: #30614c;
|
||||||
|
--color-brand-secondary: #b9d8c9;
|
||||||
|
--color-brand-tertiary: #1a4034;
|
||||||
|
|
||||||
|
--color-canvas: #fafafa;
|
||||||
|
--color-surface: #ffffff;
|
||||||
|
--color-surface-muted: #e8f2ec;
|
||||||
|
--color-border: #dbdbdb;
|
||||||
|
--color-border-strong: #a0a0a0;
|
||||||
|
--color-input: #dbdbdb;
|
||||||
|
--color-fg: #1a4034;
|
||||||
|
--color-muted: #5b5b5b;
|
||||||
|
--color-subtle: #a0a0a0;
|
||||||
|
|
||||||
|
--color-primary: #30614c;
|
||||||
|
--color-primary-hover: #1a4034;
|
||||||
|
--color-primary-fg: #ffffff;
|
||||||
|
--color-primary-soft: #e8f2ec;
|
||||||
|
--color-primary-soft-fg: #30614c;
|
||||||
|
--color-secondary: #b9d8c9;
|
||||||
|
|
||||||
|
--color-success: #30614c;
|
||||||
|
--color-success-soft: #e8f2ec;
|
||||||
|
--color-warning: #92400e;
|
||||||
|
--color-warning-soft: #fef3c7;
|
||||||
|
--color-danger: #dc2626;
|
||||||
|
--color-danger-soft: #fee2e2;
|
||||||
|
--color-info: #075985;
|
||||||
|
--color-info-soft: #e0f2fe;
|
||||||
|
|
||||||
|
--color-accent: #1a4034;
|
||||||
|
--color-accent-fg: #ffffff;
|
||||||
|
--color-focus: #30614c;
|
||||||
|
--color-overlay: rgb(26 64 52 / 0.45);
|
||||||
|
|
||||||
|
--color-nav: #1a4034;
|
||||||
|
--color-nav-fg: #ffffff;
|
||||||
|
--color-nav-muted: #b9d8c9;
|
||||||
|
--color-nav-active: #30614c;
|
||||||
|
--color-nav-active-fg: #ffffff;
|
||||||
|
--color-nav-hover: rgb(255 255 255 / 0.08);
|
||||||
|
--color-nav-border: rgb(255 255 255 / 0.12);
|
||||||
|
|
||||||
|
--radius-sm: 0.5rem;
|
||||||
|
--radius-md: 0.625rem;
|
||||||
|
--radius-lg: 0.75rem;
|
||||||
|
--radius-xl: 1rem;
|
||||||
|
--radius-2xl: 1.25rem;
|
||||||
|
|
||||||
|
--shadow-card: 0 1px 2px rgb(26 64 52 / 0.06), 0 1px 3px rgb(26 64 52 / 0.04);
|
||||||
|
--shadow-pop: 0 12px 40px rgb(0 0 0 / 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
* {
|
||||||
|
border-color: var(--color-border);
|
||||||
|
}
|
||||||
|
html,
|
||||||
|
body,
|
||||||
|
#root {
|
||||||
|
min-height: 100%;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
@apply bg-canvas font-sans text-fg antialiased;
|
||||||
|
}
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3 {
|
||||||
|
@apply font-display;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
|
button:not(:disabled),
|
||||||
|
[role='button']:not(:disabled) {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer utilities {
|
||||||
|
.tabular {
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
/* Brand topography pattern. Both SVGs are opaque: main.svg is white lines on black (screen it
|
||||||
|
onto green), mainwhite.svg is dark lines on white (multiply it onto light, tinted green). */
|
||||||
|
.pattern-on-dark {
|
||||||
|
opacity: 0.16;
|
||||||
|
mix-blend-mode: screen;
|
||||||
|
}
|
||||||
|
.pattern-fade-up {
|
||||||
|
mask-image: linear-gradient(to top, #000 30%, transparent);
|
||||||
|
}
|
||||||
|
.pattern-on-light {
|
||||||
|
opacity: 0.3;
|
||||||
|
mix-blend-mode: multiply;
|
||||||
|
filter: sepia(0.35) saturate(2.2) hue-rotate(92deg) brightness(0.96) contrast(0.92);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media print {
|
||||||
|
.no-print {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
background: white !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
96
src/lib/api.ts
Normal file
96
src/lib/api.ts
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
import type { User } from './types';
|
||||||
|
|
||||||
|
export const API_URL = (import.meta.env.VITE_API_URL ?? 'http://localhost:4000').replace(/\/$/, '');
|
||||||
|
|
||||||
|
const TOKEN_KEY = 'grv_admin_token';
|
||||||
|
const USER_KEY = 'grv_admin_user';
|
||||||
|
|
||||||
|
export function getToken(): string | null {
|
||||||
|
return localStorage.getItem(TOKEN_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUser(): User | null {
|
||||||
|
try {
|
||||||
|
return JSON.parse(localStorage.getItem(USER_KEY) ?? 'null') as User | null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isAdmin = () => getUser()?.role === 'ADMIN';
|
||||||
|
|
||||||
|
export function saveSession(token: string, user: User) {
|
||||||
|
localStorage.setItem(TOKEN_KEY, token);
|
||||||
|
localStorage.setItem(USER_KEY, JSON.stringify(user));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function signOut() {
|
||||||
|
localStorage.removeItem(TOKEN_KEY);
|
||||||
|
localStorage.removeItem(USER_KEY);
|
||||||
|
if (location.pathname !== '/login') location.assign('/login');
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ApiError extends Error {
|
||||||
|
status: number;
|
||||||
|
code?: string;
|
||||||
|
errors?: Record<string, string>;
|
||||||
|
constructor(status: number, body: { error?: string; code?: string; errors?: Record<string, string> } | null) {
|
||||||
|
super(body?.error ?? `Request failed (${status})`);
|
||||||
|
this.status = status;
|
||||||
|
this.code = body?.code;
|
||||||
|
this.errors = body?.errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function send(path: string, init: { method?: string; body?: unknown } = {}): Promise<Response> {
|
||||||
|
const token = getToken();
|
||||||
|
const res = await fetch(`${API_URL}${path}`, {
|
||||||
|
method: init.method ?? (init.body === undefined ? 'GET' : 'POST'),
|
||||||
|
headers: {
|
||||||
|
...(init.body === undefined ? {} : { 'Content-Type': 'application/json' }),
|
||||||
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
||||||
|
},
|
||||||
|
body: init.body === undefined ? undefined : JSON.stringify(init.body),
|
||||||
|
});
|
||||||
|
// Tokens are not refreshable (API.md): any 401 on an authed call means "sign in again".
|
||||||
|
if (res.status === 401 && token) signOut();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** JSON request. Throws ApiError on non-2xx or `{ ok: false }` with the server's message. */
|
||||||
|
export async function api<T>(path: string, init: { method?: string; body?: unknown } = {}): Promise<T> {
|
||||||
|
const res = await send(path, init);
|
||||||
|
const text = await res.text();
|
||||||
|
let body: unknown = null;
|
||||||
|
try {
|
||||||
|
body = text ? JSON.parse(text) : null;
|
||||||
|
} catch {
|
||||||
|
// non-JSON error page (proxy, 502): fall through to the status message
|
||||||
|
}
|
||||||
|
const failed = body && typeof body === 'object' && (body as { ok?: unknown }).ok === false;
|
||||||
|
if (!res.ok || failed) throw new ApiError(res.status, body as never);
|
||||||
|
return body as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Authenticated file download (e.g. CSV export): fetch with the bearer, save the blob. */
|
||||||
|
export async function download(path: string, filename: string) {
|
||||||
|
const res = await send(path);
|
||||||
|
if (!res.ok) {
|
||||||
|
const body = await res.json().catch(() => null);
|
||||||
|
throw new ApiError(res.status, body);
|
||||||
|
}
|
||||||
|
const url = URL.createObjectURL(await res.blob());
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = filename;
|
||||||
|
a.click();
|
||||||
|
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** `?a=1&b=2` from an object, skipping empty values. */
|
||||||
|
export function qs(params: Record<string, string | undefined>): string {
|
||||||
|
const s = new URLSearchParams(
|
||||||
|
Object.entries(params).filter((e): e is [string, string] => Boolean(e[1])),
|
||||||
|
).toString();
|
||||||
|
return s ? `?${s}` : '';
|
||||||
|
}
|
||||||
197
src/lib/types.ts
Normal file
197
src/lib/types.ts
Normal file
|
|
@ -0,0 +1,197 @@
|
||||||
|
// Hand-written to match GRV-Backend/API.md. Keep in sync when the contract changes.
|
||||||
|
|
||||||
|
export type Role = 'ATTENDEE' | 'STAFF' | 'ADMIN';
|
||||||
|
export type User = { id: string; email: string; name: string | null; role: Role };
|
||||||
|
|
||||||
|
export type CheckpointKind = 'BOOTH' | 'STARTUP_MEMBER' | 'MYSTERY_INVESTEE';
|
||||||
|
export type Checkpoint = {
|
||||||
|
id: string;
|
||||||
|
kind: CheckpointKind;
|
||||||
|
label: string;
|
||||||
|
organisation: string | null;
|
||||||
|
boothNumber: string | null;
|
||||||
|
personName: string | null;
|
||||||
|
points: number;
|
||||||
|
qrToken: string;
|
||||||
|
qrUrl: string;
|
||||||
|
active: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type OrderStatus = 'PENDING' | 'PAID' | 'CANCELLED' | 'FULFILLED';
|
||||||
|
export type OrderKind = 'TICKET' | 'MERCH';
|
||||||
|
export type Ticket = {
|
||||||
|
id: string;
|
||||||
|
qrToken: string;
|
||||||
|
qrUrl: string;
|
||||||
|
tierName: string;
|
||||||
|
holderEmail: string;
|
||||||
|
holderName: string | null;
|
||||||
|
checkedInAt: string | null;
|
||||||
|
};
|
||||||
|
export type AdminTicket = Ticket & { orderNumber: string };
|
||||||
|
export type Order = {
|
||||||
|
id: string;
|
||||||
|
number: string;
|
||||||
|
kind: OrderKind;
|
||||||
|
status: OrderStatus;
|
||||||
|
buyerName: string;
|
||||||
|
buyerEmail: string;
|
||||||
|
buyerPhone: string | null;
|
||||||
|
company: string | null;
|
||||||
|
paymentMethod: 'card' | 'bank' | 'booth';
|
||||||
|
paymentRef: string | null;
|
||||||
|
subtotalMinor: number;
|
||||||
|
discountMinor: number;
|
||||||
|
totalMinor: number;
|
||||||
|
currency: string;
|
||||||
|
discountCode: string | null;
|
||||||
|
items: { name: string; qty: number; size: string | null; unitPriceMinor: number }[];
|
||||||
|
tickets?: Ticket[];
|
||||||
|
createdAt: string;
|
||||||
|
paidAt: string | null;
|
||||||
|
fulfilledAt: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Tier = {
|
||||||
|
id: string;
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
scheduleLabel: string | null;
|
||||||
|
features: string[];
|
||||||
|
priceMinor: number;
|
||||||
|
currency: string;
|
||||||
|
capacity: number | null;
|
||||||
|
sold: number;
|
||||||
|
active: boolean;
|
||||||
|
soldOut: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Discount = {
|
||||||
|
id: string;
|
||||||
|
code: string;
|
||||||
|
percentOff: number | null;
|
||||||
|
amountOffMinor: number | null;
|
||||||
|
tierId: string | null;
|
||||||
|
tierName: string | null;
|
||||||
|
maxUses: number | null;
|
||||||
|
uses: number;
|
||||||
|
startsAt: string | null;
|
||||||
|
endsAt: string | null;
|
||||||
|
active: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type MerchItem = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string | null;
|
||||||
|
priceMinor: number;
|
||||||
|
currency: string;
|
||||||
|
sizes: string[];
|
||||||
|
stock: number;
|
||||||
|
imageUrl: string | null;
|
||||||
|
active: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Raffle = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
prize: string;
|
||||||
|
minPoints: number;
|
||||||
|
drawnAt: string | null;
|
||||||
|
winner: { id: string; name: string | null; email?: string } | null;
|
||||||
|
eligibleCount?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const applicationStatuses = [
|
||||||
|
'SUBMITTED',
|
||||||
|
'UNDER_REVIEW',
|
||||||
|
'SHORTLISTED',
|
||||||
|
'FINALIST',
|
||||||
|
'ACCEPTED',
|
||||||
|
'REJECTED',
|
||||||
|
] as const;
|
||||||
|
export type ApplicationStatus = (typeof applicationStatuses)[number] | 'DRAFT';
|
||||||
|
|
||||||
|
export type ApplicationRow = {
|
||||||
|
id: string;
|
||||||
|
startupName: string | null;
|
||||||
|
founderName: string | null;
|
||||||
|
email: string;
|
||||||
|
primarySector: string | null;
|
||||||
|
stage: string | null;
|
||||||
|
city: string | null;
|
||||||
|
status: ApplicationStatus;
|
||||||
|
submittedAt: string | null;
|
||||||
|
avgScore: number | null;
|
||||||
|
reviewCount: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ApplicationDetail = {
|
||||||
|
id: string;
|
||||||
|
status: ApplicationStatus;
|
||||||
|
email: string;
|
||||||
|
startupName: string | null;
|
||||||
|
founderName: string | null;
|
||||||
|
createdAt: string;
|
||||||
|
submittedAt: string | null;
|
||||||
|
sections: { title: string; fields: { label: string; value: string }[] }[];
|
||||||
|
reviews: {
|
||||||
|
reviewer: string;
|
||||||
|
scores: Record<string, number>;
|
||||||
|
total: number;
|
||||||
|
comment: string | null;
|
||||||
|
updatedAt: string;
|
||||||
|
}[];
|
||||||
|
criteria: { id: string; label: string }[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const inquiryIntents = [
|
||||||
|
'general',
|
||||||
|
'exhibitor',
|
||||||
|
'sponsor',
|
||||||
|
'partnership',
|
||||||
|
'startup_referral',
|
||||||
|
'sales',
|
||||||
|
'press',
|
||||||
|
'newsletter',
|
||||||
|
] as const;
|
||||||
|
export type InquiryIntent = (typeof inquiryIntents)[number];
|
||||||
|
export const inquiryStatuses = ['NEW', 'CONTACTED', 'CLOSED'] as const;
|
||||||
|
export type InquiryStatus = (typeof inquiryStatuses)[number];
|
||||||
|
export type Inquiry = {
|
||||||
|
id: string;
|
||||||
|
intent: InquiryIntent;
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
company: string | null;
|
||||||
|
phone: string | null;
|
||||||
|
message: string | null;
|
||||||
|
payload: Record<string, unknown>;
|
||||||
|
status: InquiryStatus;
|
||||||
|
createdAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Stats = {
|
||||||
|
applications: Record<string, number>;
|
||||||
|
ticketsSold: number;
|
||||||
|
revenueMinor: number;
|
||||||
|
currency: string;
|
||||||
|
ordersPending: number;
|
||||||
|
inquiriesNew: number;
|
||||||
|
attendees: number;
|
||||||
|
scansToday: number;
|
||||||
|
scansTotal: number;
|
||||||
|
leaderboard: { name: string; email: string; points: number }[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Attendee = {
|
||||||
|
id: string;
|
||||||
|
email: string;
|
||||||
|
name: string | null;
|
||||||
|
role: Role;
|
||||||
|
points: number;
|
||||||
|
scans: number;
|
||||||
|
tickets: number;
|
||||||
|
createdAt: string;
|
||||||
|
};
|
||||||
14
src/lib/utils.check.ts
Normal file
14
src/lib/utils.check.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Run: pnpm check. Money crosses the wire as integer minor units; this guards the form conversions.
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { money, toDollars, toMinor } from './utils.ts';
|
||||||
|
|
||||||
|
assert.equal(toMinor('19.99'), 1999);
|
||||||
|
assert.equal(toMinor('0.1'), 10);
|
||||||
|
assert.equal(toMinor('1.005'), 101); // float noise rounds, never truncates to 100
|
||||||
|
assert.equal(toMinor('250'), 25000);
|
||||||
|
assert.equal(toMinor(''), null);
|
||||||
|
assert.equal(toMinor('abc'), null);
|
||||||
|
assert.equal(toDollars(1999), '19.99');
|
||||||
|
assert.equal(toDollars(null), '');
|
||||||
|
assert.equal(money(123450), '$1,234.50');
|
||||||
|
console.log('money ok');
|
||||||
52
src/lib/utils.ts
Normal file
52
src/lib/utils.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { clsx, type ClassValue } from 'clsx';
|
||||||
|
import { twMerge } from 'tailwind-merge';
|
||||||
|
|
||||||
|
export function cn(...inputs: ClassValue[]) {
|
||||||
|
return twMerge(clsx(inputs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Minor units (cents) → "$1,250.00". */
|
||||||
|
export function money(minor: number, currency = 'USD') {
|
||||||
|
return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(minor / 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Dollar string from a form → integer minor units. Empty/invalid → null. */
|
||||||
|
export function toMinor(dollars: string): number | null {
|
||||||
|
const s = dollars.trim();
|
||||||
|
// shift the decimal in the string ("1.005e2" = 100.5) so float noise in n * 100 can't round down
|
||||||
|
const n = Number(`${s}e2`);
|
||||||
|
return s === '' || !Number.isFinite(n) ? null : Math.round(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Minor units → plain dollar string for an <input>. */
|
||||||
|
export const toDollars = (minor: number | null | undefined) =>
|
||||||
|
minor === null || minor === undefined ? '' : (minor / 100).toFixed(2);
|
||||||
|
|
||||||
|
export function date(iso: string | null | undefined, withTime = false) {
|
||||||
|
if (!iso) return '—';
|
||||||
|
return new Date(iso).toLocaleString('en-GB', {
|
||||||
|
day: '2-digit',
|
||||||
|
month: 'short',
|
||||||
|
year: 'numeric',
|
||||||
|
...(withTime ? { hour: '2-digit', minute: '2-digit' } : {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "UNDER_REVIEW" → "Under review", "startup_referral" → "Startup referral". */
|
||||||
|
export function humanize(value: string) {
|
||||||
|
const s = value.replace(/_/g, ' ').toLowerCase();
|
||||||
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const errorMessage = (e: unknown) => (e instanceof Error ? e.message : 'Something went wrong');
|
||||||
|
|
||||||
|
/** Value that settles `ms` after the last change (search boxes). */
|
||||||
|
export function useDebounced<T>(value: T, ms = 300): T {
|
||||||
|
const [v, setV] = useState(value);
|
||||||
|
useEffect(() => {
|
||||||
|
const t = setTimeout(() => setV(value), ms);
|
||||||
|
return () => clearTimeout(t);
|
||||||
|
}, [value, ms]);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
27
src/main.tsx
Normal file
27
src/main.tsx
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
import { StrictMode } from 'react';
|
||||||
|
import { createRoot } from 'react-dom/client';
|
||||||
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||||
|
import { RouterProvider } from 'react-router';
|
||||||
|
import { Toaster } from 'sonner';
|
||||||
|
import { router } from './router';
|
||||||
|
import { ApiError } from './lib/api';
|
||||||
|
import './index.css';
|
||||||
|
|
||||||
|
const queryClient = new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: {
|
||||||
|
staleTime: 15_000,
|
||||||
|
// 4xx won't fix itself on retry
|
||||||
|
retry: (count, err) => !(err instanceof ApiError && err.status < 500) && count < 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
createRoot(document.getElementById('root')!).render(
|
||||||
|
<StrictMode>
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<RouterProvider router={router} />
|
||||||
|
<Toaster richColors position="top-right" />
|
||||||
|
</QueryClientProvider>
|
||||||
|
</StrictMode>,
|
||||||
|
);
|
||||||
206
src/pages/ApplicationDetail.tsx
Normal file
206
src/pages/ApplicationDetail.tsx
Normal file
|
|
@ -0,0 +1,206 @@
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Link, useParams } from 'react-router';
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { ArrowLeft } from 'lucide-react';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { QueryError, StatusBadge } from '@/components/common';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { SelectNative, Textarea } from '@/components/ui/input';
|
||||||
|
import { SkeletonRows } from '@/components/ui/skeleton';
|
||||||
|
import { api, getUser } from '@/lib/api';
|
||||||
|
import { applicationStatuses, type ApplicationDetail } from '@/lib/types';
|
||||||
|
import { cn, date, errorMessage, humanize } from '@/lib/utils';
|
||||||
|
|
||||||
|
const isUrl = (v: string) => /^https?:\/\/\S+$/.test(v);
|
||||||
|
|
||||||
|
export function ApplicationDetailPage() {
|
||||||
|
const { id = '' } = useParams();
|
||||||
|
const qc = useQueryClient();
|
||||||
|
const q = useQuery({ queryKey: ['application', id], queryFn: () => api<ApplicationDetail>(`/admin/applications/${id}`) });
|
||||||
|
const app = q.data;
|
||||||
|
const me = getUser()?.email;
|
||||||
|
const mine = app?.reviews.find((r) => r.reviewer === me);
|
||||||
|
|
||||||
|
const [status, setStatus] = useState('');
|
||||||
|
const [scores, setScores] = useState<Record<string, number>>({});
|
||||||
|
const [comment, setComment] = useState('');
|
||||||
|
useEffect(() => {
|
||||||
|
if (!app) return;
|
||||||
|
setStatus(app.status);
|
||||||
|
setScores(mine?.scores ?? {});
|
||||||
|
setComment(mine?.comment ?? '');
|
||||||
|
}, [app, mine]);
|
||||||
|
|
||||||
|
const refresh = () => {
|
||||||
|
qc.invalidateQueries({ queryKey: ['application', id] });
|
||||||
|
qc.invalidateQueries({ queryKey: ['applications'] });
|
||||||
|
};
|
||||||
|
const saveStatus = useMutation({
|
||||||
|
mutationFn: () => api('/admin/applications/status', { body: { ids: [id], status } }),
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success(`Status set to ${humanize(status)}`);
|
||||||
|
refresh();
|
||||||
|
},
|
||||||
|
onError: (e) => toast.error(errorMessage(e)),
|
||||||
|
});
|
||||||
|
const saveReview = useMutation({
|
||||||
|
mutationFn: () =>
|
||||||
|
api(`/admin/applications/${id}/review`, { method: 'PUT', body: { scores, comment: comment.trim() || undefined } }),
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success('Score saved');
|
||||||
|
refresh();
|
||||||
|
},
|
||||||
|
onError: (e) => toast.error(errorMessage(e)),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (q.error) return <QueryError error={q.error} retry={() => q.refetch()} />;
|
||||||
|
if (!app) return <SkeletonRows rows={8} />;
|
||||||
|
|
||||||
|
const editable = app.status !== 'DRAFT';
|
||||||
|
const average = app.reviews.length ? app.reviews.reduce((s, r) => s + r.total, 0) / app.reviews.length : null;
|
||||||
|
const complete = app.criteria.every((c) => scores[c.id]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mx-auto max-w-7xl">
|
||||||
|
<Link to="/applications" className="inline-flex items-center gap-1 text-sm text-primary hover:underline">
|
||||||
|
<ArrowLeft className="h-3.5 w-3.5" /> All applications
|
||||||
|
</Link>
|
||||||
|
<div className="mt-4 flex flex-wrap items-end justify-between gap-4">
|
||||||
|
<div>
|
||||||
|
<h1 className="font-display text-3xl font-bold md:text-4xl">{app.startupName ?? 'Untitled'}</h1>
|
||||||
|
<p className="mt-1 text-sm text-muted">
|
||||||
|
{app.founderName ? `${app.founderName} · ` : ''}
|
||||||
|
{app.email} · submitted {date(app.submittedAt, true)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{editable ? (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<StatusBadge status={app.status} />
|
||||||
|
<SelectNative aria-label="Status" className="w-44" value={status} onChange={(e) => setStatus(e.target.value)}>
|
||||||
|
{applicationStatuses.map((s) => (
|
||||||
|
<option key={s} value={s}>
|
||||||
|
{humanize(s)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</SelectNative>
|
||||||
|
<Button size="sm" disabled={status === app.status} loading={saveStatus.isPending} onClick={() => saveStatus.mutate()}>
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<StatusBadge status="DRAFT" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-8 grid gap-8 lg:grid-cols-[minmax(0,1fr)_360px]">
|
||||||
|
<div className="space-y-6">
|
||||||
|
{app.sections.map((section, i) => (
|
||||||
|
<section key={section.title} className="rounded-xl border border-primary/12 bg-surface p-5 md:p-6">
|
||||||
|
<h2 className="font-sans text-xs font-semibold uppercase tracking-widest text-primary">
|
||||||
|
{String(i + 1).padStart(2, '0')} · {section.title}
|
||||||
|
</h2>
|
||||||
|
<dl className="mt-4 grid gap-4 sm:grid-cols-2">
|
||||||
|
{section.fields.map((f) => (
|
||||||
|
<div key={f.label} className={cn(f.value.length > 80 && 'sm:col-span-2')}>
|
||||||
|
<dt className="text-xs text-muted">{f.label}</dt>
|
||||||
|
<dd className="mt-1 whitespace-pre-wrap text-sm">
|
||||||
|
{!f.value ? (
|
||||||
|
<span className="text-subtle">—</span>
|
||||||
|
) : isUrl(f.value) ? (
|
||||||
|
<a href={f.value} target="_blank" rel="noopener noreferrer nofollow" className="break-all text-primary underline underline-offset-4">
|
||||||
|
{f.value}
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
f.value
|
||||||
|
)}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</dl>
|
||||||
|
</section>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<aside className="space-y-6 lg:sticky lg:top-24 lg:self-start">
|
||||||
|
<div className="relative overflow-hidden rounded-xl bg-brand-tertiary p-5 text-white">
|
||||||
|
<img src="/patterns/main.svg" alt="" aria-hidden className="pattern-on-dark pointer-events-none absolute inset-0 h-full w-full object-cover" />
|
||||||
|
<div className="relative">
|
||||||
|
<p className="text-xs uppercase tracking-widest text-secondary">Average score</p>
|
||||||
|
<p className="mt-1 text-4xl font-bold tabular">{average?.toFixed(2) ?? '—'}</p>
|
||||||
|
<p className="text-sm text-white/70">
|
||||||
|
{app.reviews.length} review{app.reviews.length === 1 ? '' : 's'}
|
||||||
|
{app.reviews.length < 2 ? ' · needs at least two' : ''}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{editable ? (
|
||||||
|
<form
|
||||||
|
className="rounded-xl border border-primary/12 bg-surface p-5"
|
||||||
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
saveReview.mutate();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<h2 className="font-display text-lg font-semibold">{mine ? 'Update your score' : 'Score this application'}</h2>
|
||||||
|
<div className="mt-4 space-y-4">
|
||||||
|
{app.criteria.map((c) => (
|
||||||
|
<fieldset key={c.id}>
|
||||||
|
<legend className="text-sm">{c.label}</legend>
|
||||||
|
<div className="mt-1.5 grid grid-cols-5 gap-1.5">
|
||||||
|
{[1, 2, 3, 4, 5].map((n) => (
|
||||||
|
<label key={n} className="cursor-pointer">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name={c.id}
|
||||||
|
value={n}
|
||||||
|
checked={scores[c.id] === n}
|
||||||
|
onChange={() => setScores((s) => ({ ...s, [c.id]: n }))}
|
||||||
|
className="peer sr-only"
|
||||||
|
/>
|
||||||
|
<span className="flex h-9 items-center justify-center rounded-lg border border-primary/20 bg-surface text-sm font-semibold peer-checked:border-primary peer-checked:bg-primary peer-checked:text-white peer-focus-visible:ring-2 peer-focus-visible:ring-focus">
|
||||||
|
{n}
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
))}
|
||||||
|
<label className="block text-sm">
|
||||||
|
Comment
|
||||||
|
<Textarea className="mt-1.5" rows={3} maxLength={2000} value={comment} onChange={(e) => setComment(e.target.value)} />
|
||||||
|
</label>
|
||||||
|
<Button type="submit" fullWidth disabled={!complete} loading={saveReview.isPending}>
|
||||||
|
Save score
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{app.reviews.length ? (
|
||||||
|
<ul className="space-y-3">
|
||||||
|
{app.reviews.map((r) => (
|
||||||
|
<li key={r.reviewer} className="rounded-xl border border-primary/12 bg-surface p-4 text-sm">
|
||||||
|
<div className="flex justify-between gap-2">
|
||||||
|
<span className="truncate font-medium">{r.reviewer}</span>
|
||||||
|
<span className="font-semibold tabular">{r.total.toFixed(2)}</span>
|
||||||
|
</div>
|
||||||
|
<dl className="mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-xs text-muted">
|
||||||
|
{app.criteria.map((c) => (
|
||||||
|
<div key={c.id} className="flex justify-between gap-2">
|
||||||
|
<dt className="truncate">{c.label}</dt>
|
||||||
|
<dd className="tabular">{r.scores[c.id] ?? '—'}</dd>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</dl>
|
||||||
|
{r.comment ? <p className="mt-2 whitespace-pre-wrap text-muted">{r.comment}</p> : null}
|
||||||
|
<p className="mt-2 text-xs text-subtle">{date(r.updatedAt, true)}</p>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
) : null}
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
176
src/pages/Applications.tsx
Normal file
176
src/pages/Applications.tsx
Normal file
|
|
@ -0,0 +1,176 @@
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { Link, useSearchParams } from 'react-router';
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { Download } from 'lucide-react';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { PageShell } from '@/components/layout/AppLayout';
|
||||||
|
import { DataTable, type ColumnDef } from '@/components/DataTable';
|
||||||
|
import { QueryError, StatusBadge } from '@/components/common';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Input, SelectNative } from '@/components/ui/input';
|
||||||
|
import { api, download, qs } from '@/lib/api';
|
||||||
|
import { applicationStatuses, type ApplicationRow } from '@/lib/types';
|
||||||
|
import { date, errorMessage, humanize } from '@/lib/utils';
|
||||||
|
|
||||||
|
// Same option lists as the public apply form (GRVSummit/content/apply.ts); sectors come from the API.
|
||||||
|
const STAGES = ['Idea', 'Prototype/MVP', 'Early revenue', 'Growth'];
|
||||||
|
const CITIES = ['Addis Ababa', 'Adama', 'Bahir Dar', 'Hawassa', 'Mekelle', 'Dire Dawa', 'Other'];
|
||||||
|
const FILTERS = ['status', 'sector', 'stage', 'city', 'q'] as const;
|
||||||
|
|
||||||
|
const columns: ColumnDef<ApplicationRow>[] = [
|
||||||
|
{
|
||||||
|
id: 'startup',
|
||||||
|
header: 'Startup',
|
||||||
|
accessorFn: (r) => r.startupName ?? '',
|
||||||
|
cell: ({ row: { original: r } }) => (
|
||||||
|
<div>
|
||||||
|
<Link to={`/applications/${r.id}`} className="font-semibold underline-offset-4 hover:underline">
|
||||||
|
{r.startupName ?? 'Untitled'}
|
||||||
|
</Link>
|
||||||
|
<p className="text-xs text-muted">{r.founderName ?? r.email}</p>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ header: 'Sector', accessorFn: (r) => r.primarySector ?? '—' },
|
||||||
|
{ header: 'Stage', accessorFn: (r) => r.stage ?? '—' },
|
||||||
|
{ header: 'City', accessorFn: (r) => r.city ?? '—' },
|
||||||
|
{
|
||||||
|
id: 'submitted',
|
||||||
|
header: 'Submitted',
|
||||||
|
accessorFn: (r) => r.submittedAt ?? '',
|
||||||
|
cell: ({ row }) => <span className="whitespace-nowrap">{date(row.original.submittedAt)}</span>,
|
||||||
|
},
|
||||||
|
{ header: 'Status', accessorKey: 'status', cell: ({ row }) => <StatusBadge status={row.original.status} /> },
|
||||||
|
{
|
||||||
|
id: 'score',
|
||||||
|
header: 'Avg score',
|
||||||
|
accessorFn: (r) => r.avgScore ?? -1,
|
||||||
|
cell: ({ row: { original: r } }) =>
|
||||||
|
r.avgScore === null ? (
|
||||||
|
<span className="text-subtle">—</span>
|
||||||
|
) : (
|
||||||
|
<span className="tabular">
|
||||||
|
<span className="font-semibold">{r.avgScore.toFixed(2)}</span>
|
||||||
|
<span className={`ml-1 text-xs ${r.reviewCount < 2 ? 'text-warning' : 'text-muted'}`}>({r.reviewCount})</span>
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export function ApplicationsPage() {
|
||||||
|
const qc = useQueryClient();
|
||||||
|
const [params, setParams] = useSearchParams();
|
||||||
|
const filters = Object.fromEntries(FILTERS.map((k) => [k, params.get(k) ?? undefined]));
|
||||||
|
const [search, setSearch] = useState(filters.q ?? '');
|
||||||
|
const [selected, setSelected] = useState<Record<string, boolean>>({});
|
||||||
|
const [bulkStatus, setBulkStatus] = useState('');
|
||||||
|
|
||||||
|
const list = useQuery({
|
||||||
|
queryKey: ['applications', filters],
|
||||||
|
queryFn: () => api<ApplicationRow[]>(`/admin/applications${qs(filters)}`),
|
||||||
|
});
|
||||||
|
const sectors = useQuery({
|
||||||
|
queryKey: ['sectors'],
|
||||||
|
queryFn: () => api<{ sectors: string[] }>('/sectors'),
|
||||||
|
staleTime: Infinity,
|
||||||
|
});
|
||||||
|
|
||||||
|
const setFilter = (key: string, value: string) => {
|
||||||
|
const next = new URLSearchParams(params);
|
||||||
|
if (value) next.set(key, value);
|
||||||
|
else next.delete(key);
|
||||||
|
setParams(next, { replace: true });
|
||||||
|
setSelected({});
|
||||||
|
};
|
||||||
|
|
||||||
|
const ids = Object.keys(selected).filter((id) => selected[id]);
|
||||||
|
const bulk = useMutation({
|
||||||
|
mutationFn: () => api<{ updated: number }>('/admin/applications/status', { body: { ids, status: bulkStatus } }),
|
||||||
|
onSuccess: (r) => {
|
||||||
|
toast.success(`Updated ${r.updated} application${r.updated === 1 ? '' : 's'}`);
|
||||||
|
setSelected({});
|
||||||
|
qc.invalidateQueries({ queryKey: ['applications'] });
|
||||||
|
},
|
||||||
|
onError: (e) => toast.error(errorMessage(e)),
|
||||||
|
});
|
||||||
|
|
||||||
|
const selects = [
|
||||||
|
{ key: 'status', all: 'All submitted', options: ['DRAFT', ...applicationStatuses], label: humanize },
|
||||||
|
{ key: 'sector', all: 'All sectors', options: sectors.data?.sectors ?? [] },
|
||||||
|
{ key: 'stage', all: 'All stages', options: STAGES },
|
||||||
|
{ key: 'city', all: 'All cities', options: CITIES },
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageShell
|
||||||
|
title="Applications"
|
||||||
|
subtitle={list.data ? `${list.data.length} shown · amber count = fewer than two reviews` : 'Pitch competition review'}
|
||||||
|
actions={
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
onClick={() =>
|
||||||
|
download(`/admin/applications/export.csv${qs(filters)}`, 'grv-applications.csv').catch((e) => toast.error(errorMessage(e)))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Download /> Export CSV
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<form
|
||||||
|
className="grid gap-3 rounded-xl border border-primary/12 bg-surface p-4 sm:grid-cols-2 lg:grid-cols-[1.4fr_repeat(4,1fr)]"
|
||||||
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setFilter('q', search.trim());
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
aria-label="Search"
|
||||||
|
placeholder="Search startup, founder, email ↵"
|
||||||
|
value={search}
|
||||||
|
onChange={(e) => setSearch(e.target.value)}
|
||||||
|
onBlur={() => search.trim() !== (filters.q ?? '') && setFilter('q', search.trim())}
|
||||||
|
/>
|
||||||
|
{selects.map((s) => (
|
||||||
|
<SelectNative key={s.key} aria-label={s.key} value={filters[s.key] ?? ''} onChange={(e) => setFilter(s.key, e.target.value)}>
|
||||||
|
<option value="">{s.all}</option>
|
||||||
|
{s.options.map((o) => (
|
||||||
|
<option key={o} value={o}>
|
||||||
|
{s.label ? s.label(o) : o}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</SelectNative>
|
||||||
|
))}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{list.error ? <QueryError error={list.error} retry={() => list.refetch()} /> : null}
|
||||||
|
|
||||||
|
<div className="no-print flex flex-wrap items-center gap-3 text-sm">
|
||||||
|
<span className="text-muted">{ids.length} selected · set to</span>
|
||||||
|
<SelectNative aria-label="New status" className="w-48" value={bulkStatus} onChange={(e) => setBulkStatus(e.target.value)}>
|
||||||
|
<option value="" disabled>
|
||||||
|
Choose status
|
||||||
|
</option>
|
||||||
|
{applicationStatuses.map((s) => (
|
||||||
|
<option key={s} value={s}>
|
||||||
|
{humanize(s)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</SelectNative>
|
||||||
|
<Button size="sm" disabled={!ids.length || !bulkStatus} loading={bulk.isPending} onClick={() => bulk.mutate()}>
|
||||||
|
Update
|
||||||
|
</Button>
|
||||||
|
<span className="text-xs text-muted">Result emails go out for shortlisted, finalist, accepted and rejected.</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DataTable
|
||||||
|
data={list.data}
|
||||||
|
loading={list.isLoading}
|
||||||
|
columns={columns}
|
||||||
|
getRowId={(r) => r.id}
|
||||||
|
selection={[selected, setSelected]}
|
||||||
|
canSelect={(r) => r.status !== 'DRAFT'}
|
||||||
|
empty="No applications match these filters."
|
||||||
|
/>
|
||||||
|
</PageShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
44
src/pages/Attendees.tsx
Normal file
44
src/pages/Attendees.tsx
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { PageShell } from '@/components/layout/AppLayout';
|
||||||
|
import { DataTable, type ColumnDef } from '@/components/DataTable';
|
||||||
|
import { QueryError } from '@/components/common';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { api, qs } from '@/lib/api';
|
||||||
|
import type { Attendee } from '@/lib/types';
|
||||||
|
import { date, useDebounced } from '@/lib/utils';
|
||||||
|
|
||||||
|
const columns: ColumnDef<Attendee>[] = [
|
||||||
|
{
|
||||||
|
id: 'who',
|
||||||
|
header: 'Attendee',
|
||||||
|
accessorFn: (a) => a.name ?? a.email,
|
||||||
|
cell: ({ row: { original: a } }) => (
|
||||||
|
<div>
|
||||||
|
<p className="font-medium">
|
||||||
|
{a.name ?? '—'} {a.role !== 'ATTENDEE' ? <Badge tone="primary">{a.role}</Badge> : null}
|
||||||
|
</p>
|
||||||
|
<p className="text-xs text-muted">{a.email}</p>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ header: 'Points', accessorKey: 'points', cell: ({ row }) => <span className="font-semibold tabular">{row.original.points}</span> },
|
||||||
|
{ header: 'Scans', accessorKey: 'scans', cell: ({ row }) => <span className="tabular">{row.original.scans}</span> },
|
||||||
|
{ header: 'Tickets', accessorKey: 'tickets', cell: ({ row }) => <span className="tabular">{row.original.tickets}</span> },
|
||||||
|
{ id: 'joined', header: 'Joined', accessorKey: 'createdAt', cell: ({ row }) => <span className="whitespace-nowrap">{date(row.original.createdAt)}</span> },
|
||||||
|
];
|
||||||
|
|
||||||
|
export function AttendeesPage() {
|
||||||
|
const [q, setQ] = useState('');
|
||||||
|
const search = useDebounced(q.trim());
|
||||||
|
const list = useQuery({ queryKey: ['attendees', search], queryFn: () => api<Attendee[]>(`/admin/attendees${qs({ q: search })}`) });
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageShell title="Attendees" subtitle={list.data ? `${list.data.length} people signed in to the app` : 'Everyone signed in to the app'}>
|
||||||
|
<Input aria-label="Search" placeholder="Search name or email" className="max-w-xs" value={q} onChange={(e) => setQ(e.target.value)} />
|
||||||
|
{list.error ? <QueryError error={list.error} retry={() => list.refetch()} /> : null}
|
||||||
|
<DataTable data={list.data} loading={list.isLoading} columns={columns} getRowId={(a) => a.id} empty="No attendees match." />
|
||||||
|
</PageShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
258
src/pages/Checkpoints.tsx
Normal file
258
src/pages/Checkpoints.tsx
Normal file
|
|
@ -0,0 +1,258 @@
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { Link } from 'react-router';
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { Pencil, Plus, Printer, Trash2 } from 'lucide-react';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { PageShell } from '@/components/layout/AppLayout';
|
||||||
|
import { DataTable, type ColumnDef } from '@/components/DataTable';
|
||||||
|
import { ActiveBadge, AdminOnly, FormDialog, PatternEmpty, QrImage, QueryError, useSave } from '@/components/common';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Input, SelectNative } from '@/components/ui/input';
|
||||||
|
import { Field } from '@/components/ui/field';
|
||||||
|
import { SwitchRow } from '@/components/ui/switch';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { ConfirmDialog } from '@/components/ui/confirm-dialog';
|
||||||
|
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||||
|
import { api, qs } from '@/lib/api';
|
||||||
|
import type { Checkpoint, CheckpointKind } from '@/lib/types';
|
||||||
|
import { errorMessage } from '@/lib/utils';
|
||||||
|
|
||||||
|
export const kindLabel: Record<CheckpointKind, string> = {
|
||||||
|
BOOTH: 'Booth',
|
||||||
|
STARTUP_MEMBER: 'Startup member',
|
||||||
|
MYSTERY_INVESTEE: 'Mystery investee',
|
||||||
|
};
|
||||||
|
const defaultPoints: Record<CheckpointKind, number> = { BOOTH: 10, STARTUP_MEMBER: 20, MYSTERY_INVESTEE: 50 };
|
||||||
|
|
||||||
|
export const printUrl = (ids: string[]) => `/checkpoints/print?ids=${ids.join(',')}`;
|
||||||
|
|
||||||
|
export function useCheckpoints(kind?: string) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ['checkpoints', kind ?? ''],
|
||||||
|
queryFn: () => api<Checkpoint[]>(`/admin/checkpoints${qs({ kind })}`),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CheckpointsPage() {
|
||||||
|
const qc = useQueryClient();
|
||||||
|
const [kind, setKind] = useState('ALL');
|
||||||
|
const [selected, setSelected] = useState<Record<string, boolean>>({});
|
||||||
|
const [editing, setEditing] = useState<Checkpoint | 'new' | null>(null);
|
||||||
|
const [deleting, setDeleting] = useState<Checkpoint | null>(null);
|
||||||
|
const list = useCheckpoints(kind === 'ALL' ? undefined : kind);
|
||||||
|
const ids = Object.keys(selected).filter((id) => selected[id]);
|
||||||
|
|
||||||
|
const remove = useMutation({
|
||||||
|
mutationFn: (id: string) => api(`/admin/checkpoints/${id}`, { method: 'DELETE' }),
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success('Checkpoint deleted');
|
||||||
|
setDeleting(null);
|
||||||
|
qc.invalidateQueries({ queryKey: ['checkpoints'] });
|
||||||
|
},
|
||||||
|
onError: (e) => toast.error(errorMessage(e)),
|
||||||
|
});
|
||||||
|
|
||||||
|
const columns: ColumnDef<Checkpoint>[] = [
|
||||||
|
{
|
||||||
|
id: 'qr',
|
||||||
|
header: 'QR',
|
||||||
|
enableSorting: false,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<a href={row.original.qrUrl} target="_blank" rel="noreferrer" title={row.original.qrUrl}>
|
||||||
|
<QrImage value={row.original.qrUrl} size={56} />
|
||||||
|
</a>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'label',
|
||||||
|
header: 'Checkpoint',
|
||||||
|
accessorKey: 'label',
|
||||||
|
cell: ({ row: { original: c } }) => (
|
||||||
|
<div>
|
||||||
|
<p className="font-semibold">{c.personName ?? c.label}</p>
|
||||||
|
<p className="text-xs text-muted">
|
||||||
|
{[c.personName ? c.label : null, c.organisation !== c.label ? c.organisation : null, c.boothNumber ? `Booth ${c.boothNumber}` : null].filter(Boolean).join(' · ') || '—'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'kind',
|
||||||
|
header: 'Kind',
|
||||||
|
accessorKey: 'kind',
|
||||||
|
cell: ({ row }) => <Badge tone={row.original.kind === 'MYSTERY_INVESTEE' ? 'solid' : 'outline'}>{kindLabel[row.original.kind]}</Badge>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'points',
|
||||||
|
header: 'Points',
|
||||||
|
accessorKey: 'points',
|
||||||
|
cell: ({ row: { original: c } }) => (
|
||||||
|
<span className="tabular">
|
||||||
|
{c.points}
|
||||||
|
{c.kind === 'MYSTERY_INVESTEE' ? <span className="text-xs text-muted"> ×2 = {c.points * 2}</span> : null}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ id: 'active', header: 'Status', accessorKey: 'active', cell: ({ row }) => <ActiveBadge active={row.original.active} /> },
|
||||||
|
{
|
||||||
|
id: 'act',
|
||||||
|
enableSorting: false,
|
||||||
|
header: () => <span className="sr-only">Actions</span>,
|
||||||
|
cell: ({ row: { original: c } }) => (
|
||||||
|
<div className="flex justify-end gap-1">
|
||||||
|
<Button asChild variant="ghost" size="icon-sm" aria-label="Print card">
|
||||||
|
<Link to={printUrl([c.id])}>
|
||||||
|
<Printer />
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
<AdminOnly>
|
||||||
|
<Button variant="ghost" size="icon-sm" aria-label="Edit" onClick={() => setEditing(c)}>
|
||||||
|
<Pencil />
|
||||||
|
</Button>
|
||||||
|
<Button variant="ghost" size="icon-sm" aria-label="Delete" className="text-danger" onClick={() => setDeleting(c)}>
|
||||||
|
<Trash2 />
|
||||||
|
</Button>
|
||||||
|
</AdminOnly>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageShell
|
||||||
|
title="Checkpoints"
|
||||||
|
subtitle="QR codes attendees scan in the app for points: partner booths, startup team members and the mystery investee."
|
||||||
|
actions={
|
||||||
|
<>
|
||||||
|
<Button asChild variant="secondary" aria-disabled={!ids.length} className={ids.length ? '' : 'pointer-events-none opacity-40'}>
|
||||||
|
<Link to={printUrl(ids)}>
|
||||||
|
<Printer /> Print selected ({ids.length})
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
<AdminOnly>
|
||||||
|
<Button onClick={() => setEditing('new')}>
|
||||||
|
<Plus /> New checkpoint
|
||||||
|
</Button>
|
||||||
|
</AdminOnly>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Tabs
|
||||||
|
value={kind}
|
||||||
|
onValueChange={(k) => {
|
||||||
|
setKind(k);
|
||||||
|
setSelected({});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TabsList>
|
||||||
|
<TabsTrigger value="ALL">All</TabsTrigger>
|
||||||
|
{(Object.keys(kindLabel) as CheckpointKind[]).map((k) => (
|
||||||
|
<TabsTrigger key={k} value={k}>
|
||||||
|
{kindLabel[k]}
|
||||||
|
</TabsTrigger>
|
||||||
|
))}
|
||||||
|
</TabsList>
|
||||||
|
</Tabs>
|
||||||
|
{list.error ? <QueryError error={list.error} retry={() => list.refetch()} /> : null}
|
||||||
|
{list.data?.length === 0 ? (
|
||||||
|
<PatternEmpty title="No checkpoints yet" description="Create a booth, startup member or mystery investee checkpoint to generate its QR code." />
|
||||||
|
) : (
|
||||||
|
<DataTable data={list.data} loading={list.isLoading} columns={columns} getRowId={(c) => c.id} selection={[selected, setSelected]} />
|
||||||
|
)}
|
||||||
|
{editing ? <CheckpointDialog checkpoint={editing === 'new' ? null : editing} defaultKind={(kind === 'ALL' ? 'BOOTH' : kind) as CheckpointKind} onClose={() => setEditing(null)} /> : null}
|
||||||
|
<ConfirmDialog
|
||||||
|
open={!!deleting}
|
||||||
|
onOpenChange={(o) => !o && setDeleting(null)}
|
||||||
|
title={`Delete ${deleting?.personName ?? deleting?.label ?? ''}?`}
|
||||||
|
description="Its printed QR stops working. Points already earned from it stay counted."
|
||||||
|
confirmLabel="Delete checkpoint"
|
||||||
|
tone="danger"
|
||||||
|
loading={remove.isPending}
|
||||||
|
onConfirm={() => { if (deleting) remove.mutate(deleting.id); }}
|
||||||
|
/>
|
||||||
|
</PageShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CheckpointDialog({
|
||||||
|
checkpoint: c,
|
||||||
|
defaultKind,
|
||||||
|
defaultOrganisation,
|
||||||
|
onClose,
|
||||||
|
}: {
|
||||||
|
checkpoint: Checkpoint | null;
|
||||||
|
defaultKind: CheckpointKind;
|
||||||
|
defaultOrganisation?: string;
|
||||||
|
onClose: () => void;
|
||||||
|
}) {
|
||||||
|
const [f, setF] = useState({
|
||||||
|
kind: c?.kind ?? defaultKind,
|
||||||
|
label: c?.label ?? '',
|
||||||
|
organisation: c?.organisation ?? defaultOrganisation ?? '',
|
||||||
|
boothNumber: c?.boothNumber ?? '',
|
||||||
|
personName: c?.personName ?? '',
|
||||||
|
points: c?.points?.toString() ?? '',
|
||||||
|
active: c?.active ?? true,
|
||||||
|
});
|
||||||
|
const set = (k: keyof typeof f) => (e: { target: { value: string } }) => setF({ ...f, [k]: e.target.value });
|
||||||
|
const save = useSave('/admin/checkpoints', 'checkpoints', onClose);
|
||||||
|
const person = f.kind !== 'BOOTH';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormDialog
|
||||||
|
open
|
||||||
|
onOpenChange={(o) => !o && onClose()}
|
||||||
|
title={c ? 'Edit checkpoint' : 'New checkpoint'}
|
||||||
|
loading={save.isPending}
|
||||||
|
onSubmit={() =>
|
||||||
|
save.mutate({
|
||||||
|
id: c?.id,
|
||||||
|
body: {
|
||||||
|
...(c ? { active: f.active } : { kind: f.kind }),
|
||||||
|
label: f.label.trim(),
|
||||||
|
organisation: f.organisation.trim() || null,
|
||||||
|
boothNumber: f.kind === 'BOOTH' ? f.boothNumber.trim() || null : null,
|
||||||
|
personName: person ? f.personName.trim() || null : null,
|
||||||
|
...(f.points ? { points: Number(f.points) } : {}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Field label="Kind" hint={c ? 'Kind is fixed once created.' : undefined}>
|
||||||
|
<SelectNative disabled={!!c} value={f.kind} onChange={set('kind')}>
|
||||||
|
{(Object.keys(kindLabel) as CheckpointKind[]).map((k) => (
|
||||||
|
<option key={k} value={k}>
|
||||||
|
{kindLabel[k]}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</SelectNative>
|
||||||
|
</Field>
|
||||||
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
|
{person ? (
|
||||||
|
<Field label="Person name">
|
||||||
|
<Input required value={f.personName} onChange={set('personName')} />
|
||||||
|
</Field>
|
||||||
|
) : null}
|
||||||
|
<Field label={person ? 'Role' : 'Booth / partner name'} hint={person ? 'e.g. Co-founder, Partner at …' : undefined}>
|
||||||
|
<Input required value={f.label} onChange={set('label')} />
|
||||||
|
</Field>
|
||||||
|
<Field label={f.kind === 'STARTUP_MEMBER' ? 'Startup' : 'Organisation'} optional={f.kind !== 'STARTUP_MEMBER'}>
|
||||||
|
<Input required={f.kind === 'STARTUP_MEMBER'} value={f.organisation} onChange={set('organisation')} />
|
||||||
|
</Field>
|
||||||
|
{f.kind === 'BOOTH' ? (
|
||||||
|
<Field label="Booth number" optional>
|
||||||
|
<Input value={f.boothNumber} onChange={set('boothNumber')} />
|
||||||
|
</Field>
|
||||||
|
) : null}
|
||||||
|
<Field
|
||||||
|
label="Points"
|
||||||
|
optional
|
||||||
|
hint={f.kind === 'MYSTERY_INVESTEE' ? `Default ${defaultPoints[f.kind]}; finding the mystery investee awards double.` : `Default ${defaultPoints[f.kind]}`}
|
||||||
|
>
|
||||||
|
<Input type="number" min="0" step="1" placeholder={String(defaultPoints[f.kind])} value={f.points} onChange={set('points')} />
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
{c ? <SwitchRow label="Active" description="Inactive codes stop awarding points" checked={f.active} onCheckedChange={(active) => setF({ ...f, active })} /> : null}
|
||||||
|
</FormDialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
102
src/pages/CheckpointsPrint.tsx
Normal file
102
src/pages/CheckpointsPrint.tsx
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
import { Link, Navigate, useNavigate, useSearchParams } from 'react-router';
|
||||||
|
import { ArrowLeft, Printer } from 'lucide-react';
|
||||||
|
import { QrImage, QueryError } from '@/components/common';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { SkeletonRows } from '@/components/ui/skeleton';
|
||||||
|
import { getToken } from '@/lib/api';
|
||||||
|
import type { Checkpoint } from '@/lib/types';
|
||||||
|
import { useCheckpoints } from './Checkpoints';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A6 cards, one per page: `/checkpoints/print?ids=a,b,c`. Rendered outside the app shell so only
|
||||||
|
* the cards print. On A4 paper pick "4 pages per sheet" in the print dialog and cut.
|
||||||
|
*/
|
||||||
|
export function CheckpointsPrintPage() {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [params] = useSearchParams();
|
||||||
|
const ids = (params.get('ids') ?? '').split(',').filter(Boolean);
|
||||||
|
const list = useCheckpoints();
|
||||||
|
if (!getToken()) return <Navigate to="/login" replace />;
|
||||||
|
|
||||||
|
const cards = ids.map((id) => list.data?.find((c) => c.id === id)).filter((c): c is Checkpoint => !!c);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-canvas print:bg-white">
|
||||||
|
<style>{`
|
||||||
|
@page { size: A6 portrait; margin: 0; }
|
||||||
|
@media print {
|
||||||
|
.a6-card { box-shadow: none !important; border: none !important; margin: 0 !important; break-after: page; }
|
||||||
|
.a6-card:last-child { break-after: auto; }
|
||||||
|
.a6-grid { display: block !important; padding: 0 !important; }
|
||||||
|
}
|
||||||
|
`}</style>
|
||||||
|
<div className="no-print sticky top-0 z-10 flex items-center gap-3 border-b border-border bg-surface px-4 py-3">
|
||||||
|
<Button variant="ghost" size="sm" onClick={() => (history.length > 1 ? navigate(-1) : navigate('/checkpoints'))}>
|
||||||
|
<ArrowLeft /> Back
|
||||||
|
</Button>
|
||||||
|
<p className="text-sm text-muted">
|
||||||
|
{cards.length} card{cards.length === 1 ? '' : 's'} · A6 (105 × 148 mm)
|
||||||
|
</p>
|
||||||
|
<Button className="ml-auto" disabled={!cards.length} onClick={() => window.print()}>
|
||||||
|
<Printer /> Print
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{list.error ? (
|
||||||
|
<div className="p-6">
|
||||||
|
<QueryError error={list.error} retry={() => list.refetch()} />
|
||||||
|
</div>
|
||||||
|
) : list.isLoading ? (
|
||||||
|
<div className="p-6">
|
||||||
|
<SkeletonRows />
|
||||||
|
</div>
|
||||||
|
) : cards.length === 0 ? (
|
||||||
|
<p className="p-10 text-center text-muted">
|
||||||
|
Nothing to print. Pick checkpoints on the <Link to="/checkpoints" className="text-primary underline">Checkpoints</Link> page.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<div className="a6-grid flex flex-wrap justify-center gap-6 p-6">
|
||||||
|
{cards.map((c) => (
|
||||||
|
<PrintCard key={c.id} c={c} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function PrintCard({ c }: { c: Checkpoint }) {
|
||||||
|
const mystery = c.kind === 'MYSTERY_INVESTEE';
|
||||||
|
const title = mystery ? '?' : (c.personName ?? c.label);
|
||||||
|
const lines = mystery
|
||||||
|
? []
|
||||||
|
: c.kind === 'STARTUP_MEMBER'
|
||||||
|
? [c.label, c.organisation]
|
||||||
|
: [c.organisation !== c.label ? c.organisation : null, c.boothNumber ? `Booth ${c.boothNumber}` : null];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section
|
||||||
|
className="a6-card flex flex-col items-center overflow-hidden rounded-xl border border-primary/15 bg-white text-center text-brand-tertiary shadow-card"
|
||||||
|
style={{ width: '105mm', height: '148mm', padding: '9mm 8mm 8mm' }}
|
||||||
|
>
|
||||||
|
<img src="/GRVLogo.png" alt="GRV Summit" style={{ height: '14mm' }} className="object-contain" />
|
||||||
|
<div className="flex min-h-0 flex-1 flex-col items-center justify-center" style={{ gap: '2mm' }}>
|
||||||
|
<h2
|
||||||
|
className="font-display font-bold leading-tight"
|
||||||
|
style={{ fontSize: mystery ? '30mm' : title.length > 22 ? '7mm' : '9mm' }}
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</h2>
|
||||||
|
{lines.filter(Boolean).map((l) => (
|
||||||
|
<p key={l} className="font-medium text-primary" style={{ fontSize: '4.2mm' }}>
|
||||||
|
{l}
|
||||||
|
</p>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<QrImage value={c.qrUrl} size={240} className="h-auto" />
|
||||||
|
<p className="font-semibold uppercase tracking-widest text-primary" style={{ fontSize: '3.2mm', marginTop: '3mm' }}>
|
||||||
|
Scan with the GRV Summit app
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
90
src/pages/Dashboard.tsx
Normal file
90
src/pages/Dashboard.tsx
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { Link } from 'react-router';
|
||||||
|
import { Banknote, Inbox, ScanLine, ShoppingCart, Ticket, Users } from 'lucide-react';
|
||||||
|
import { PageShell } from '@/components/layout/AppLayout';
|
||||||
|
import { QueryError, StatCard, StatusBadge } from '@/components/common';
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import { SkeletonRows } from '@/components/ui/skeleton';
|
||||||
|
import { api } from '@/lib/api';
|
||||||
|
import { applicationStatuses, type Stats } from '@/lib/types';
|
||||||
|
import { money } from '@/lib/utils';
|
||||||
|
|
||||||
|
export function DashboardPage() {
|
||||||
|
const q = useQuery({ queryKey: ['stats'], queryFn: () => api<Stats>('/admin/stats'), refetchInterval: 30_000 });
|
||||||
|
const s = q.data;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageShell title="Dashboard" subtitle="Live numbers, refreshed every 30 seconds.">
|
||||||
|
{q.error ? <QueryError error={q.error} retry={() => q.refetch()} /> : null}
|
||||||
|
{!s ? (
|
||||||
|
q.isLoading ? <SkeletonRows rows={4} /> : null
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
||||||
|
<StatCard label="Tickets sold" value={s.ticketsSold.toLocaleString()} icon={Ticket} />
|
||||||
|
<StatCard label="Revenue" value={money(s.revenueMinor, s.currency)} icon={Banknote} />
|
||||||
|
<StatCard
|
||||||
|
label="Pending orders"
|
||||||
|
value={<Link to="/orders" className="hover:underline">{s.ordersPending}</Link>}
|
||||||
|
hint="Awaiting payment"
|
||||||
|
icon={ShoppingCart}
|
||||||
|
/>
|
||||||
|
<StatCard
|
||||||
|
label="New inquiries"
|
||||||
|
value={<Link to="/inquiries" className="hover:underline">{s.inquiriesNew}</Link>}
|
||||||
|
icon={Inbox}
|
||||||
|
/>
|
||||||
|
<StatCard label="Attendees" value={s.attendees.toLocaleString()} icon={Users} />
|
||||||
|
<StatCard label="Scans today" value={s.scansToday.toLocaleString()} hint={`${s.scansTotal.toLocaleString()} total`} icon={ScanLine} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-4 lg:grid-cols-2">
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Applications by status</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<ul className="divide-y divide-border">
|
||||||
|
{[...applicationStatuses, ...Object.keys(s.applications).filter((k) => !(applicationStatuses as readonly string[]).includes(k))].map((status) => (
|
||||||
|
<li key={status} className="flex items-center justify-between py-2.5">
|
||||||
|
<Link to={`/applications?status=${status}`} className="hover:underline">
|
||||||
|
<StatusBadge status={status} />
|
||||||
|
</Link>
|
||||||
|
<span className="font-semibold tabular">{s.applications[status] ?? 0}</span>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Leaderboard · top 10</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
{s.leaderboard.length === 0 ? (
|
||||||
|
<p className="py-6 text-center text-sm text-muted">No scans yet.</p>
|
||||||
|
) : (
|
||||||
|
<ol className="divide-y divide-border">
|
||||||
|
{s.leaderboard.slice(0, 10).map((p, i) => (
|
||||||
|
<li key={p.email} className="flex items-center gap-3 py-2.5">
|
||||||
|
<span className="flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-surface-muted text-xs font-bold text-primary tabular">
|
||||||
|
{i + 1}
|
||||||
|
</span>
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<p className="truncate text-sm font-medium">{p.name || p.email}</p>
|
||||||
|
{p.name ? <p className="truncate text-xs text-muted">{p.email}</p> : null}
|
||||||
|
</div>
|
||||||
|
<span className="font-semibold tabular">{p.points} pts</span>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ol>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</PageShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
157
src/pages/Discounts.tsx
Normal file
157
src/pages/Discounts.tsx
Normal file
|
|
@ -0,0 +1,157 @@
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { Pencil, Plus } from 'lucide-react';
|
||||||
|
import { PageShell } from '@/components/layout/AppLayout';
|
||||||
|
import { DataTable, type ColumnDef } from '@/components/DataTable';
|
||||||
|
import { ActiveBadge, AdminOnly, FormDialog, QueryError, useSave } from '@/components/common';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Input, SelectNative } from '@/components/ui/input';
|
||||||
|
import { Field } from '@/components/ui/field';
|
||||||
|
import { SwitchRow } from '@/components/ui/switch';
|
||||||
|
import { api } from '@/lib/api';
|
||||||
|
import type { Discount, Tier } from '@/lib/types';
|
||||||
|
import { date, money, toDollars, toMinor } from '@/lib/utils';
|
||||||
|
|
||||||
|
/** ISO → value for <input type="datetime-local"> (local time). */
|
||||||
|
const toLocalInput = (iso: string | null) => {
|
||||||
|
if (!iso) return '';
|
||||||
|
const d = new Date(iso);
|
||||||
|
return new Date(d.getTime() - d.getTimezoneOffset() * 60_000).toISOString().slice(0, 16);
|
||||||
|
};
|
||||||
|
const fromLocalInput = (v: string) => (v ? new Date(v).toISOString() : null);
|
||||||
|
|
||||||
|
export function DiscountsPage() {
|
||||||
|
const [editing, setEditing] = useState<Discount | 'new' | null>(null);
|
||||||
|
const list = useQuery({ queryKey: ['discounts'], queryFn: () => api<Discount[]>('/admin/discounts') });
|
||||||
|
|
||||||
|
const columns: ColumnDef<Discount>[] = [
|
||||||
|
{ header: 'Code', accessorKey: 'code', cell: ({ row }) => <span className="font-mono font-semibold">{row.original.code}</span> },
|
||||||
|
{
|
||||||
|
id: 'off',
|
||||||
|
header: 'Off',
|
||||||
|
accessorFn: (d) => d.percentOff ?? d.amountOffMinor,
|
||||||
|
cell: ({ row: { original: d } }) => (d.percentOff !== null ? `${d.percentOff}%` : money(d.amountOffMinor ?? 0)),
|
||||||
|
},
|
||||||
|
{ header: 'Tier', accessorFn: (d) => d.tierName ?? 'All tiers' },
|
||||||
|
{ id: 'uses', header: 'Uses', accessorKey: 'uses', cell: ({ row: { original: d } }) => <span className="tabular">{d.uses}{d.maxUses !== null ? ` / ${d.maxUses}` : ''}</span> },
|
||||||
|
{
|
||||||
|
id: 'window',
|
||||||
|
header: 'Valid',
|
||||||
|
enableSorting: false,
|
||||||
|
cell: ({ row: { original: d } }) => (
|
||||||
|
<span className="whitespace-nowrap text-xs text-muted">
|
||||||
|
{d.startsAt || d.endsAt ? `${date(d.startsAt)} → ${date(d.endsAt)}` : 'Always'}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ id: 'active', header: 'Status', accessorKey: 'active', cell: ({ row }) => <ActiveBadge active={row.original.active} /> },
|
||||||
|
{
|
||||||
|
id: 'edit',
|
||||||
|
enableSorting: false,
|
||||||
|
header: () => <span className="sr-only">Edit</span>,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<AdminOnly>
|
||||||
|
<Button variant="ghost" size="icon-sm" aria-label={`Edit ${row.original.code}`} onClick={() => setEditing(row.original)}>
|
||||||
|
<Pencil />
|
||||||
|
</Button>
|
||||||
|
</AdminOnly>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageShell
|
||||||
|
title="Discount codes"
|
||||||
|
subtitle="Applied at ticket checkout."
|
||||||
|
actions={
|
||||||
|
<AdminOnly>
|
||||||
|
<Button onClick={() => setEditing('new')}>
|
||||||
|
<Plus /> New code
|
||||||
|
</Button>
|
||||||
|
</AdminOnly>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{list.error ? <QueryError error={list.error} retry={() => list.refetch()} /> : null}
|
||||||
|
<DataTable data={list.data} loading={list.isLoading} columns={columns} getRowId={(d) => d.id} empty="No discount codes yet." />
|
||||||
|
{editing ? <DiscountDialog discount={editing === 'new' ? null : editing} onClose={() => setEditing(null)} /> : null}
|
||||||
|
</PageShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DiscountDialog({ discount: d, onClose }: { discount: Discount | null; onClose: () => void }) {
|
||||||
|
const tiers = useQuery({ queryKey: ['tiers'], queryFn: () => api<Tier[]>('/admin/tiers') });
|
||||||
|
const [f, setF] = useState({
|
||||||
|
code: d?.code ?? '',
|
||||||
|
type: d?.amountOffMinor != null ? 'amount' : 'percent',
|
||||||
|
value: d?.amountOffMinor != null ? toDollars(d.amountOffMinor) : (d?.percentOff?.toString() ?? ''),
|
||||||
|
tierId: d?.tierId ?? '',
|
||||||
|
maxUses: d?.maxUses?.toString() ?? '',
|
||||||
|
startsAt: toLocalInput(d?.startsAt ?? null),
|
||||||
|
endsAt: toLocalInput(d?.endsAt ?? null),
|
||||||
|
active: d?.active ?? true,
|
||||||
|
});
|
||||||
|
const set = (k: keyof typeof f) => (e: { target: { value: string } }) => setF({ ...f, [k]: e.target.value });
|
||||||
|
const save = useSave('/admin/discounts', 'discounts', onClose);
|
||||||
|
const percent = f.type === 'percent';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormDialog
|
||||||
|
open
|
||||||
|
onOpenChange={(o) => !o && onClose()}
|
||||||
|
title={d ? `Edit ${d.code}` : 'New discount code'}
|
||||||
|
loading={save.isPending}
|
||||||
|
onSubmit={() =>
|
||||||
|
save.mutate({
|
||||||
|
id: d?.id,
|
||||||
|
body: {
|
||||||
|
code: f.code.trim().toUpperCase(),
|
||||||
|
// exactly one of the two; the other is cleared so a type switch on edit sticks
|
||||||
|
percentOff: percent ? Number(f.value) : null,
|
||||||
|
amountOffMinor: percent ? null : toMinor(f.value),
|
||||||
|
tierId: f.tierId || null,
|
||||||
|
maxUses: f.maxUses ? Number(f.maxUses) : null,
|
||||||
|
startsAt: fromLocalInput(f.startsAt),
|
||||||
|
endsAt: fromLocalInput(f.endsAt),
|
||||||
|
active: f.active,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
|
<Field label="Code">
|
||||||
|
<Input required className="font-mono uppercase" value={f.code} onChange={set('code')} />
|
||||||
|
</Field>
|
||||||
|
<Field label="Applies to">
|
||||||
|
<SelectNative value={f.tierId} onChange={set('tierId')}>
|
||||||
|
<option value="">All tiers</option>
|
||||||
|
{tiers.data?.map((t) => (
|
||||||
|
<option key={t.id} value={t.id}>
|
||||||
|
{t.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</SelectNative>
|
||||||
|
</Field>
|
||||||
|
<Field label="Discount type">
|
||||||
|
<SelectNative value={f.type} onChange={(e) => setF({ ...f, type: e.target.value, value: '' })}>
|
||||||
|
<option value="percent">Percent off</option>
|
||||||
|
<option value="amount">Fixed amount off</option>
|
||||||
|
</SelectNative>
|
||||||
|
</Field>
|
||||||
|
<Field label={percent ? 'Percent (1–100)' : 'Amount (USD)'}>
|
||||||
|
<Input required type="number" min={percent ? 1 : 0.01} max={percent ? 100 : undefined} step={percent ? 1 : 0.01} value={f.value} onChange={set('value')} />
|
||||||
|
</Field>
|
||||||
|
<Field label="Max uses" optional hint="Empty = unlimited">
|
||||||
|
<Input type="number" min="1" step="1" value={f.maxUses} onChange={set('maxUses')} />
|
||||||
|
</Field>
|
||||||
|
<div />
|
||||||
|
<Field label="Starts" optional>
|
||||||
|
<Input type="datetime-local" value={f.startsAt} onChange={set('startsAt')} />
|
||||||
|
</Field>
|
||||||
|
<Field label="Ends" optional>
|
||||||
|
<Input type="datetime-local" value={f.endsAt} onChange={set('endsAt')} />
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
<SwitchRow label="Active" checked={f.active} onCheckedChange={(active) => setF({ ...f, active })} />
|
||||||
|
</FormDialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
146
src/pages/Inquiries.tsx
Normal file
146
src/pages/Inquiries.tsx
Normal file
|
|
@ -0,0 +1,146 @@
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { ChevronDown, ChevronRight } from 'lucide-react';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { PageShell } from '@/components/layout/AppLayout';
|
||||||
|
import { DataTable, type ColumnDef } from '@/components/DataTable';
|
||||||
|
import { QueryError } from '@/components/common';
|
||||||
|
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||||
|
import { Input, SelectNative } from '@/components/ui/input';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { api, qs } from '@/lib/api';
|
||||||
|
import { inquiryIntents, inquiryStatuses, type Inquiry, type InquiryStatus } from '@/lib/types';
|
||||||
|
import { date, errorMessage, humanize, useDebounced } from '@/lib/utils';
|
||||||
|
|
||||||
|
export function InquiriesPage() {
|
||||||
|
const qc = useQueryClient();
|
||||||
|
const [intent, setIntent] = useState<string>(inquiryIntents[0]);
|
||||||
|
const [status, setStatus] = useState('');
|
||||||
|
const [q, setQ] = useState('');
|
||||||
|
const [open, setOpen] = useState<Record<string, boolean>>({});
|
||||||
|
|
||||||
|
const search = useDebounced(q.trim());
|
||||||
|
const filters = { intent, status, q: search };
|
||||||
|
const list = useQuery({ queryKey: ['inquiries', filters], queryFn: () => api<Inquiry[]>(`/admin/inquiries${qs(filters)}`) });
|
||||||
|
|
||||||
|
const update = useMutation({
|
||||||
|
mutationFn: (v: { id: string; status: InquiryStatus }) => api(`/admin/inquiries/${v.id}`, { method: 'PATCH', body: { status: v.status } }),
|
||||||
|
onSuccess: () => {
|
||||||
|
qc.invalidateQueries({ queryKey: ['inquiries'] });
|
||||||
|
qc.invalidateQueries({ queryKey: ['stats'] });
|
||||||
|
},
|
||||||
|
onError: (e) => toast.error(errorMessage(e)),
|
||||||
|
});
|
||||||
|
|
||||||
|
const columns: ColumnDef<Inquiry>[] = [
|
||||||
|
{
|
||||||
|
id: 'expand',
|
||||||
|
enableSorting: false,
|
||||||
|
header: () => <span className="sr-only">Details</span>,
|
||||||
|
cell: ({ row: { original: r } }) => (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon-sm"
|
||||||
|
aria-label={open[r.id] ? 'Hide details' : 'Show details'}
|
||||||
|
aria-expanded={!!open[r.id]}
|
||||||
|
onClick={() => setOpen((o) => ({ ...o, [r.id]: !o[r.id] }))}
|
||||||
|
>
|
||||||
|
{open[r.id] ? <ChevronDown /> : <ChevronRight />}
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'from',
|
||||||
|
header: 'From',
|
||||||
|
accessorFn: (r) => r.name,
|
||||||
|
cell: ({ row: { original: r } }) => (
|
||||||
|
<div>
|
||||||
|
<p className="font-medium">{r.name}</p>
|
||||||
|
<a href={`mailto:${r.email}`} className="text-xs text-primary hover:underline">
|
||||||
|
{r.email}
|
||||||
|
</a>
|
||||||
|
{r.phone ? <p className="text-xs text-muted">{r.phone}</p> : null}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ header: 'Company', accessorFn: (r) => r.company ?? '—' },
|
||||||
|
{
|
||||||
|
id: 'message',
|
||||||
|
header: 'Message',
|
||||||
|
enableSorting: false,
|
||||||
|
cell: ({ row }) => <p className="line-clamp-2 max-w-md text-muted">{row.original.message || '—'}</p>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'received',
|
||||||
|
header: 'Received',
|
||||||
|
accessorKey: 'createdAt',
|
||||||
|
cell: ({ row }) => <span className="whitespace-nowrap">{date(row.original.createdAt, true)}</span>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'Status',
|
||||||
|
accessorKey: 'status',
|
||||||
|
cell: ({ row: { original: r } }) => (
|
||||||
|
<SelectNative
|
||||||
|
aria-label="Status"
|
||||||
|
className="h-9 w-32"
|
||||||
|
value={r.status}
|
||||||
|
onChange={(e) => update.mutate({ id: r.id, status: e.target.value as InquiryStatus })}
|
||||||
|
>
|
||||||
|
{inquiryStatuses.map((s) => (
|
||||||
|
<option key={s} value={s}>
|
||||||
|
{humanize(s)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</SelectNative>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageShell title="Inquiries" subtitle="Everything sent through the site's contact, partner, press and newsletter forms.">
|
||||||
|
<Tabs value={intent} onValueChange={setIntent}>
|
||||||
|
<TabsList>
|
||||||
|
{inquiryIntents.map((i) => (
|
||||||
|
<TabsTrigger key={i} value={i}>
|
||||||
|
{humanize(i)}
|
||||||
|
</TabsTrigger>
|
||||||
|
))}
|
||||||
|
</TabsList>
|
||||||
|
</Tabs>
|
||||||
|
<div className="flex flex-wrap gap-3">
|
||||||
|
<Input aria-label="Search" placeholder="Search name, email, company" className="max-w-xs" value={q} onChange={(e) => setQ(e.target.value)} />
|
||||||
|
<SelectNative aria-label="Status filter" className="w-40" value={status} onChange={(e) => setStatus(e.target.value)}>
|
||||||
|
<option value="">All statuses</option>
|
||||||
|
{inquiryStatuses.map((s) => (
|
||||||
|
<option key={s} value={s}>
|
||||||
|
{humanize(s)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</SelectNative>
|
||||||
|
</div>
|
||||||
|
{list.error ? <QueryError error={list.error} retry={() => list.refetch()} /> : null}
|
||||||
|
<DataTable
|
||||||
|
data={list.data}
|
||||||
|
loading={list.isLoading}
|
||||||
|
columns={columns}
|
||||||
|
getRowId={(r) => r.id}
|
||||||
|
empty={`No ${humanize(intent).toLowerCase()} inquiries.`}
|
||||||
|
renderExpanded={(r) =>
|
||||||
|
open[r.id] ? (
|
||||||
|
<div className="space-y-3 text-sm">
|
||||||
|
{r.message ? <p className="whitespace-pre-wrap">{r.message}</p> : null}
|
||||||
|
<dl className="grid gap-x-6 gap-y-2 sm:grid-cols-2 lg:grid-cols-3">
|
||||||
|
{Object.entries(r.payload ?? {}).map(([k, v]) => (
|
||||||
|
<div key={k}>
|
||||||
|
<dt className="text-xs text-muted">{k}</dt>
|
||||||
|
<dd className="break-words">{typeof v === 'string' ? v : JSON.stringify(v)}</dd>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</PageShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
132
src/pages/Login.tsx
Normal file
132
src/pages/Login.tsx
Normal file
|
|
@ -0,0 +1,132 @@
|
||||||
|
import { useState, type FormEvent } from 'react';
|
||||||
|
import { Navigate, useNavigate } from 'react-router';
|
||||||
|
import { ArrowLeft } from 'lucide-react';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { Field } from '@/components/ui/field';
|
||||||
|
import { api, ApiError, getToken, getUser, saveSession } from '@/lib/api';
|
||||||
|
import type { User } from '@/lib/types';
|
||||||
|
import { errorMessage } from '@/lib/utils';
|
||||||
|
|
||||||
|
export function LoginPage() {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [step, setStep] = useState<'email' | 'code'>('email');
|
||||||
|
const [email, setEmail] = useState('');
|
||||||
|
const [code, setCode] = useState('');
|
||||||
|
const [busy, setBusy] = useState(false);
|
||||||
|
const [error, setError] = useState<string>();
|
||||||
|
|
||||||
|
const user = getUser();
|
||||||
|
if (getToken() && user && user.role !== 'ATTENDEE') return <Navigate to="/" replace />;
|
||||||
|
|
||||||
|
async function requestCode(e?: FormEvent) {
|
||||||
|
e?.preventDefault();
|
||||||
|
setBusy(true);
|
||||||
|
setError(undefined);
|
||||||
|
try {
|
||||||
|
await api('/auth/otp/request', { body: { email: email.trim() } });
|
||||||
|
setStep('code');
|
||||||
|
setCode('');
|
||||||
|
} catch (err) {
|
||||||
|
setError(errorMessage(err));
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function verify(e: FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
setBusy(true);
|
||||||
|
setError(undefined);
|
||||||
|
try {
|
||||||
|
const res = await api<{ accessToken: string; user: User }>('/auth/otp/verify', {
|
||||||
|
body: { email: email.trim(), code },
|
||||||
|
});
|
||||||
|
if (res.user.role === 'ATTENDEE') {
|
||||||
|
setError(`${res.user.email} is not on the staff list. Ask an admin to add you, or use the GRV Summit app.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
saveSession(res.accessToken, res.user);
|
||||||
|
navigate('/', { replace: true });
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof ApiError && err.code === 'invalid_code' ? 'That code is wrong or expired.' : errorMessage(err));
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="grid min-h-screen lg:grid-cols-2">
|
||||||
|
<div className="relative hidden overflow-hidden bg-primary text-white lg:flex lg:flex-col lg:justify-between lg:p-12">
|
||||||
|
<img src="/patterns/main.svg" alt="" aria-hidden className="pattern-on-dark pointer-events-none absolute inset-0 h-full w-full object-cover" />
|
||||||
|
<div className="relative flex items-center gap-3">
|
||||||
|
<span className="rounded-xl bg-white px-3 py-2">
|
||||||
|
<img src="/GRVLogo.png" alt="GRV Summit" className="h-10 w-auto" />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="relative">
|
||||||
|
<p className="text-xs font-semibold uppercase tracking-widest text-secondary">Staff portal</p>
|
||||||
|
<h1 className="mt-3 max-w-md font-display text-5xl font-bold leading-tight">Run the summit from one place</h1>
|
||||||
|
<p className="mt-4 max-w-md text-white/80">Applications, tickets, check-in, QR checkpoints and raffles.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="relative flex items-center justify-center overflow-hidden px-4 py-12">
|
||||||
|
<img src="/patterns/mainwhite.svg" alt="" aria-hidden className="pattern-on-light pointer-events-none absolute inset-0 h-full w-full object-cover lg:hidden" />
|
||||||
|
<div className="relative w-full max-w-sm rounded-2xl border border-primary/12 bg-surface p-7 shadow-pop">
|
||||||
|
<img src="/GRVLogo.png" alt="GRV Summit" className="mb-5 h-10 w-auto lg:hidden" />
|
||||||
|
<h2 className="font-display text-2xl font-bold">Sign in</h2>
|
||||||
|
<p className="mt-1 text-sm text-muted">
|
||||||
|
{step === 'email' ? 'We will email you a 6-digit code.' : `Enter the code sent to ${email}.`}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{step === 'email' ? (
|
||||||
|
<form onSubmit={requestCode} className="mt-6 space-y-4">
|
||||||
|
<Field label="Work email">
|
||||||
|
<Input type="email" required autoFocus autoComplete="email" value={email} onChange={(e) => setEmail(e.target.value)} />
|
||||||
|
</Field>
|
||||||
|
{error ? <p role="alert" className="text-sm text-danger">{error}</p> : null}
|
||||||
|
<Button type="submit" fullWidth loading={busy}>
|
||||||
|
Send code
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
) : (
|
||||||
|
<form onSubmit={verify} className="mt-6 space-y-4">
|
||||||
|
<Field label="6-digit code">
|
||||||
|
<Input
|
||||||
|
inputMode="numeric"
|
||||||
|
autoComplete="one-time-code"
|
||||||
|
pattern="\d{6}"
|
||||||
|
maxLength={6}
|
||||||
|
required
|
||||||
|
autoFocus
|
||||||
|
className="text-center font-mono text-xl tracking-[0.5em]"
|
||||||
|
value={code}
|
||||||
|
onChange={(e) => setCode(e.target.value.replace(/\D/g, ''))}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
{error ? <p role="alert" className="text-sm text-danger">{error}</p> : null}
|
||||||
|
<Button type="submit" fullWidth loading={busy} disabled={code.length !== 6}>
|
||||||
|
Verify and sign in
|
||||||
|
</Button>
|
||||||
|
<div className="flex justify-between text-sm">
|
||||||
|
<button type="button" className="inline-flex items-center gap-1 text-primary hover:underline" onClick={() => { setStep('email'); setError(undefined); }}>
|
||||||
|
<ArrowLeft className="h-3.5 w-3.5" /> Change email
|
||||||
|
</button>
|
||||||
|
<button type="button" className="text-primary hover:underline" disabled={busy} onClick={() => requestCode()}>
|
||||||
|
Resend code
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{import.meta.env.DEV ? (
|
||||||
|
<p className="mt-6 rounded-lg bg-surface-muted px-3 py-2 text-xs text-primary">
|
||||||
|
In dev the code is printed in the backend console.
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
181
src/pages/Merch.tsx
Normal file
181
src/pages/Merch.tsx
Normal file
|
|
@ -0,0 +1,181 @@
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { Pencil, Plus } from 'lucide-react';
|
||||||
|
import { PageShell } from '@/components/layout/AppLayout';
|
||||||
|
import { DataTable, type ColumnDef } from '@/components/DataTable';
|
||||||
|
import { ActiveBadge, AdminOnly, FormDialog, QueryError, StatusBadge, useSave } from '@/components/common';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Input, Textarea } from '@/components/ui/input';
|
||||||
|
import { Field } from '@/components/ui/field';
|
||||||
|
import { SwitchRow } from '@/components/ui/switch';
|
||||||
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||||
|
import { api } from '@/lib/api';
|
||||||
|
import type { MerchItem, Order } from '@/lib/types';
|
||||||
|
import { date, money, toDollars, toMinor } from '@/lib/utils';
|
||||||
|
import { OrderActions } from './Orders';
|
||||||
|
|
||||||
|
export function MerchPage() {
|
||||||
|
const [editing, setEditing] = useState<MerchItem | 'new' | null>(null);
|
||||||
|
const items = useQuery({ queryKey: ['merch'], queryFn: () => api<MerchItem[]>('/admin/merch') });
|
||||||
|
const orders = useQuery({
|
||||||
|
queryKey: ['orders', { kind: 'MERCH' }],
|
||||||
|
queryFn: () => api<Order[]>('/admin/orders?kind=MERCH'),
|
||||||
|
refetchInterval: 20_000,
|
||||||
|
});
|
||||||
|
const queue = orders.data?.filter((o) => o.status === 'PENDING' || o.status === 'PAID');
|
||||||
|
|
||||||
|
const itemCols: ColumnDef<MerchItem>[] = [
|
||||||
|
{
|
||||||
|
id: 'name',
|
||||||
|
header: 'Item',
|
||||||
|
accessorKey: 'name',
|
||||||
|
cell: ({ row: { original: m } }) => (
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
{m.imageUrl ? <img src={m.imageUrl} alt="" className="h-10 w-10 rounded-lg object-cover" /> : null}
|
||||||
|
<div>
|
||||||
|
<p className="font-semibold">{m.name}</p>
|
||||||
|
{m.sizes.length ? <p className="text-xs text-muted">{m.sizes.join(' · ')}</p> : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ id: 'price', header: 'Price', accessorKey: 'priceMinor', cell: ({ row }) => <span className="tabular">{money(row.original.priceMinor, row.original.currency)}</span> },
|
||||||
|
{ header: 'Stock', accessorKey: 'stock', cell: ({ row }) => <span className={`tabular ${row.original.stock <= 0 ? 'text-danger' : ''}`}>{row.original.stock}</span> },
|
||||||
|
{ id: 'active', header: 'Status', accessorKey: 'active', cell: ({ row }) => <ActiveBadge active={row.original.active} /> },
|
||||||
|
{
|
||||||
|
id: 'edit',
|
||||||
|
enableSorting: false,
|
||||||
|
header: () => <span className="sr-only">Edit</span>,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<AdminOnly>
|
||||||
|
<Button variant="ghost" size="icon-sm" aria-label={`Edit ${row.original.name}`} onClick={() => setEditing(row.original)}>
|
||||||
|
<Pencil />
|
||||||
|
</Button>
|
||||||
|
</AdminOnly>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const queueCols: ColumnDef<Order>[] = [
|
||||||
|
{ header: 'Order', accessorKey: 'number', cell: ({ row }) => <span className="font-mono font-semibold">{row.original.number}</span> },
|
||||||
|
{
|
||||||
|
id: 'buyer',
|
||||||
|
header: 'Buyer',
|
||||||
|
accessorFn: (o) => o.buyerName,
|
||||||
|
cell: ({ row: { original: o } }) => (
|
||||||
|
<div>
|
||||||
|
<p className="font-medium">{o.buyerName}</p>
|
||||||
|
<p className="text-xs text-muted">{o.buyerEmail}</p>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'items',
|
||||||
|
header: 'Items',
|
||||||
|
enableSorting: false,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<ul className="text-sm">
|
||||||
|
{row.original.items.map((it, i) => (
|
||||||
|
<li key={i}>
|
||||||
|
{it.qty} × {it.name}
|
||||||
|
{it.size ? <span className="font-semibold"> ({it.size})</span> : null}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ id: 'total', header: 'Total', accessorKey: 'totalMinor', cell: ({ row }) => <span className="tabular">{money(row.original.totalMinor, row.original.currency)}</span> },
|
||||||
|
{ header: 'Status', accessorKey: 'status', cell: ({ row }) => <StatusBadge status={row.original.status} /> },
|
||||||
|
{ id: 'created', header: 'Ordered', accessorKey: 'createdAt', cell: ({ row }) => <span className="whitespace-nowrap">{date(row.original.createdAt, true)}</span> },
|
||||||
|
{ id: 'act', enableSorting: false, header: () => <span className="sr-only">Actions</span>, cell: ({ row }) => <OrderActions order={row.original} /> },
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageShell
|
||||||
|
title="Merch"
|
||||||
|
subtitle="Attendees order in the app and pay & collect at the merch booth."
|
||||||
|
actions={
|
||||||
|
<AdminOnly>
|
||||||
|
<Button onClick={() => setEditing('new')}>
|
||||||
|
<Plus /> New item
|
||||||
|
</Button>
|
||||||
|
</AdminOnly>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Tabs defaultValue="queue">
|
||||||
|
<TabsList>
|
||||||
|
<TabsTrigger value="queue">Pickup queue{queue ? ` (${queue.length})` : ''}</TabsTrigger>
|
||||||
|
<TabsTrigger value="items">Items</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
<TabsContent value="queue" className="space-y-4">
|
||||||
|
{orders.error ? <QueryError error={orders.error} retry={() => orders.refetch()} /> : null}
|
||||||
|
<DataTable data={queue} loading={orders.isLoading} columns={queueCols} getRowId={(o) => o.id} empty="Queue is clear." />
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="items" className="space-y-4">
|
||||||
|
{items.error ? <QueryError error={items.error} retry={() => items.refetch()} /> : null}
|
||||||
|
<DataTable data={items.data} loading={items.isLoading} columns={itemCols} getRowId={(m) => m.id} empty="No merch items yet." />
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
{editing ? <MerchDialog item={editing === 'new' ? null : editing} onClose={() => setEditing(null)} /> : null}
|
||||||
|
</PageShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MerchDialog({ item: m, onClose }: { item: MerchItem | null; onClose: () => void }) {
|
||||||
|
const [f, setF] = useState({
|
||||||
|
name: m?.name ?? '',
|
||||||
|
description: m?.description ?? '',
|
||||||
|
price: toDollars(m?.priceMinor ?? null),
|
||||||
|
sizes: m?.sizes.join(', ') ?? '',
|
||||||
|
stock: m?.stock?.toString() ?? '0',
|
||||||
|
imageUrl: m?.imageUrl ?? '',
|
||||||
|
active: m?.active ?? true,
|
||||||
|
});
|
||||||
|
const set = (k: keyof typeof f) => (e: { target: { value: string } }) => setF({ ...f, [k]: e.target.value });
|
||||||
|
const save = useSave('/admin/merch', 'merch', onClose);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormDialog
|
||||||
|
open
|
||||||
|
onOpenChange={(o) => !o && onClose()}
|
||||||
|
title={m ? `Edit ${m.name}` : 'New merch item'}
|
||||||
|
loading={save.isPending}
|
||||||
|
onSubmit={() =>
|
||||||
|
save.mutate({
|
||||||
|
id: m?.id,
|
||||||
|
body: {
|
||||||
|
name: f.name.trim(),
|
||||||
|
description: f.description.trim() || null,
|
||||||
|
priceMinor: toMinor(f.price) ?? 0,
|
||||||
|
sizes: f.sizes.split(',').map((s) => s.trim()).filter(Boolean),
|
||||||
|
stock: Number(f.stock),
|
||||||
|
imageUrl: f.imageUrl.trim() || null,
|
||||||
|
active: f.active,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Field label="Name">
|
||||||
|
<Input required value={f.name} onChange={set('name')} />
|
||||||
|
</Field>
|
||||||
|
<Field label="Description" optional>
|
||||||
|
<Textarea rows={2} value={f.description} onChange={set('description')} />
|
||||||
|
</Field>
|
||||||
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
|
<Field label="Price (USD)">
|
||||||
|
<Input required type="number" min="0" step="0.01" value={f.price} onChange={set('price')} />
|
||||||
|
</Field>
|
||||||
|
<Field label="Stock">
|
||||||
|
<Input required type="number" min="0" step="1" value={f.stock} onChange={set('stock')} />
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
<Field label="Sizes" optional hint="Comma separated, e.g. S, M, L, XL">
|
||||||
|
<Input value={f.sizes} onChange={set('sizes')} />
|
||||||
|
</Field>
|
||||||
|
<Field label="Image URL" optional>
|
||||||
|
<Input type="url" value={f.imageUrl} onChange={set('imageUrl')} />
|
||||||
|
</Field>
|
||||||
|
<SwitchRow label="Active" description="Shown in the app shop" checked={f.active} onCheckedChange={(active) => setF({ ...f, active })} />
|
||||||
|
</FormDialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
309
src/pages/Orders.tsx
Normal file
309
src/pages/Orders.tsx
Normal file
|
|
@ -0,0 +1,309 @@
|
||||||
|
import { useState, type FormEvent } from 'react';
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { ChevronDown, ChevronRight, ScanLine } from 'lucide-react';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { PageShell } from '@/components/layout/AppLayout';
|
||||||
|
import { DataTable, type ColumnDef } from '@/components/DataTable';
|
||||||
|
import { QrImage, QueryError, StatusBadge } from '@/components/common';
|
||||||
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||||
|
import { Input, SelectNative } from '@/components/ui/input';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { ConfirmDialog } from '@/components/ui/confirm-dialog';
|
||||||
|
import { Field } from '@/components/ui/field';
|
||||||
|
import { api, ApiError, qs } from '@/lib/api';
|
||||||
|
import type { AdminTicket, Order, Ticket } from '@/lib/types';
|
||||||
|
import { date, errorMessage, money, useDebounced } from '@/lib/utils';
|
||||||
|
|
||||||
|
type Action = 'mark-paid' | 'fulfil' | 'cancel' | 'resend';
|
||||||
|
const actionLabel: Record<Action, string> = { 'mark-paid': 'Mark paid', fulfil: 'Fulfil', cancel: 'Cancel', resend: 'Resend' };
|
||||||
|
|
||||||
|
/** Row actions for an order; shared with the merch pickup queue. */
|
||||||
|
export function OrderActions({ order }: { order: Order }) {
|
||||||
|
const qc = useQueryClient();
|
||||||
|
const [pending, setPending] = useState<Action | null>(null);
|
||||||
|
const [ref, setRef] = useState('');
|
||||||
|
const run = useMutation({
|
||||||
|
mutationFn: (action: Action) =>
|
||||||
|
api(`/admin/orders/${order.id}/${action}`, { body: action === 'mark-paid' ? { paymentRef: ref.trim() || undefined } : {} }),
|
||||||
|
onSuccess: (_, action) => {
|
||||||
|
toast.success(action === 'resend' ? `Ticket email re-sent for ${order.number}` : `${order.number}: ${actionLabel[action].toLowerCase()} done`);
|
||||||
|
setPending(null);
|
||||||
|
setRef('');
|
||||||
|
qc.invalidateQueries({ queryKey: ['orders'] });
|
||||||
|
qc.invalidateQueries({ queryKey: ['tickets'] });
|
||||||
|
qc.invalidateQueries({ queryKey: ['stats'] });
|
||||||
|
},
|
||||||
|
onError: (e) => toast.error(errorMessage(e)),
|
||||||
|
});
|
||||||
|
|
||||||
|
const open = order.status === 'PENDING' || order.status === 'PAID';
|
||||||
|
const actions: Action[] = [
|
||||||
|
...(order.status === 'PENDING' ? (['mark-paid'] as const) : []),
|
||||||
|
...(open && order.kind === 'MERCH' ? (['fulfil'] as const) : []),
|
||||||
|
...(order.kind === 'TICKET' && (order.status === 'PAID' || order.status === 'FULFILLED') ? (['resend'] as const) : []),
|
||||||
|
...(open ? (['cancel'] as const) : []),
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-wrap justify-end gap-1.5">
|
||||||
|
{actions.map((a) => (
|
||||||
|
<Button
|
||||||
|
key={a}
|
||||||
|
size="sm"
|
||||||
|
variant={a === 'cancel' ? 'danger-outline' : a === 'resend' ? 'outline' : 'primary'}
|
||||||
|
loading={run.isPending && run.variables === a}
|
||||||
|
onClick={() => (a === 'mark-paid' || a === 'cancel' ? setPending(a) : run.mutate(a))}
|
||||||
|
>
|
||||||
|
{actionLabel[a]}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
<ConfirmDialog
|
||||||
|
open={pending !== null}
|
||||||
|
onOpenChange={(o) => !o && setPending(null)}
|
||||||
|
title={pending === 'cancel' ? `Cancel ${order.number}?` : `Mark ${order.number} as paid`}
|
||||||
|
description={
|
||||||
|
pending === 'cancel'
|
||||||
|
? 'The order is marked cancelled. This cannot be undone here.'
|
||||||
|
: order.kind === 'TICKET'
|
||||||
|
? `${money(order.totalMinor, order.currency)} from ${order.buyerName}. Tickets are issued and emailed to ${order.buyerEmail}.`
|
||||||
|
: `${money(order.totalMinor, order.currency)} from ${order.buyerName}.`
|
||||||
|
}
|
||||||
|
confirmLabel={pending === 'cancel' ? 'Cancel order' : 'Mark paid'}
|
||||||
|
tone={pending === 'cancel' ? 'danger' : 'primary'}
|
||||||
|
loading={run.isPending}
|
||||||
|
onConfirm={() => { if (pending) run.mutate(pending); }}
|
||||||
|
>
|
||||||
|
{pending === 'mark-paid' ? (
|
||||||
|
<Field label="Payment reference" optional hint="Bank transfer ref, receipt number…">
|
||||||
|
<Input value={ref} onChange={(e) => setRef(e.target.value)} />
|
||||||
|
</Field>
|
||||||
|
) : null}
|
||||||
|
</ConfirmDialog>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function OrderDetails({ order }: { order: Order }) {
|
||||||
|
return (
|
||||||
|
<div className="grid gap-6 text-sm lg:grid-cols-2">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p className="text-xs font-semibold uppercase tracking-widest text-primary">Items</p>
|
||||||
|
<ul className="space-y-1">
|
||||||
|
{order.items.map((it, i) => (
|
||||||
|
<li key={i} className="flex justify-between gap-4">
|
||||||
|
<span>
|
||||||
|
{it.qty} × {it.name}
|
||||||
|
{it.size ? ` (${it.size})` : ''}
|
||||||
|
</span>
|
||||||
|
<span className="tabular">{money(it.unitPriceMinor * it.qty, order.currency)}</span>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
{order.discountMinor ? (
|
||||||
|
<p className="flex justify-between text-muted">
|
||||||
|
<span>Discount {order.discountCode}</span>
|
||||||
|
<span className="tabular">−{money(order.discountMinor, order.currency)}</span>
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
<p className="text-muted">
|
||||||
|
{order.company ? `${order.company} · ` : ''}
|
||||||
|
{order.buyerPhone ?? ''} · pay by {order.paymentMethod}
|
||||||
|
{order.paymentRef ? ` · ref ${order.paymentRef}` : ''}
|
||||||
|
</p>
|
||||||
|
<p className="text-muted">
|
||||||
|
Paid {date(order.paidAt, true)} · Fulfilled {date(order.fulfilledAt, true)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{order.tickets?.length ? (
|
||||||
|
<div>
|
||||||
|
<p className="text-xs font-semibold uppercase tracking-widest text-primary">Tickets</p>
|
||||||
|
<ul className="mt-2 flex flex-wrap gap-3">
|
||||||
|
{order.tickets.map((t) => (
|
||||||
|
<li key={t.id} className="flex items-center gap-3 rounded-lg border border-primary/12 bg-surface p-2">
|
||||||
|
<QrImage value={t.qrUrl} size={64} />
|
||||||
|
<div className="text-xs">
|
||||||
|
<p className="font-medium">{t.tierName}</p>
|
||||||
|
<p className="text-muted">{t.holderName ?? t.holderEmail}</p>
|
||||||
|
<CheckInBadge ticket={t} />
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const CheckInBadge = ({ ticket }: { ticket: Ticket }) =>
|
||||||
|
ticket.checkedInAt ? <Badge tone="success">In · {date(ticket.checkedInAt, true)}</Badge> : <Badge tone="outline">Not checked in</Badge>;
|
||||||
|
|
||||||
|
function OrdersTab() {
|
||||||
|
const [kind, setKind] = useState('');
|
||||||
|
const [status, setStatus] = useState('');
|
||||||
|
const [q, setQ] = useState('');
|
||||||
|
const [open, setOpen] = useState<Record<string, boolean>>({});
|
||||||
|
const filters = { kind, status, q: useDebounced(q.trim()) };
|
||||||
|
const list = useQuery({ queryKey: ['orders', filters], queryFn: () => api<Order[]>(`/admin/orders${qs(filters)}`) });
|
||||||
|
|
||||||
|
const columns: ColumnDef<Order>[] = [
|
||||||
|
{
|
||||||
|
id: 'expand',
|
||||||
|
enableSorting: false,
|
||||||
|
header: () => <span className="sr-only">Details</span>,
|
||||||
|
cell: ({ row: { original: o } }) => (
|
||||||
|
<Button variant="ghost" size="icon-sm" aria-label="Toggle details" aria-expanded={!!open[o.id]} onClick={() => setOpen((s) => ({ ...s, [o.id]: !s[o.id] }))}>
|
||||||
|
{open[o.id] ? <ChevronDown /> : <ChevronRight />}
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ header: 'Order', accessorKey: 'number', cell: ({ row }) => <span className="font-mono font-semibold">{row.original.number}</span> },
|
||||||
|
{ header: 'Kind', accessorKey: 'kind', cell: ({ row }) => <Badge tone="outline">{row.original.kind}</Badge> },
|
||||||
|
{
|
||||||
|
id: 'buyer',
|
||||||
|
header: 'Buyer',
|
||||||
|
accessorFn: (o) => o.buyerName,
|
||||||
|
cell: ({ row: { original: o } }) => (
|
||||||
|
<div>
|
||||||
|
<p className="font-medium">{o.buyerName}</p>
|
||||||
|
<p className="text-xs text-muted">{o.buyerEmail}</p>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ id: 'total', header: 'Total', accessorKey: 'totalMinor', cell: ({ row }) => <span className="tabular">{money(row.original.totalMinor, row.original.currency)}</span> },
|
||||||
|
{ header: 'Status', accessorKey: 'status', cell: ({ row }) => <StatusBadge status={row.original.status} /> },
|
||||||
|
{ id: 'created', header: 'Created', accessorKey: 'createdAt', cell: ({ row }) => <span className="whitespace-nowrap">{date(row.original.createdAt, true)}</span> },
|
||||||
|
{ id: 'actions', enableSorting: false, header: () => <span className="sr-only">Actions</span>, cell: ({ row }) => <OrderActions order={row.original} /> },
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex flex-wrap gap-3">
|
||||||
|
<Input aria-label="Search" placeholder="Order number, name, email" className="max-w-xs" value={q} onChange={(e) => setQ(e.target.value)} />
|
||||||
|
<SelectNative aria-label="Kind" className="w-36" value={kind} onChange={(e) => setKind(e.target.value)}>
|
||||||
|
<option value="">All kinds</option>
|
||||||
|
<option value="TICKET">Tickets</option>
|
||||||
|
<option value="MERCH">Merch</option>
|
||||||
|
</SelectNative>
|
||||||
|
<SelectNative aria-label="Status" className="w-40" value={status} onChange={(e) => setStatus(e.target.value)}>
|
||||||
|
<option value="">All statuses</option>
|
||||||
|
{['PENDING', 'PAID', 'FULFILLED', 'CANCELLED'].map((s) => (
|
||||||
|
<option key={s} value={s}>
|
||||||
|
{s.charAt(0) + s.slice(1).toLowerCase()}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</SelectNative>
|
||||||
|
</div>
|
||||||
|
{list.error ? <QueryError error={list.error} retry={() => list.refetch()} /> : null}
|
||||||
|
<DataTable
|
||||||
|
data={list.data}
|
||||||
|
loading={list.isLoading}
|
||||||
|
columns={columns}
|
||||||
|
getRowId={(o) => o.id}
|
||||||
|
empty="No orders match."
|
||||||
|
renderExpanded={(o) => (open[o.id] ? <OrderDetails order={o} /> : null)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function TicketsTab() {
|
||||||
|
const qc = useQueryClient();
|
||||||
|
const [q, setQ] = useState('');
|
||||||
|
const [token, setToken] = useState('');
|
||||||
|
const [last, setLast] = useState<{ ok: boolean; text: string }>();
|
||||||
|
const search = useDebounced(q.trim());
|
||||||
|
const list = useQuery({ queryKey: ['tickets', search], queryFn: () => api<AdminTicket[]>(`/admin/tickets${qs({ q: search })}`) });
|
||||||
|
|
||||||
|
const checkIn = useMutation({
|
||||||
|
mutationFn: (t: string) => api<Ticket>('/admin/tickets/check-in', { body: { token: t } }),
|
||||||
|
onSuccess: (t) => {
|
||||||
|
setLast({ ok: true, text: `Checked in: ${t.holderName ?? t.holderEmail} · ${t.tierName}` });
|
||||||
|
setToken('');
|
||||||
|
qc.invalidateQueries({ queryKey: ['tickets'] });
|
||||||
|
},
|
||||||
|
onError: (e) => {
|
||||||
|
setLast({ ok: false, text: e instanceof ApiError && e.status === 409 ? `Already checked in. ${e.message}` : errorMessage(e) });
|
||||||
|
setToken('');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const submit = (e: FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (token.trim()) checkIn.mutate(token.trim());
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns: ColumnDef<AdminTicket>[] = [
|
||||||
|
{ id: 'qr', enableSorting: false, header: 'QR', cell: ({ row }) => <QrImage value={row.original.qrUrl} size={48} /> },
|
||||||
|
{
|
||||||
|
id: 'holder',
|
||||||
|
header: 'Holder',
|
||||||
|
accessorFn: (t) => t.holderName ?? t.holderEmail,
|
||||||
|
cell: ({ row: { original: t } }) => (
|
||||||
|
<div>
|
||||||
|
<p className="font-medium">{t.holderName ?? '—'}</p>
|
||||||
|
<p className="text-xs text-muted">{t.holderEmail}</p>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ header: 'Tier', accessorKey: 'tierName' },
|
||||||
|
{ header: 'Order', accessorKey: 'orderNumber', cell: ({ row }) => <span className="font-mono">{row.original.orderNumber}</span> },
|
||||||
|
{ id: 'checkin', header: 'Check-in', accessorFn: (t) => t.checkedInAt ?? '', cell: ({ row }) => <CheckInBadge ticket={row.original} /> },
|
||||||
|
{
|
||||||
|
id: 'act',
|
||||||
|
enableSorting: false,
|
||||||
|
header: () => <span className="sr-only">Actions</span>,
|
||||||
|
cell: ({ row: { original: t } }) =>
|
||||||
|
t.checkedInAt ? null : (
|
||||||
|
<Button size="sm" variant="outline" loading={checkIn.isPending && checkIn.variables === t.qrToken} onClick={() => checkIn.mutate(t.qrToken)}>
|
||||||
|
Check in
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<form onSubmit={submit} className="rounded-xl border border-primary/12 bg-surface p-4">
|
||||||
|
<label htmlFor="checkin-token" className="text-sm font-medium">
|
||||||
|
Check in a ticket
|
||||||
|
</label>
|
||||||
|
<p className="text-xs text-muted">Paste the ticket link or token, or focus the box and scan with a handheld QR scanner.</p>
|
||||||
|
<div className="mt-2 flex gap-2">
|
||||||
|
<Input id="checkin-token" autoFocus autoComplete="off" placeholder="https://grv.ethiopiatrustfund.org/t/…" value={token} onChange={(e) => setToken(e.target.value)} />
|
||||||
|
<Button type="submit" loading={checkIn.isPending} disabled={!token.trim()}>
|
||||||
|
<ScanLine /> Check in
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{last ? (
|
||||||
|
<p role="status" className={`mt-2 rounded-lg px-3 py-2 text-sm font-medium ${last.ok ? 'bg-success-soft text-success' : 'bg-danger-soft text-danger'}`}>
|
||||||
|
{last.text}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</form>
|
||||||
|
<Input aria-label="Search tickets" placeholder="Search holder, email, order" className="max-w-xs" value={q} onChange={(e) => setQ(e.target.value)} />
|
||||||
|
{list.error ? <QueryError error={list.error} retry={() => list.refetch()} /> : null}
|
||||||
|
<DataTable data={list.data} loading={list.isLoading} columns={columns} getRowId={(t) => t.id} empty="No tickets issued yet." />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function OrdersPage() {
|
||||||
|
return (
|
||||||
|
<PageShell title="Orders & tickets" subtitle="Bank and booth payments are confirmed here; marking a ticket order paid issues and emails the tickets.">
|
||||||
|
<Tabs defaultValue="orders">
|
||||||
|
<TabsList>
|
||||||
|
<TabsTrigger value="orders">Orders</TabsTrigger>
|
||||||
|
<TabsTrigger value="tickets">Tickets & check-in</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
<TabsContent value="orders">
|
||||||
|
<OrdersTab />
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="tickets">
|
||||||
|
<TicketsTab />
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
</PageShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
135
src/pages/Raffles.tsx
Normal file
135
src/pages/Raffles.tsx
Normal file
|
|
@ -0,0 +1,135 @@
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { Dices, Pencil, Plus, Trophy } from 'lucide-react';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { PageShell } from '@/components/layout/AppLayout';
|
||||||
|
import { AdminOnly, FormDialog, PatternEmpty, QueryError, useSave } from '@/components/common';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { Field } from '@/components/ui/field';
|
||||||
|
import { ConfirmDialog } from '@/components/ui/confirm-dialog';
|
||||||
|
import { SkeletonRows } from '@/components/ui/skeleton';
|
||||||
|
import { api } from '@/lib/api';
|
||||||
|
import type { Raffle } from '@/lib/types';
|
||||||
|
import { date, errorMessage } from '@/lib/utils';
|
||||||
|
|
||||||
|
export function RafflesPage() {
|
||||||
|
const qc = useQueryClient();
|
||||||
|
const list = useQuery({ queryKey: ['raffles'], queryFn: () => api<Raffle[]>('/admin/raffles') });
|
||||||
|
const [editing, setEditing] = useState<Raffle | 'new' | null>(null);
|
||||||
|
const [drawing, setDrawing] = useState<Raffle | null>(null);
|
||||||
|
|
||||||
|
const draw = useMutation({
|
||||||
|
mutationFn: (id: string) => api<Raffle>(`/admin/raffles/${id}/draw`, { body: {} }),
|
||||||
|
onSuccess: (r) => {
|
||||||
|
toast.success(`Winner: ${r.winner?.name ?? r.winner?.email ?? 'drawn'}`);
|
||||||
|
setDrawing(null);
|
||||||
|
qc.invalidateQueries({ queryKey: ['raffles'] });
|
||||||
|
},
|
||||||
|
onError: (e) => toast.error(errorMessage(e)),
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageShell
|
||||||
|
title="Raffles"
|
||||||
|
subtitle="Attendees with enough points are entered automatically. Previous winners are excluded from later draws."
|
||||||
|
actions={
|
||||||
|
<AdminOnly>
|
||||||
|
<Button onClick={() => setEditing('new')}>
|
||||||
|
<Plus /> New raffle
|
||||||
|
</Button>
|
||||||
|
</AdminOnly>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{list.error ? <QueryError error={list.error} retry={() => list.refetch()} /> : null}
|
||||||
|
{list.isLoading ? (
|
||||||
|
<SkeletonRows />
|
||||||
|
) : list.data?.length === 0 ? (
|
||||||
|
<PatternEmpty title="No raffles yet" description="Create a raffle with a prize and a minimum points threshold." />
|
||||||
|
) : (
|
||||||
|
<div className="grid gap-4 md:grid-cols-2 xl:grid-cols-3">
|
||||||
|
{list.data?.map((r) => (
|
||||||
|
<article key={r.id} className="flex flex-col rounded-xl border border-primary/12 bg-surface p-5 shadow-card">
|
||||||
|
<div className="flex items-start justify-between gap-2">
|
||||||
|
<div>
|
||||||
|
<h2 className="font-display text-xl font-bold">{r.name}</h2>
|
||||||
|
<p className="text-sm text-muted">{r.prize}</p>
|
||||||
|
</div>
|
||||||
|
<AdminOnly>
|
||||||
|
{r.drawnAt ? null : (
|
||||||
|
<Button variant="ghost" size="icon-sm" aria-label={`Edit ${r.name}`} onClick={() => setEditing(r)}>
|
||||||
|
<Pencil />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</AdminOnly>
|
||||||
|
</div>
|
||||||
|
<dl className="mt-4 grid grid-cols-2 gap-3 text-sm">
|
||||||
|
<div className="rounded-lg bg-surface-muted p-3">
|
||||||
|
<dt className="text-xs text-primary">Min points</dt>
|
||||||
|
<dd className="text-lg font-bold tabular">{r.minPoints}</dd>
|
||||||
|
</div>
|
||||||
|
<div className="rounded-lg bg-surface-muted p-3">
|
||||||
|
<dt className="text-xs text-primary">Eligible now</dt>
|
||||||
|
<dd className="text-lg font-bold tabular">{r.eligibleCount ?? '—'}</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
<div className="mt-4 flex-1" />
|
||||||
|
{r.winner ? (
|
||||||
|
<div className="flex items-center gap-3 rounded-lg bg-brand-tertiary p-3 text-white">
|
||||||
|
<Trophy className="h-5 w-5 text-secondary" aria-hidden />
|
||||||
|
<div className="min-w-0">
|
||||||
|
<p className="truncate font-semibold">{r.winner.name ?? r.winner.email ?? 'Winner'}</p>
|
||||||
|
<p className="truncate text-xs text-white/70">
|
||||||
|
{r.winner.name && r.winner.email ? `${r.winner.email} · ` : ''}drawn {date(r.drawnAt, true)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<AdminOnly>
|
||||||
|
<Button fullWidth disabled={!r.eligibleCount} onClick={() => setDrawing(r)}>
|
||||||
|
<Dices /> Draw winner
|
||||||
|
</Button>
|
||||||
|
</AdminOnly>
|
||||||
|
)}
|
||||||
|
</article>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{editing ? <RaffleDialog raffle={editing === 'new' ? null : editing} onClose={() => setEditing(null)} /> : null}
|
||||||
|
<ConfirmDialog
|
||||||
|
open={!!drawing}
|
||||||
|
onOpenChange={(o) => !o && setDrawing(null)}
|
||||||
|
title={`Draw ${drawing?.name ?? ''}?`}
|
||||||
|
description={`One winner is picked at random from ${drawing?.eligibleCount ?? 0} eligible attendees. This can only be done once.`}
|
||||||
|
confirmLabel="Draw winner"
|
||||||
|
loading={draw.isPending}
|
||||||
|
onConfirm={() => { if (drawing) draw.mutate(drawing.id); }}
|
||||||
|
/>
|
||||||
|
</PageShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function RaffleDialog({ raffle: r, onClose }: { raffle: Raffle | null; onClose: () => void }) {
|
||||||
|
const [f, setF] = useState({ name: r?.name ?? '', prize: r?.prize ?? '', minPoints: r?.minPoints?.toString() ?? '' });
|
||||||
|
const save = useSave('/admin/raffles', 'raffles', onClose);
|
||||||
|
return (
|
||||||
|
<FormDialog
|
||||||
|
open
|
||||||
|
onOpenChange={(o) => !o && onClose()}
|
||||||
|
title={r ? `Edit ${r.name}` : 'New raffle'}
|
||||||
|
loading={save.isPending}
|
||||||
|
onSubmit={() => save.mutate({ id: r?.id, body: { name: f.name.trim(), prize: f.prize.trim(), minPoints: Number(f.minPoints) } })}
|
||||||
|
>
|
||||||
|
<Field label="Name">
|
||||||
|
<Input required value={f.name} onChange={(e) => setF({ ...f, name: e.target.value })} />
|
||||||
|
</Field>
|
||||||
|
<Field label="Prize">
|
||||||
|
<Input required value={f.prize} onChange={(e) => setF({ ...f, prize: e.target.value })} />
|
||||||
|
</Field>
|
||||||
|
<Field label="Minimum points to enter">
|
||||||
|
<Input required type="number" min="0" step="1" value={f.minPoints} onChange={(e) => setF({ ...f, minPoints: e.target.value })} />
|
||||||
|
</Field>
|
||||||
|
</FormDialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
99
src/pages/Startups.tsx
Normal file
99
src/pages/Startups.tsx
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { Link } from 'react-router';
|
||||||
|
import { Pencil, Plus, Printer } from 'lucide-react';
|
||||||
|
import { PageShell } from '@/components/layout/AppLayout';
|
||||||
|
import { AdminOnly, PatternEmpty, QrImage, QueryError } from '@/components/common';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { SkeletonRows } from '@/components/ui/skeleton';
|
||||||
|
import type { Checkpoint } from '@/lib/types';
|
||||||
|
import { CheckpointDialog, printUrl, useCheckpoints } from './Checkpoints';
|
||||||
|
|
||||||
|
export function StartupsPage() {
|
||||||
|
const list = useCheckpoints('STARTUP_MEMBER');
|
||||||
|
const [editing, setEditing] = useState<{ c: Checkpoint | null; org?: string } | null>(null);
|
||||||
|
|
||||||
|
const groups = new Map<string, Checkpoint[]>();
|
||||||
|
for (const c of list.data ?? []) {
|
||||||
|
const org = c.organisation ?? 'No startup set';
|
||||||
|
groups.set(org, [...(groups.get(org) ?? []), c]);
|
||||||
|
}
|
||||||
|
const sorted = [...groups.entries()].sort(([a], [b]) => a.localeCompare(b));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageShell
|
||||||
|
title="Startups"
|
||||||
|
subtitle="Each team member wears a badge QR; attendees earn points for meeting them."
|
||||||
|
actions={
|
||||||
|
<>
|
||||||
|
<Button asChild variant="secondary" className={list.data?.length ? '' : 'pointer-events-none opacity-40'}>
|
||||||
|
<Link to={printUrl((list.data ?? []).map((c) => c.id))}>
|
||||||
|
<Printer /> Print all badges
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
<AdminOnly>
|
||||||
|
<Button onClick={() => setEditing({ c: null })}>
|
||||||
|
<Plus /> New member
|
||||||
|
</Button>
|
||||||
|
</AdminOnly>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{list.error ? <QueryError error={list.error} retry={() => list.refetch()} /> : null}
|
||||||
|
{list.isLoading ? (
|
||||||
|
<SkeletonRows />
|
||||||
|
) : sorted.length === 0 ? (
|
||||||
|
<PatternEmpty title="No startup members yet" description="Add startup team members as checkpoints to give each a badge QR." />
|
||||||
|
) : (
|
||||||
|
<div className="grid gap-4 lg:grid-cols-2">
|
||||||
|
{sorted.map(([org, members]) => (
|
||||||
|
<section key={org} className="rounded-xl border border-primary/12 bg-surface p-5 shadow-card">
|
||||||
|
<div className="flex items-start justify-between gap-3">
|
||||||
|
<div>
|
||||||
|
<h2 className="font-display text-xl font-bold">{org}</h2>
|
||||||
|
<p className="text-xs text-muted">
|
||||||
|
{members.length} member{members.length === 1 ? '' : 's'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-1.5">
|
||||||
|
<AdminOnly>
|
||||||
|
<Button size="sm" variant="outline" onClick={() => setEditing({ c: null, org: org === 'No startup set' ? undefined : org })}>
|
||||||
|
<Plus /> Add
|
||||||
|
</Button>
|
||||||
|
</AdminOnly>
|
||||||
|
<Button asChild size="sm" variant="secondary">
|
||||||
|
<Link to={printUrl(members.map((m) => m.id))}>
|
||||||
|
<Printer /> Print badges
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<ul className="mt-4 divide-y divide-border">
|
||||||
|
{members.map((m) => (
|
||||||
|
<li key={m.id} className="flex items-center gap-3 py-3">
|
||||||
|
<QrImage value={m.qrUrl} size={56} />
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<p className="truncate font-medium">{m.personName ?? '—'}</p>
|
||||||
|
<p className="truncate text-xs text-muted">
|
||||||
|
{m.label} · {m.points} pts
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{m.active ? null : <Badge tone="outline">Inactive</Badge>}
|
||||||
|
<AdminOnly>
|
||||||
|
<Button variant="ghost" size="icon-sm" aria-label={`Edit ${m.personName ?? m.label}`} onClick={() => setEditing({ c: m })}>
|
||||||
|
<Pencil />
|
||||||
|
</Button>
|
||||||
|
</AdminOnly>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{editing ? (
|
||||||
|
<CheckpointDialog checkpoint={editing.c} defaultKind="STARTUP_MEMBER" defaultOrganisation={editing.org} onClose={() => setEditing(null)} />
|
||||||
|
) : null}
|
||||||
|
</PageShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
141
src/pages/Tiers.tsx
Normal file
141
src/pages/Tiers.tsx
Normal file
|
|
@ -0,0 +1,141 @@
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { Pencil, Plus } from 'lucide-react';
|
||||||
|
import { PageShell } from '@/components/layout/AppLayout';
|
||||||
|
import { DataTable, type ColumnDef } from '@/components/DataTable';
|
||||||
|
import { ActiveBadge, AdminOnly, FormDialog, QueryError, useSave } from '@/components/common';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Input, Textarea } from '@/components/ui/input';
|
||||||
|
import { Field } from '@/components/ui/field';
|
||||||
|
import { SwitchRow } from '@/components/ui/switch';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { api } from '@/lib/api';
|
||||||
|
import type { Tier } from '@/lib/types';
|
||||||
|
import { money, toDollars, toMinor } from '@/lib/utils';
|
||||||
|
|
||||||
|
export function TiersPage() {
|
||||||
|
const [editing, setEditing] = useState<Tier | 'new' | null>(null);
|
||||||
|
const list = useQuery({ queryKey: ['tiers'], queryFn: () => api<Tier[]>('/admin/tiers') });
|
||||||
|
|
||||||
|
const columns: ColumnDef<Tier>[] = [
|
||||||
|
{
|
||||||
|
id: 'name',
|
||||||
|
header: 'Tier',
|
||||||
|
accessorKey: 'name',
|
||||||
|
cell: ({ row: { original: t } }) => (
|
||||||
|
<div>
|
||||||
|
<p className="font-semibold">{t.name}</p>
|
||||||
|
<p className="font-mono text-xs text-muted">{t.code}</p>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ id: 'price', header: 'Price', accessorKey: 'priceMinor', cell: ({ row }) => <span className="tabular">{money(row.original.priceMinor, row.original.currency)}</span> },
|
||||||
|
{
|
||||||
|
id: 'sold',
|
||||||
|
header: 'Sold',
|
||||||
|
accessorKey: 'sold',
|
||||||
|
cell: ({ row: { original: t } }) => (
|
||||||
|
<span className="tabular">
|
||||||
|
{t.sold}
|
||||||
|
{t.capacity !== null ? ` / ${t.capacity}` : ''} {t.soldOut ? <Badge tone="warning">Sold out</Badge> : null}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ header: 'Schedule', accessorFn: (t) => t.scheduleLabel ?? '—' },
|
||||||
|
{ id: 'active', header: 'Status', accessorKey: 'active', cell: ({ row }) => <ActiveBadge active={row.original.active} /> },
|
||||||
|
{
|
||||||
|
id: 'edit',
|
||||||
|
enableSorting: false,
|
||||||
|
header: () => <span className="sr-only">Edit</span>,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<AdminOnly>
|
||||||
|
<Button variant="ghost" size="icon-sm" aria-label={`Edit ${row.original.name}`} onClick={() => setEditing(row.original)}>
|
||||||
|
<Pencil />
|
||||||
|
</Button>
|
||||||
|
</AdminOnly>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageShell
|
||||||
|
title="Ticket tiers"
|
||||||
|
subtitle="Passes shown on the site's tickets page. Inactive tiers are hidden from buyers."
|
||||||
|
actions={
|
||||||
|
<AdminOnly>
|
||||||
|
<Button onClick={() => setEditing('new')}>
|
||||||
|
<Plus /> New tier
|
||||||
|
</Button>
|
||||||
|
</AdminOnly>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{list.error ? <QueryError error={list.error} retry={() => list.refetch()} /> : null}
|
||||||
|
<DataTable data={list.data} loading={list.isLoading} columns={columns} getRowId={(t) => t.id} empty="No tiers yet." />
|
||||||
|
{editing ? <TierDialog tier={editing === 'new' ? null : editing} onClose={() => setEditing(null)} /> : null}
|
||||||
|
</PageShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function TierDialog({ tier, onClose }: { tier: Tier | null; onClose: () => void }) {
|
||||||
|
const [f, setF] = useState({
|
||||||
|
code: tier?.code ?? '',
|
||||||
|
name: tier?.name ?? '',
|
||||||
|
description: tier?.description ?? '',
|
||||||
|
scheduleLabel: tier?.scheduleLabel ?? '',
|
||||||
|
features: tier?.features.join('\n') ?? '',
|
||||||
|
price: toDollars(tier?.priceMinor ?? null),
|
||||||
|
capacity: tier?.capacity?.toString() ?? '',
|
||||||
|
active: tier?.active ?? true,
|
||||||
|
});
|
||||||
|
const set = (k: keyof typeof f) => (e: { target: { value: string } }) => setF({ ...f, [k]: e.target.value });
|
||||||
|
const save = useSave('/admin/tiers', 'tiers', onClose);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormDialog
|
||||||
|
open
|
||||||
|
onOpenChange={(o) => !o && onClose()}
|
||||||
|
title={tier ? `Edit ${tier.name}` : 'New tier'}
|
||||||
|
loading={save.isPending}
|
||||||
|
onSubmit={() =>
|
||||||
|
save.mutate({
|
||||||
|
id: tier?.id,
|
||||||
|
body: {
|
||||||
|
...(tier ? {} : { code: f.code.trim() }),
|
||||||
|
name: f.name.trim(),
|
||||||
|
description: f.description.trim(),
|
||||||
|
scheduleLabel: f.scheduleLabel.trim() || null,
|
||||||
|
features: f.features.split('\n').map((s) => s.trim()).filter(Boolean),
|
||||||
|
priceMinor: toMinor(f.price) ?? 0,
|
||||||
|
capacity: f.capacity ? Number(f.capacity) : null,
|
||||||
|
active: f.active,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
|
<Field label="Code" hint={tier ? 'Fixed once created (used in checkout links).' : 'e.g. general, vip'}>
|
||||||
|
<Input required disabled={!!tier} pattern="[a-z0-9_-]+" value={f.code} onChange={set('code')} />
|
||||||
|
</Field>
|
||||||
|
<Field label="Name">
|
||||||
|
<Input required value={f.name} onChange={set('name')} />
|
||||||
|
</Field>
|
||||||
|
<Field label="Price (USD)" hint="0 for free">
|
||||||
|
<Input required type="number" min="0" step="0.01" value={f.price} onChange={set('price')} />
|
||||||
|
</Field>
|
||||||
|
<Field label="Capacity" optional hint="Empty = unlimited">
|
||||||
|
<Input type="number" min="0" step="1" value={f.capacity} onChange={set('capacity')} />
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
<Field label="Schedule label" optional hint="e.g. Both days · 12–13 March">
|
||||||
|
<Input value={f.scheduleLabel} onChange={set('scheduleLabel')} />
|
||||||
|
</Field>
|
||||||
|
<Field label="Description">
|
||||||
|
<Textarea required rows={2} value={f.description} onChange={set('description')} />
|
||||||
|
</Field>
|
||||||
|
<Field label="Features" optional hint="One per line">
|
||||||
|
<Textarea rows={4} value={f.features} onChange={set('features')} />
|
||||||
|
</Field>
|
||||||
|
<SwitchRow label="Active" description="Visible and purchasable on the site" checked={f.active} onCheckedChange={(active) => setF({ ...f, active })} />
|
||||||
|
</FormDialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
40
src/router.tsx
Normal file
40
src/router.tsx
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
import { createBrowserRouter } from 'react-router';
|
||||||
|
import { AppLayout } from './components/layout/AppLayout';
|
||||||
|
import { LoginPage } from './pages/Login';
|
||||||
|
import { DashboardPage } from './pages/Dashboard';
|
||||||
|
import { ApplicationsPage } from './pages/Applications';
|
||||||
|
import { ApplicationDetailPage } from './pages/ApplicationDetail';
|
||||||
|
import { InquiriesPage } from './pages/Inquiries';
|
||||||
|
import { OrdersPage } from './pages/Orders';
|
||||||
|
import { TiersPage } from './pages/Tiers';
|
||||||
|
import { DiscountsPage } from './pages/Discounts';
|
||||||
|
import { CheckpointsPage } from './pages/Checkpoints';
|
||||||
|
import { CheckpointsPrintPage } from './pages/CheckpointsPrint';
|
||||||
|
import { StartupsPage } from './pages/Startups';
|
||||||
|
import { RafflesPage } from './pages/Raffles';
|
||||||
|
import { MerchPage } from './pages/Merch';
|
||||||
|
import { AttendeesPage } from './pages/Attendees';
|
||||||
|
|
||||||
|
export const router = createBrowserRouter([
|
||||||
|
{ path: '/login', element: <LoginPage /> },
|
||||||
|
// Print view sits outside the shell so only the cards print.
|
||||||
|
{ path: '/checkpoints/print', element: <CheckpointsPrintPage /> },
|
||||||
|
{
|
||||||
|
element: <AppLayout />,
|
||||||
|
children: [
|
||||||
|
{ index: true, element: <DashboardPage /> },
|
||||||
|
{ path: 'applications', element: <ApplicationsPage /> },
|
||||||
|
{ path: 'applications/:id', element: <ApplicationDetailPage /> },
|
||||||
|
{ path: 'inquiries', element: <InquiriesPage /> },
|
||||||
|
{ path: 'orders', element: <OrdersPage /> },
|
||||||
|
{ path: 'tiers', element: <TiersPage /> },
|
||||||
|
{ path: 'discounts', element: <DiscountsPage /> },
|
||||||
|
{ path: 'checkpoints', element: <CheckpointsPage /> },
|
||||||
|
{ path: 'startups', element: <StartupsPage /> },
|
||||||
|
{ path: 'raffles', element: <RafflesPage /> },
|
||||||
|
{ path: 'merch', element: <MerchPage /> },
|
||||||
|
{ path: 'attendees', element: <AttendeesPage /> },
|
||||||
|
{ path: '*', element: <p className="text-muted">Page not found.</p> },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
21
tsconfig.json
Normal file
21
tsconfig.json
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es2023",
|
||||||
|
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"types": ["vite/client", "node"],
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"noEmit": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"paths": { "@/*": ["./src/*"] },
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"noFallthroughCasesInSwitch": true
|
||||||
|
},
|
||||||
|
"include": ["src", "vite.config.ts"]
|
||||||
|
}
|
||||||
11
vite.config.ts
Normal file
11
vite.config.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import path from 'node:path';
|
||||||
|
import react from '@vitejs/plugin-react';
|
||||||
|
import tailwindcss from '@tailwindcss/vite';
|
||||||
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react(), tailwindcss()],
|
||||||
|
resolve: { alias: { '@': path.resolve(import.meta.dirname, 'src') } },
|
||||||
|
server: { port: 5175 },
|
||||||
|
build: { chunkSizeWarningLimit: 900 },
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user