chore: scaffold turbo monorepo with hono api and react admin web
This commit is contained in:
153
apps/web/src/routes/_authenticated/index.tsx
Normal file
153
apps/web/src/routes/_authenticated/index.tsx
Normal file
@@ -0,0 +1,153 @@
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { ActivityIcon, CircleCheckIcon, ServerIcon, UsersIcon } from 'lucide-react'
|
||||
import { Area, AreaChart, CartesianGrid, ResponsiveContainer, XAxis, YAxis } from 'recharts'
|
||||
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { useHealth } from '@/hooks/use-health'
|
||||
import { ApiError } from '@/lib/api-client'
|
||||
|
||||
const TRAFFIC = [
|
||||
{ day: 'Mon', requests: 420 },
|
||||
{ day: 'Tue', requests: 512 },
|
||||
{ day: 'Wed', requests: 388 },
|
||||
{ day: 'Thu', requests: 640 },
|
||||
{ day: 'Fri', requests: 731 },
|
||||
{ day: 'Sat', requests: 254 },
|
||||
{ day: 'Sun', requests: 198 },
|
||||
]
|
||||
|
||||
export const Route = createFileRoute('/_authenticated/')({
|
||||
component: DashboardPage,
|
||||
})
|
||||
|
||||
function DashboardPage() {
|
||||
return (
|
||||
<div className="flex flex-col gap-4 md:gap-6">
|
||||
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<StatCard title="Users" value="2,481" description="+12% vs last month" icon={UsersIcon} />
|
||||
<StatCard title="Active lists" value="318" description="+4 this week" icon={ActivityIcon} />
|
||||
<StatCard title="Tasks done" value="9,204" description="+18% vs last month" icon={CircleCheckIcon} />
|
||||
<ApiStatusCard />
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 lg:grid-cols-2">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Requests</CardTitle>
|
||||
<CardDescription>API requests over the last 7 days</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="h-72 pl-0">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<AreaChart data={TRAFFIC} margin={{ left: 12, right: 12, top: 8 }}>
|
||||
<defs>
|
||||
<linearGradient id="fillRequests" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="5%" stopColor="var(--color-primary)" stopOpacity={0.7} />
|
||||
<stop offset="95%" stopColor="var(--color-primary)" stopOpacity={0.05} />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<CartesianGrid vertical={false} strokeDasharray="3 3" />
|
||||
<XAxis dataKey="day" tickLine={false} axisLine={false} />
|
||||
<YAxis tickLine={false} axisLine={false} width={40} />
|
||||
<Area
|
||||
dataKey="requests"
|
||||
type="monotone"
|
||||
stroke="var(--color-primary)"
|
||||
fill="url(#fillRequests)"
|
||||
strokeWidth={2}
|
||||
/>
|
||||
</AreaChart>
|
||||
</ResponsiveContainer>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Recent activity</CardTitle>
|
||||
<CardDescription>What your team has been doing</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{[
|
||||
{ who: 'Ada Lovelace', what: 'created list "Q4 roadmap"', when: '2h ago' },
|
||||
{ who: 'Alan Turing', what: 'completed 12 tasks', when: '5h ago' },
|
||||
{ who: 'Grace Hopper', what: 'invited 3 teammates', when: 'yesterday' },
|
||||
{ who: 'Linus Torvalds', what: 'archived "Sprint 41"', when: '2 days ago' },
|
||||
].map((item) => (
|
||||
<div key={item.what} className="flex items-start gap-3">
|
||||
<div className="bg-muted text-muted-foreground flex size-9 shrink-0 items-center justify-center rounded-full text-xs font-medium">
|
||||
{item.who.slice(0, 2).toUpperCase()}
|
||||
</div>
|
||||
<div className="flex-1 text-sm">
|
||||
<p>
|
||||
<span className="font-medium">{item.who}</span> {item.what}
|
||||
</p>
|
||||
<p className="text-muted-foreground text-xs">{item.when}</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function StatCard({
|
||||
title,
|
||||
value,
|
||||
description,
|
||||
icon: Icon,
|
||||
}: {
|
||||
title: string
|
||||
value: string
|
||||
description: string
|
||||
icon: typeof UsersIcon
|
||||
}) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">{title}</CardTitle>
|
||||
<Icon className="text-muted-foreground size-4" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-semibold">{value}</div>
|
||||
<p className="text-muted-foreground text-xs">{description}</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
/** Pings `GET /health` through TanStack Query, proving the API wiring works. */
|
||||
function ApiStatusCard() {
|
||||
const { data, isPending, error } = useHealth()
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">API</CardTitle>
|
||||
<ServerIcon className="text-muted-foreground size-4" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isPending && <div className="text-2xl font-semibold">…</div>}
|
||||
{data && (
|
||||
<>
|
||||
<div className="text-2xl font-semibold">
|
||||
<Badge variant="secondary">online</Badge>
|
||||
</div>
|
||||
<p className="text-muted-foreground text-xs">up {data.uptimeSeconds}s</p>
|
||||
</>
|
||||
)}
|
||||
{error && (
|
||||
<>
|
||||
<div className="text-2xl font-semibold">
|
||||
<Badge variant="destructive">offline</Badge>
|
||||
</div>
|
||||
<p className="text-muted-foreground truncate text-xs">
|
||||
{error instanceof ApiError ? (error.problem.detail ?? error.message) : 'API unreachable'}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
49
apps/web/src/routes/_authenticated/route.tsx
Normal file
49
apps/web/src/routes/_authenticated/route.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import { createFileRoute, Navigate, Outlet } from '@tanstack/react-router'
|
||||
|
||||
import { AppHeader } from '@/components/layout/app-header'
|
||||
import { AppSidebar } from '@/components/layout/app-sidebar'
|
||||
import { SidebarInset, SidebarProvider } from '@/components/ui/sidebar'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { useSession } from '@/lib/auth-client'
|
||||
|
||||
export const Route = createFileRoute('/_authenticated')({
|
||||
component: AuthenticatedLayout,
|
||||
})
|
||||
|
||||
/**
|
||||
* Layout for every authenticated page. The session lives in BetterAuth (Hono
|
||||
* API); while it resolves we render a loader, and without a session we bounce
|
||||
* the user to `/sign-in`.
|
||||
*/
|
||||
function AuthenticatedLayout() {
|
||||
const { data: session, isPending } = useSession()
|
||||
|
||||
if (isPending) {
|
||||
return <SessionLoading />
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
return <Navigate to="/sign-in" replace />
|
||||
}
|
||||
|
||||
return (
|
||||
<SidebarProvider>
|
||||
<AppSidebar />
|
||||
<SidebarInset>
|
||||
<AppHeader />
|
||||
<div className="flex flex-1 flex-col gap-4 p-4 md:gap-6 md:p-6">
|
||||
<Outlet />
|
||||
</div>
|
||||
</SidebarInset>
|
||||
</SidebarProvider>
|
||||
)
|
||||
}
|
||||
|
||||
function SessionLoading() {
|
||||
return (
|
||||
<div className="space-y-4 p-6">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-64 w-full" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
98
apps/web/src/routes/_authenticated/settings.tsx
Normal file
98
apps/web/src/routes/_authenticated/settings.tsx
Normal file
@@ -0,0 +1,98 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { z } from 'zod'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Field, FieldDescription, FieldError, FieldGroup, FieldLabel } from '@/components/ui/field'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { useSession } from '@/lib/auth-client'
|
||||
|
||||
export const Route = createFileRoute('/_authenticated/settings')({
|
||||
component: SettingsPage,
|
||||
})
|
||||
|
||||
const profileSchema = z.object({
|
||||
name: z.string().min(1, 'Name is required').max(80),
|
||||
email: z.email('Enter a valid email address'),
|
||||
})
|
||||
|
||||
type ProfileValues = z.infer<typeof profileSchema>
|
||||
|
||||
function SettingsPage() {
|
||||
const { data: session } = useSession()
|
||||
const [saved, setSaved] = useState(false)
|
||||
|
||||
const form = useForm<ProfileValues>({
|
||||
resolver: zodResolver(profileSchema),
|
||||
defaultValues: {
|
||||
name: session?.user.name ?? '',
|
||||
email: session?.user.email ?? '',
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="grid max-w-3xl gap-4 md:gap-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Profile</CardTitle>
|
||||
<CardDescription>This is how other people will see you.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(() => {
|
||||
// Wire this to a `PATCH /users/me` feature on the API.
|
||||
setSaved(true)
|
||||
})}
|
||||
>
|
||||
<FieldGroup>
|
||||
<Field data-invalid={!!form.formState.errors.name}>
|
||||
<FieldLabel htmlFor="name">Name</FieldLabel>
|
||||
<Input id="name" placeholder="Ada Lovelace" {...form.register('name')} />
|
||||
<FieldError errors={[form.formState.errors.name]} />
|
||||
</Field>
|
||||
|
||||
<Field data-invalid={!!form.formState.errors.email}>
|
||||
<FieldLabel htmlFor="email">Email</FieldLabel>
|
||||
<Input id="email" type="email" placeholder="ada@example.com" {...form.register('email')} />
|
||||
<FieldDescription>We only use it to sign you in.</FieldDescription>
|
||||
<FieldError errors={[form.formState.errors.email]} />
|
||||
</Field>
|
||||
|
||||
<div className="flex items-center gap-4">
|
||||
<Button type="submit" disabled={form.formState.isSubmitting}>
|
||||
Save changes
|
||||
</Button>
|
||||
{saved && <span className="text-muted-foreground text-sm">Saved locally.</span>}
|
||||
</div>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Appearance</CardTitle>
|
||||
<CardDescription>Notifications and display preferences.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{[
|
||||
{ id: 'digest', label: 'Weekly digest', hint: 'A summary of your lists every Monday.' },
|
||||
{ id: 'mentions', label: 'Mentions', hint: 'Ping me when someone mentions my name.' },
|
||||
].map((option) => (
|
||||
<div key={option.id} className="flex items-center justify-between gap-4">
|
||||
<div>
|
||||
<p className="text-sm font-medium">{option.label}</p>
|
||||
<p className="text-muted-foreground text-sm">{option.hint}</p>
|
||||
</div>
|
||||
<Switch defaultChecked aria-label={option.label} />
|
||||
</div>
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
131
apps/web/src/routes/_authenticated/tasks.tsx
Normal file
131
apps/web/src/routes/_authenticated/tasks.tsx
Normal file
@@ -0,0 +1,131 @@
|
||||
import {
|
||||
createColumnHelper,
|
||||
tableFeatures,
|
||||
useTable,
|
||||
} from '@tanstack/react-table'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { SearchIcon } from 'lucide-react'
|
||||
import { useMemo, useState } from 'react'
|
||||
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from '@/components/ui/table'
|
||||
|
||||
export const Route = createFileRoute('/_authenticated/tasks')({
|
||||
component: TasksPage,
|
||||
})
|
||||
|
||||
type Task = {
|
||||
title: string
|
||||
list: string
|
||||
status: 'todo' | 'in progress' | 'done'
|
||||
priority: 'low' | 'medium' | 'high'
|
||||
}
|
||||
|
||||
const TASKS: Task[] = [
|
||||
{ title: 'Design onboarding flow', list: 'Q4 roadmap', status: 'in progress', priority: 'high' },
|
||||
{ title: 'Write API docs', list: 'Docs', status: 'todo', priority: 'medium' },
|
||||
{ title: 'Review Prisma migrations', list: 'Backend', status: 'todo', priority: 'high' },
|
||||
{ title: 'Ship dark mode', list: 'Design system', status: 'done', priority: 'low' },
|
||||
{ title: 'Migrate to Turborepo', list: 'Infra', status: 'done', priority: 'medium' },
|
||||
{ title: 'Add e2e smoke test', list: 'Quality', status: 'in progress', priority: 'low' },
|
||||
]
|
||||
|
||||
// `tableFeatures` and the columns live at module scope so row models stay stable.
|
||||
const features = tableFeatures({})
|
||||
const columnHelper = createColumnHelper<typeof features, Task>()
|
||||
|
||||
const columns = columnHelper.columns([
|
||||
columnHelper.accessor('title', { header: 'Task' }),
|
||||
columnHelper.accessor('list', { header: 'List' }),
|
||||
columnHelper.accessor('status', { header: 'Status' }),
|
||||
columnHelper.accessor('priority', { header: 'Priority' }),
|
||||
])
|
||||
|
||||
const STATUS_VARIANT = {
|
||||
todo: 'outline',
|
||||
'in progress': 'secondary',
|
||||
done: 'default',
|
||||
} as const
|
||||
|
||||
function TasksPage() {
|
||||
const [query, setQuery] = useState('')
|
||||
|
||||
const data = useMemo(
|
||||
() =>
|
||||
TASKS.filter((task) =>
|
||||
`${task.title} ${task.list} ${task.status}`.toLowerCase().includes(query.toLowerCase()),
|
||||
),
|
||||
[query],
|
||||
)
|
||||
|
||||
const table = useTable({ features, columns, data })
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Tasks</CardTitle>
|
||||
<CardDescription>Every task across your lists.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="relative max-w-sm">
|
||||
<SearchIcon className="text-muted-foreground absolute top-2.5 left-2.5 size-4" />
|
||||
<Input
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
placeholder="Filter tasks…"
|
||||
className="pl-8"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<TableRow key={headerGroup.id}>
|
||||
{headerGroup.headers.map((header) => (
|
||||
<TableHead key={header.id}>
|
||||
{header.isPlaceholder ? null : <table.FlexRender header={header} />}
|
||||
</TableHead>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{table.getRowModel().rows.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={columns.length} className="text-muted-foreground h-24 text-center">
|
||||
No tasks match your filter.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{table.getRowModel().rows.map((row) => (
|
||||
<TableRow key={row.id}>
|
||||
{row.getAllCells().map((cell) => (
|
||||
<TableCell key={cell.id}>
|
||||
{cell.column.id === 'status' ? (
|
||||
<Badge variant={STATUS_VARIANT[cell.getValue<Task['status']>()]}>
|
||||
{cell.getValue<Task['status']>()}
|
||||
</Badge>
|
||||
) : (
|
||||
<table.FlexRender cell={cell} />
|
||||
)}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user