create-freakpunch 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -2
- package/bin/create-freakpunch.mjs +227 -0
- package/files/README.md +15 -0
- package/files/app.config.ts +58 -0
- package/package.json +21 -4
- package/template/.dockerignore +17 -0
- package/template/.oxlintrc.json +9 -0
- package/template/AGENTS.md +6 -0
- package/template/BACKEND.md +86 -0
- package/template/CLAUDE.md +292 -0
- package/template/Dockerfile +19 -0
- package/template/_gitignore +26 -0
- package/template/components.json +27 -0
- package/template/design/COMPONENTS.md +145 -0
- package/template/design/DESIGN.md +212 -0
- package/template/design/PATTERNS.md +110 -0
- package/template/index.html +25 -0
- package/template/nginx.conf +32 -0
- package/template/package-lock.json +6484 -0
- package/template/package.json +51 -0
- package/template/public/favicon.svg +1 -0
- package/template/public/robots.txt +2 -0
- package/template/src/app.config.ts +61 -0
- package/template/src/app.roles.ts +24 -0
- package/template/src/components/ui/alert-dialog.tsx +181 -0
- package/template/src/components/ui/avatar.tsx +116 -0
- package/template/src/components/ui/badge.tsx +57 -0
- package/template/src/components/ui/breadcrumb.tsx +130 -0
- package/template/src/components/ui/button.tsx +58 -0
- package/template/src/components/ui/calendar.tsx +277 -0
- package/template/src/components/ui/card.tsx +99 -0
- package/template/src/components/ui/chart.tsx +370 -0
- package/template/src/components/ui/checkbox.tsx +28 -0
- package/template/src/components/ui/combobox.tsx +329 -0
- package/template/src/components/ui/command.tsx +191 -0
- package/template/src/components/ui/dialog.tsx +162 -0
- package/template/src/components/ui/dropdown-menu.tsx +271 -0
- package/template/src/components/ui/empty.tsx +103 -0
- package/template/src/components/ui/field.tsx +236 -0
- package/template/src/components/ui/input-group.tsx +263 -0
- package/template/src/components/ui/input.tsx +45 -0
- package/template/src/components/ui/kbd.tsx +31 -0
- package/template/src/components/ui/label.tsx +17 -0
- package/template/src/components/ui/pagination.tsx +134 -0
- package/template/src/components/ui/popover.tsx +87 -0
- package/template/src/components/ui/radio-group.tsx +35 -0
- package/template/src/components/ui/select.tsx +204 -0
- package/template/src/components/ui/separator.tsx +25 -0
- package/template/src/components/ui/sheet.tsx +139 -0
- package/template/src/components/ui/sidebar.tsx +741 -0
- package/template/src/components/ui/skeleton.tsx +13 -0
- package/template/src/components/ui/sonner.tsx +78 -0
- package/template/src/components/ui/spinner.tsx +42 -0
- package/template/src/components/ui/switch.tsx +29 -0
- package/template/src/components/ui/table.tsx +121 -0
- package/template/src/components/ui/tabs.tsx +191 -0
- package/template/src/components/ui/textarea.tsx +17 -0
- package/template/src/components/ui/toggle-group.tsx +94 -0
- package/template/src/components/ui/toggle.tsx +48 -0
- package/template/src/components/ui/tooltip.tsx +91 -0
- package/template/src/core/api/http.ts +76 -0
- package/template/src/core/api/mock.ts +88 -0
- package/template/src/core/api/rest.ts +67 -0
- package/template/src/core/api/types.ts +21 -0
- package/template/src/core/audit/audit.service.ts +125 -0
- package/template/src/core/audit/hooks.ts +19 -0
- package/template/src/core/auth/auth-store.ts +52 -0
- package/template/src/core/auth/auth.service.ts +75 -0
- package/template/src/core/auth/can.tsx +39 -0
- package/template/src/core/auth/dev-role-switcher.tsx +64 -0
- package/template/src/core/auth/permissions.ts +115 -0
- package/template/src/core/auth/require-auth.tsx +16 -0
- package/template/src/core/auth/require-permission.tsx +24 -0
- package/template/src/core/auth/roles.ts +9 -0
- package/template/src/core/auth/types.ts +20 -0
- package/template/src/core/auth/use-auth.ts +19 -0
- package/template/src/core/company/company.service.ts +92 -0
- package/template/src/core/company/hooks.ts +40 -0
- package/template/src/core/company/password-policy.ts +40 -0
- package/template/src/core/company/types.ts +46 -0
- package/template/src/core/components/button-link.tsx +14 -0
- package/template/src/core/components/confirm-dialog.tsx +116 -0
- package/template/src/core/components/data-table/data-table.tsx +297 -0
- package/template/src/core/components/data-table/features.ts +24 -0
- package/template/src/core/components/data-table/table-header-cell.tsx +13 -0
- package/template/src/core/components/data-table/toolbar.tsx +100 -0
- package/template/src/core/components/data-table/use-list-url-state.ts +108 -0
- package/template/src/core/components/date-picker.tsx +71 -0
- package/template/src/core/components/file-attachments.tsx +84 -0
- package/template/src/core/components/form-error.tsx +9 -0
- package/template/src/core/components/form-page.tsx +93 -0
- package/template/src/core/components/image-upload.tsx +86 -0
- package/template/src/core/components/page.tsx +74 -0
- package/template/src/core/components/phone-input.tsx +58 -0
- package/template/src/core/components/search-select.tsx +57 -0
- package/template/src/core/components/segmented.tsx +41 -0
- package/template/src/core/components/states.tsx +97 -0
- package/template/src/core/components/status-badge.tsx +26 -0
- package/template/src/core/components/user-avatar.tsx +23 -0
- package/template/src/core/config/runtime.ts +14 -0
- package/template/src/core/config/types.ts +36 -0
- package/template/src/core/i18n/i18n.ts +69 -0
- package/template/src/core/i18n/i18next.d.ts +12 -0
- package/template/src/core/i18n/keys.ts +37 -0
- package/template/src/core/i18n/language-switcher.tsx +45 -0
- package/template/src/core/i18n/types.ts +17 -0
- package/template/src/core/i18n/use-format.ts +31 -0
- package/template/src/core/layout/app-shell.tsx +50 -0
- package/template/src/core/layout/app-sidebar.tsx +268 -0
- package/template/src/core/layout/command-menu.tsx +117 -0
- package/template/src/core/layout/top-bar.tsx +100 -0
- package/template/src/core/lib/csv.ts +27 -0
- package/template/src/core/lib/format.ts +87 -0
- package/template/src/core/lib/phone.ts +50 -0
- package/template/src/core/lib/storage.ts +27 -0
- package/template/src/core/modules/lazy-page.ts +9 -0
- package/template/src/core/modules/navigation.ts +39 -0
- package/template/src/core/modules/types.ts +55 -0
- package/template/src/core/notifications/hooks.ts +84 -0
- package/template/src/core/notifications/notification-center.tsx +251 -0
- package/template/src/core/notifications/notifications.service.ts +237 -0
- package/template/src/core/notifications/types.ts +65 -0
- package/template/src/core/preferences/preferences-store.ts +70 -0
- package/template/src/core/theme/brand-context.tsx +53 -0
- package/template/src/core/theme/brand.ts +29 -0
- package/template/src/core/theme/theme-context.tsx +62 -0
- package/template/src/core/theme/theme-options.ts +8 -0
- package/template/src/core/theme/theme-toggle.tsx +45 -0
- package/template/src/core/users/hooks.ts +51 -0
- package/template/src/core/users/types.ts +37 -0
- package/template/src/core/users/users.mock.ts +24 -0
- package/template/src/core/users/users.service.ts +167 -0
- package/template/src/hooks/use-mobile.ts +19 -0
- package/template/src/index.css +321 -0
- package/template/src/lib/utils.ts +1 -0
- package/template/src/locales/en/account.ts +180 -0
- package/template/src/locales/en/auth.ts +17 -0
- package/template/src/locales/en/common.ts +150 -0
- package/template/src/locales/en/company.ts +378 -0
- package/template/src/locales/en/dashboard.ts +41 -0
- package/template/src/locales/en/errors.ts +18 -0
- package/template/src/locales/en/landing.ts +15 -0
- package/template/src/locales/en/notifications.ts +43 -0
- package/template/src/locales/en/settings.ts +25 -0
- package/template/src/locales/index.ts +58 -0
- package/template/src/locales/tr/account.ts +184 -0
- package/template/src/locales/tr/auth.ts +21 -0
- package/template/src/locales/tr/common.ts +153 -0
- package/template/src/locales/tr/company.ts +382 -0
- package/template/src/locales/tr/dashboard.ts +45 -0
- package/template/src/locales/tr/errors.ts +22 -0
- package/template/src/locales/tr/landing.ts +19 -0
- package/template/src/locales/tr/notifications.ts +47 -0
- package/template/src/locales/tr/settings.ts +29 -0
- package/template/src/main.tsx +16 -0
- package/template/src/modules/locales.ts +14 -0
- package/template/src/modules/products/api/products.mock.ts +46 -0
- package/template/src/modules/products/api/products.service.ts +84 -0
- package/template/src/modules/products/components/product-status.tsx +21 -0
- package/template/src/modules/products/hooks.ts +73 -0
- package/template/src/modules/products/index.ts +50 -0
- package/template/src/modules/products/locales/en.ts +78 -0
- package/template/src/modules/products/locales/tr.ts +82 -0
- package/template/src/modules/products/pages/product-detail-page.tsx +108 -0
- package/template/src/modules/products/pages/product-form-page.tsx +211 -0
- package/template/src/modules/products/pages/products-list-page.tsx +286 -0
- package/template/src/modules/products/types.ts +61 -0
- package/template/src/modules/registry.ts +19 -0
- package/template/src/pages/dashboard/dashboard-page.tsx +270 -0
- package/template/src/pages/dashboard/dashboard.service.ts +92 -0
- package/template/src/pages/landing-page.tsx +79 -0
- package/template/src/pages/login-page.tsx +140 -0
- package/template/src/pages/no-access-page.tsx +11 -0
- package/template/src/pages/not-found-page.tsx +62 -0
- package/template/src/pages/settings/account/account.service.ts +147 -0
- package/template/src/pages/settings/account/components/mock-qr.tsx +50 -0
- package/template/src/pages/settings/account/components/password-strength.tsx +38 -0
- package/template/src/pages/settings/account/components/two-factor-dialog.tsx +140 -0
- package/template/src/pages/settings/account/hooks.ts +73 -0
- package/template/src/pages/settings/account/notifications-page.tsx +103 -0
- package/template/src/pages/settings/account/preferences-page.tsx +157 -0
- package/template/src/pages/settings/account/profile-page.tsx +242 -0
- package/template/src/pages/settings/account/security-page.tsx +364 -0
- package/template/src/pages/settings/account/types.ts +37 -0
- package/template/src/pages/settings/company/audit-log-page.tsx +126 -0
- package/template/src/pages/settings/company/branding-page.tsx +278 -0
- package/template/src/pages/settings/company/components/invite-dialog.tsx +106 -0
- package/template/src/pages/settings/company/components/read-only-notice.tsx +13 -0
- package/template/src/pages/settings/company/danger-zone-page.tsx +127 -0
- package/template/src/pages/settings/company/general-page.tsx +232 -0
- package/template/src/pages/settings/company/integrations/api-keys-panel.tsx +170 -0
- package/template/src/pages/settings/company/integrations/hooks.ts +37 -0
- package/template/src/pages/settings/company/integrations/integrations-page.tsx +57 -0
- package/template/src/pages/settings/company/integrations/integrations.service.ts +173 -0
- package/template/src/pages/settings/company/integrations/settings-forms.tsx +299 -0
- package/template/src/pages/settings/company/integrations/webhooks-panel.tsx +179 -0
- package/template/src/pages/settings/company/modules-page.tsx +57 -0
- package/template/src/pages/settings/company/roles-page.tsx +115 -0
- package/template/src/pages/settings/company/security-policies-page.tsx +164 -0
- package/template/src/pages/settings/company/users-page.tsx +262 -0
- package/template/src/pages/settings/settings-layout.tsx +57 -0
- package/template/src/pages/settings/settings-nav.ts +69 -0
- package/template/src/pages/settings/settings-routes.tsx +49 -0
- package/template/src/providers.tsx +68 -0
- package/template/src/router.tsx +54 -0
- package/template/tools/check-design.mjs +73 -0
- package/template/tools/new-module.mjs +90 -0
- package/template/tools/templates/module/api/__id__.mock.ts.tpl +17 -0
- package/template/tools/templates/module/api/__id__.service.ts.tpl +51 -0
- package/template/tools/templates/module/hooks.ts.tpl +57 -0
- package/template/tools/templates/module/index.ts.tpl +37 -0
- package/template/tools/templates/module/locales/en.ts.tpl +45 -0
- package/template/tools/templates/module/locales/tr.ts.tpl +49 -0
- package/template/tools/templates/module/pages/__id__-form-page.tsx.tpl +121 -0
- package/template/tools/templates/module/pages/__id__-list-page.tsx.tpl +237 -0
- package/template/tools/templates/module/types.ts.tpl +32 -0
- package/template/tsconfig.app.json +32 -0
- package/template/tsconfig.json +12 -0
- package/template/tsconfig.node.json +23 -0
- package/template/vite.config.ts +44 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { Trans, useTranslation } from 'react-i18next'
|
|
3
|
+
import { Link } from 'react-router'
|
|
4
|
+
import { Area, AreaChart, CartesianGrid, Line, LineChart, XAxis, YAxis } from 'recharts'
|
|
5
|
+
import { ArrowDownRight, ArrowRight, ArrowUpRight } from 'lucide-react'
|
|
6
|
+
|
|
7
|
+
import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from '@/components/ui/chart'
|
|
8
|
+
import { Skeleton } from '@/components/ui/skeleton'
|
|
9
|
+
import { usePermissions } from '@/core/auth/can'
|
|
10
|
+
import { useAuth } from '@/core/auth/use-auth'
|
|
11
|
+
import { isFeatureOn } from '@/core/config/runtime'
|
|
12
|
+
import { Page, Panel } from '@/core/components/page'
|
|
13
|
+
import { Segmented } from '@/core/components/segmented'
|
|
14
|
+
import { ErrorState } from '@/core/components/states'
|
|
15
|
+
import { StatusDot } from '@/core/components/status-badge'
|
|
16
|
+
import { useAnyT } from '@/core/i18n/keys'
|
|
17
|
+
import { useFormat } from '@/core/i18n/use-format'
|
|
18
|
+
import type { Formatters } from '@/core/lib/format'
|
|
19
|
+
import { quickActions } from '@/core/modules/navigation'
|
|
20
|
+
import { cn } from '@/lib/utils'
|
|
21
|
+
import { enabledModules } from '@/modules/registry'
|
|
22
|
+
import { rangeDays, useActivity, useKpis, useRevenue, type Activity, type Kpi, type Range } from './dashboard.service'
|
|
23
|
+
|
|
24
|
+
const ranges = ['7d', '30d', '90d'] as const
|
|
25
|
+
const moduleWidgets = enabledModules.flatMap((m) => m.dashboardWidgets ?? [])
|
|
26
|
+
const demoCards = isFeatureOn('demoDashboard')
|
|
27
|
+
|
|
28
|
+
function formatKpi(kpi: Kpi, fmt: Formatters) {
|
|
29
|
+
if (kpi.format === 'currency') return fmt.currencyWhole(kpi.value)
|
|
30
|
+
if (kpi.format === 'percent') return fmt.percent(kpi.value)
|
|
31
|
+
return fmt.number(kpi.value)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function greetingKey() {
|
|
35
|
+
const h = new Date().getHours()
|
|
36
|
+
return h < 12 ? 'greeting.morning' : h < 18 ? 'greeting.afternoon' : 'greeting.evening'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default function DashboardPage() {
|
|
40
|
+
const [range, setRange] = useState<Range>('30d')
|
|
41
|
+
const { user } = useAuth()
|
|
42
|
+
const { t } = useTranslation(['dashboard', 'common'])
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Page
|
|
46
|
+
title={t(greetingKey(), { name: user?.firstName || t('greeting.fallbackName') })}
|
|
47
|
+
documentTitle={t('common:nav.dashboard')}
|
|
48
|
+
description={t('description')}
|
|
49
|
+
actions={
|
|
50
|
+
demoCards && (
|
|
51
|
+
<Segmented
|
|
52
|
+
label={t('range.label')}
|
|
53
|
+
value={range}
|
|
54
|
+
onChange={setRange}
|
|
55
|
+
options={ranges.map((r) => ({ value: r, label: t(`range.${r}`) }))}
|
|
56
|
+
/>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
>
|
|
60
|
+
{demoCards && <KpiGrid range={range} />}
|
|
61
|
+
{moduleWidgets.map((Widget, i) => (
|
|
62
|
+
<Widget key={i} />
|
|
63
|
+
))}
|
|
64
|
+
{demoCards ? (
|
|
65
|
+
<>
|
|
66
|
+
<div className="grid gap-4 xl:grid-cols-3">
|
|
67
|
+
<RevenueCard range={range} className="xl:col-span-2" />
|
|
68
|
+
<QuickActionsCard />
|
|
69
|
+
</div>
|
|
70
|
+
<ActivityCard />
|
|
71
|
+
</>
|
|
72
|
+
) : (
|
|
73
|
+
<QuickActionsCard />
|
|
74
|
+
)}
|
|
75
|
+
</Page>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function KpiGrid({ range }: { range: Range }) {
|
|
80
|
+
const { data, isPending, error, refetch } = useKpis(range)
|
|
81
|
+
if (error) return <ErrorState error={error} onRetry={() => refetch()} />
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
|
85
|
+
{isPending
|
|
86
|
+
? Array.from({ length: 4 }, (_, i) => <Skeleton key={i} className="h-[7.5rem] rounded-xl" />)
|
|
87
|
+
: data.map((kpi) => <KpiCard key={kpi.id} kpi={kpi} />)}
|
|
88
|
+
</div>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function KpiCard({ kpi }: { kpi: Kpi }) {
|
|
93
|
+
const { t } = useTranslation(['dashboard', 'common'])
|
|
94
|
+
const fmt = useFormat()
|
|
95
|
+
const up = kpi.change >= 0
|
|
96
|
+
const spark = kpi.spark.map((v, i) => ({ i, v }))
|
|
97
|
+
return (
|
|
98
|
+
<div className="flex flex-col gap-3 rounded-xl border bg-card p-4 shadow-(--shadow-card)">
|
|
99
|
+
<div className="flex items-center justify-between">
|
|
100
|
+
<span className="label-caps">{t(`kpis.${kpi.id}`)}</span>
|
|
101
|
+
<span
|
|
102
|
+
className={cn(
|
|
103
|
+
'inline-flex items-center gap-0.5 text-[11px] tabular-nums',
|
|
104
|
+
up ? 'text-success' : 'text-danger',
|
|
105
|
+
)}
|
|
106
|
+
>
|
|
107
|
+
{up ? <ArrowUpRight className="size-3" /> : <ArrowDownRight className="size-3" />}
|
|
108
|
+
{fmt.delta(kpi.change)}
|
|
109
|
+
</span>
|
|
110
|
+
</div>
|
|
111
|
+
<div className="flex items-end justify-between gap-3">
|
|
112
|
+
<span className="text-2xl font-semibold tracking-tight tabular-nums">{formatKpi(kpi, fmt)}</span>
|
|
113
|
+
<div className="h-8 w-20" aria-hidden>
|
|
114
|
+
<ChartContainer config={{ v: { color: 'var(--muted-foreground)' } }} className="aspect-auto h-8 w-20">
|
|
115
|
+
<LineChart data={spark}>
|
|
116
|
+
<Line dataKey="v" type="monotone" stroke="var(--color-v)" strokeWidth={1.5} dot={false} isAnimationActive={false} />
|
|
117
|
+
</LineChart>
|
|
118
|
+
</ChartContainer>
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function RevenueCard({ range, className }: { range: Range; className?: string }) {
|
|
126
|
+
const { data, isPending, error, refetch } = useRevenue(range)
|
|
127
|
+
const { t } = useTranslation(['dashboard', 'common'])
|
|
128
|
+
const fmt = useFormat()
|
|
129
|
+
const total = data?.reduce((s, p) => s + p.revenue, 0) ?? 0
|
|
130
|
+
const chartConfig = { revenue: { label: t('kpis.revenue'), color: 'var(--chart-1)' } } satisfies ChartConfig
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<Panel label={t('panels.revenue')} className={className} bodyClassName="p-4">
|
|
134
|
+
{error ? (
|
|
135
|
+
<ErrorState error={error} onRetry={() => refetch()} />
|
|
136
|
+
) : (
|
|
137
|
+
<>
|
|
138
|
+
<div className="mb-4 flex items-baseline gap-2">
|
|
139
|
+
{isPending ? (
|
|
140
|
+
<Skeleton className="h-8 w-32" />
|
|
141
|
+
) : (
|
|
142
|
+
<span className="text-2xl font-semibold tracking-tight tabular-nums">{fmt.currency(total)}</span>
|
|
143
|
+
)}
|
|
144
|
+
<span className="text-xs text-muted-foreground">{t('range.last', { count: rangeDays[range] })}</span>
|
|
145
|
+
</div>
|
|
146
|
+
{isPending ? (
|
|
147
|
+
<Skeleton className="h-64 w-full rounded-lg" />
|
|
148
|
+
) : (
|
|
149
|
+
<ChartContainer config={chartConfig} className="aspect-auto h-64 w-full">
|
|
150
|
+
<AreaChart data={data} margin={{ left: 0, right: 4, top: 4 }}>
|
|
151
|
+
<defs>
|
|
152
|
+
<linearGradient id="fill-revenue" x1="0" y1="0" x2="0" y2="1">
|
|
153
|
+
<stop offset="0%" stopColor="var(--color-revenue)" stopOpacity={0.22} />
|
|
154
|
+
<stop offset="100%" stopColor="var(--color-revenue)" stopOpacity={0} />
|
|
155
|
+
</linearGradient>
|
|
156
|
+
</defs>
|
|
157
|
+
<CartesianGrid vertical={false} strokeDasharray="3 3" />
|
|
158
|
+
<XAxis
|
|
159
|
+
dataKey="date"
|
|
160
|
+
tickLine={false}
|
|
161
|
+
axisLine={false}
|
|
162
|
+
tickMargin={8}
|
|
163
|
+
minTickGap={28}
|
|
164
|
+
tickFormatter={(d: string) => fmt.dayMonth(d)}
|
|
165
|
+
/>
|
|
166
|
+
<YAxis tickLine={false} axisLine={false} width={52} tickFormatter={(v: number) => fmt.compactCurrency(v)} />
|
|
167
|
+
<ChartTooltip
|
|
168
|
+
cursor={{ stroke: 'var(--border)' }}
|
|
169
|
+
content={
|
|
170
|
+
<ChartTooltipContent
|
|
171
|
+
labelFormatter={(d) => fmt.weekdayDayMonth(String(d))}
|
|
172
|
+
formatter={(v) => (
|
|
173
|
+
<span className="font-medium tabular-nums">{fmt.currency(Number(v))}</span>
|
|
174
|
+
)}
|
|
175
|
+
/>
|
|
176
|
+
}
|
|
177
|
+
/>
|
|
178
|
+
<Area
|
|
179
|
+
dataKey="revenue"
|
|
180
|
+
type="monotone"
|
|
181
|
+
stroke="var(--color-revenue)"
|
|
182
|
+
strokeWidth={2}
|
|
183
|
+
fill="url(#fill-revenue)"
|
|
184
|
+
/>
|
|
185
|
+
</AreaChart>
|
|
186
|
+
</ChartContainer>
|
|
187
|
+
)}
|
|
188
|
+
</>
|
|
189
|
+
)}
|
|
190
|
+
</Panel>
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function QuickActionsCard() {
|
|
195
|
+
const t = useAnyT()
|
|
196
|
+
const { can } = usePermissions()
|
|
197
|
+
return (
|
|
198
|
+
<Panel label={t('dashboard:panels.quickActions')} bodyClassName="p-2">
|
|
199
|
+
<ul className="flex flex-col gap-0.5">
|
|
200
|
+
{quickActions
|
|
201
|
+
.filter((a) => !a.permission || can(a.permission))
|
|
202
|
+
.map(({ path, label, description, icon: Icon }) => (
|
|
203
|
+
<li key={path}>
|
|
204
|
+
<Link
|
|
205
|
+
to={path}
|
|
206
|
+
className="group flex items-center gap-3 rounded-lg p-2 outline-none hover:bg-fill-1 focus-visible:ring-2 focus-visible:ring-ring/40"
|
|
207
|
+
>
|
|
208
|
+
<span className="flex size-9 shrink-0 items-center justify-center rounded-lg border bg-raised text-muted-foreground shadow-(--shadow-raised) group-hover:text-primary">
|
|
209
|
+
<Icon className="size-4" />
|
|
210
|
+
</span>
|
|
211
|
+
<span className="min-w-0 flex-1">
|
|
212
|
+
<span className="block text-sm font-medium">{t(label)}</span>
|
|
213
|
+
{description && <span className="block truncate text-xs text-muted-foreground">{t(description)}</span>}
|
|
214
|
+
</span>
|
|
215
|
+
<ArrowRight className="size-4 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100" />
|
|
216
|
+
</Link>
|
|
217
|
+
</li>
|
|
218
|
+
))}
|
|
219
|
+
</ul>
|
|
220
|
+
</Panel>
|
|
221
|
+
)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function ActivityCard() {
|
|
225
|
+
const { data, isPending, error, refetch } = useActivity()
|
|
226
|
+
const { t } = useTranslation(['dashboard', 'common'])
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<Panel label={t('panels.activity')}>
|
|
230
|
+
{error ? (
|
|
231
|
+
<ErrorState error={error} onRetry={() => refetch()} />
|
|
232
|
+
) : (
|
|
233
|
+
<ul className="divide-y">
|
|
234
|
+
{isPending
|
|
235
|
+
? Array.from({ length: 5 }, (_, i) => (
|
|
236
|
+
<li key={i} className="flex items-center gap-3 px-4 py-3">
|
|
237
|
+
<Skeleton className="size-1.5 rounded-full" />
|
|
238
|
+
<Skeleton className="h-4 flex-1" />
|
|
239
|
+
</li>
|
|
240
|
+
))
|
|
241
|
+
: data.map((a) => <ActivityRow key={a.id} activity={a} />)}
|
|
242
|
+
</ul>
|
|
243
|
+
)}
|
|
244
|
+
</Panel>
|
|
245
|
+
)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function ActivityRow({ activity: a }: { activity: Activity }) {
|
|
249
|
+
const { t } = useTranslation(['dashboard', 'common'])
|
|
250
|
+
const fmt = useFormat()
|
|
251
|
+
const actor = a.actor === 'system' ? t('activity.system') : a.actor === 'payments' ? t('activity.payments') : a.actor
|
|
252
|
+
const target = a.amount === undefined ? a.target : `${a.target} · ${fmt.currency(a.amount)}`
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
<li className="flex items-center gap-3 px-4 py-3 text-sm">
|
|
256
|
+
<StatusDot tone={a.tone} />
|
|
257
|
+
<p className="min-w-0 flex-1 truncate text-muted-foreground">
|
|
258
|
+
<Trans
|
|
259
|
+
t={t}
|
|
260
|
+
i18nKey={`activity.${a.kind}`}
|
|
261
|
+
values={{ actor, target }}
|
|
262
|
+
components={{ b: <span className="font-medium text-foreground" /> }}
|
|
263
|
+
/>
|
|
264
|
+
</p>
|
|
265
|
+
<time dateTime={a.at} className="shrink-0 tabular-nums text-[11px] text-muted-foreground">
|
|
266
|
+
{fmt.relative(a.at)}
|
|
267
|
+
</time>
|
|
268
|
+
</li>
|
|
269
|
+
)
|
|
270
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
|
|
3
|
+
import { delay, seededRandom } from '@/core/api/mock'
|
|
4
|
+
|
|
5
|
+
export type Range = '7d' | '30d' | '90d'
|
|
6
|
+
|
|
7
|
+
export type KpiId = 'revenue' | 'orders' | 'customers' | 'conversion'
|
|
8
|
+
|
|
9
|
+
export type Kpi = {
|
|
10
|
+
/** Label comes from `dashboard:kpis.<id>`. */
|
|
11
|
+
id: KpiId
|
|
12
|
+
value: number
|
|
13
|
+
format: 'currency' | 'number' | 'percent'
|
|
14
|
+
/** Change vs previous period, in percent. */
|
|
15
|
+
change: number
|
|
16
|
+
spark: number[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type RevenuePoint = { date: string; revenue: number; orders: number }
|
|
20
|
+
|
|
21
|
+
/** Event kinds map to `dashboard:activity.<kind>` sentences. */
|
|
22
|
+
export type ActivityKind = 'orderPlaced' | 'lowStock' | 'updated' | 'refund' | 'published'
|
|
23
|
+
|
|
24
|
+
export type Activity = {
|
|
25
|
+
id: string
|
|
26
|
+
/** A person's name, or `system` / `payments` for automated events. */
|
|
27
|
+
actor: string
|
|
28
|
+
kind: ActivityKind
|
|
29
|
+
target: string
|
|
30
|
+
/** Order amount; formatted in the active locale and appended to the target. */
|
|
31
|
+
amount?: number
|
|
32
|
+
at: string
|
|
33
|
+
tone: 'success' | 'warning' | 'danger' | 'info' | 'neutral'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface DashboardService {
|
|
37
|
+
kpis(range: Range): Promise<Kpi[]>
|
|
38
|
+
revenue(range: Range): Promise<RevenuePoint[]>
|
|
39
|
+
activity(): Promise<Activity[]>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const rangeDays: Record<Range, number> = { '7d': 7, '30d': 30, '90d': 90 }
|
|
43
|
+
|
|
44
|
+
function series(n: number, seed: number) {
|
|
45
|
+
const rand = seededRandom(seed)
|
|
46
|
+
let v = 3200
|
|
47
|
+
return Array.from({ length: n }, (_, i) => {
|
|
48
|
+
v = Math.max(1200, v + (rand() - 0.42) * 600)
|
|
49
|
+
const date = new Date(Date.now() - (n - 1 - i) * 86_400_000)
|
|
50
|
+
return { date: date.toISOString().slice(0, 10), revenue: Math.round(v), orders: Math.round(v / (38 + rand() * 12)) }
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const mockDashboardService: DashboardService = {
|
|
55
|
+
async kpis(range) {
|
|
56
|
+
await delay()
|
|
57
|
+
const pts = series(rangeDays[range], 7)
|
|
58
|
+
const revenue = pts.reduce((s, p) => s + p.revenue, 0)
|
|
59
|
+
const orders = pts.reduce((s, p) => s + p.orders, 0)
|
|
60
|
+
const scale = rangeDays[range] / 30
|
|
61
|
+
return [
|
|
62
|
+
{ id: 'revenue', value: revenue, format: 'currency', change: 12.4, spark: pts.map((p) => p.revenue) },
|
|
63
|
+
{ id: 'orders', value: orders, format: 'number', change: 8.1, spark: pts.map((p) => p.orders) },
|
|
64
|
+
{ id: 'customers', value: Math.round(412 * scale), format: 'number', change: -2.3, spark: pts.map((p) => p.orders * 0.4) },
|
|
65
|
+
{ id: 'conversion', value: 3.42, format: 'percent', change: 0.6, spark: pts.map((p) => p.revenue / p.orders) },
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
async revenue(range) {
|
|
69
|
+
await delay()
|
|
70
|
+
return series(rangeDays[range], 7)
|
|
71
|
+
},
|
|
72
|
+
async activity() {
|
|
73
|
+
await delay()
|
|
74
|
+
const ago = (min: number) => new Date(Date.now() - min * 60_000).toISOString()
|
|
75
|
+
return [
|
|
76
|
+
{ id: 'a1', actor: 'Maya Chen', kind: 'orderPlaced', target: '#10482', amount: 284, at: ago(4), tone: 'success' },
|
|
77
|
+
{ id: 'a2', actor: 'system', kind: 'lowStock', target: 'Halo Pendant', at: ago(26), tone: 'warning' },
|
|
78
|
+
{ id: 'a3', actor: 'Jonas Weber', kind: 'updated', target: 'Oak Side Table', at: ago(58), tone: 'info' },
|
|
79
|
+
{ id: 'a4', actor: 'payments', kind: 'refund', target: '#10467', amount: 79, at: ago(140), tone: 'danger' },
|
|
80
|
+
{ id: 'a5', actor: 'Ana Lopez', kind: 'published', target: 'Linen Cushion Natural', at: ago(310), tone: 'neutral' },
|
|
81
|
+
{ id: 'a6', actor: 'Maya Chen', kind: 'orderPlaced', target: '#10461', amount: 1120, at: ago(620), tone: 'success' },
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const dashboardService: DashboardService = mockDashboardService
|
|
87
|
+
|
|
88
|
+
export const useKpis = (range: Range) =>
|
|
89
|
+
useQuery({ queryKey: ['dashboard', 'kpis', range], queryFn: () => dashboardService.kpis(range) })
|
|
90
|
+
export const useRevenue = (range: Range) =>
|
|
91
|
+
useQuery({ queryKey: ['dashboard', 'revenue', range], queryFn: () => dashboardService.revenue(range) })
|
|
92
|
+
export const useActivity = () => useQuery({ queryKey: ['dashboard', 'activity'], queryFn: () => dashboardService.activity() })
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useEffect } from 'react'
|
|
2
|
+
import { useTranslation } from 'react-i18next'
|
|
3
|
+
import { ArrowRight, Boxes, Gauge, Palette } from 'lucide-react'
|
|
4
|
+
|
|
5
|
+
import { appConfig } from '@/app.config'
|
|
6
|
+
import { useSession } from '@/core/auth/use-auth'
|
|
7
|
+
import { ButtonLink } from '@/core/components/button-link'
|
|
8
|
+
import { LanguageSwitcher } from '@/core/i18n/language-switcher'
|
|
9
|
+
import { ThemeToggle } from '@/core/theme/theme-toggle'
|
|
10
|
+
|
|
11
|
+
const YEAR = new Date().getFullYear()
|
|
12
|
+
|
|
13
|
+
const features = [
|
|
14
|
+
{ id: 'modular', icon: Boxes },
|
|
15
|
+
{ id: 'tokens', icon: Palette },
|
|
16
|
+
{ id: 'api', icon: Gauge },
|
|
17
|
+
] as const
|
|
18
|
+
|
|
19
|
+
export default function LandingPage() {
|
|
20
|
+
const session = useSession()
|
|
21
|
+
const { t } = useTranslation(['landing', 'common'])
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
document.title = appConfig.name
|
|
25
|
+
}, [])
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div className="flex min-h-svh flex-col bg-canvas">
|
|
29
|
+
<header className="mx-auto flex h-16 w-full max-w-5xl items-center justify-between px-6">
|
|
30
|
+
<span className="flex items-center gap-2 text-[15px] font-semibold tracking-tight">
|
|
31
|
+
<span className="flex size-7 items-center justify-center rounded-lg bg-foreground text-xs text-background">
|
|
32
|
+
{appConfig.name[0]?.toUpperCase()}
|
|
33
|
+
</span>
|
|
34
|
+
{appConfig.name}
|
|
35
|
+
</span>
|
|
36
|
+
<div className="flex items-center gap-1.5">
|
|
37
|
+
<LanguageSwitcher />
|
|
38
|
+
<ThemeToggle />
|
|
39
|
+
<ButtonLink to={session ? '/app' : '/login'} variant="outline" size="sm">
|
|
40
|
+
{session ? t('openApp') : t('signIn')}
|
|
41
|
+
</ButtonLink>
|
|
42
|
+
</div>
|
|
43
|
+
</header>
|
|
44
|
+
|
|
45
|
+
<main className="flex flex-1 flex-col items-center justify-center px-6 py-20 text-center">
|
|
46
|
+
<span className="label-caps mb-6 inline-flex items-center gap-2 rounded-full border bg-raised px-3 py-1 shadow-(--shadow-raised)">
|
|
47
|
+
<span className="size-1.5 rounded-full bg-primary" />
|
|
48
|
+
{t('common:app.tagline')}
|
|
49
|
+
</span>
|
|
50
|
+
<h1 className="max-w-2xl text-5xl font-semibold tracking-tight text-balance sm:text-6xl">
|
|
51
|
+
{t('headline')}
|
|
52
|
+
<br />
|
|
53
|
+
<span className="text-muted-foreground">{t('headlineMuted')}</span>
|
|
54
|
+
</h1>
|
|
55
|
+
<p className="mt-5 max-w-lg text-base leading-relaxed text-pretty text-muted-foreground sm:text-lg">{t('lead')}</p>
|
|
56
|
+
<div className="mt-9 flex items-center gap-3">
|
|
57
|
+
<ButtonLink to={session ? '/app' : '/login'} size="xl" className="rounded-full px-5">
|
|
58
|
+
{session ? t('openDashboard') : t('signIn')}
|
|
59
|
+
<ArrowRight data-icon="inline-end" />
|
|
60
|
+
</ButtonLink>
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<ul className="mt-20 grid w-full max-w-4xl gap-4 text-left sm:grid-cols-3">
|
|
64
|
+
{features.map(({ id, icon: Icon }) => (
|
|
65
|
+
<li key={id} className="rounded-xl border bg-card p-5 shadow-(--shadow-card)">
|
|
66
|
+
<Icon className="size-5 text-primary" strokeWidth={1.75} />
|
|
67
|
+
<h2 className="mt-4 text-sm font-medium">{t(`features.${id}.title`)}</h2>
|
|
68
|
+
<p className="mt-1 text-sm text-muted-foreground">{t(`features.${id}.text`)}</p>
|
|
69
|
+
</li>
|
|
70
|
+
))}
|
|
71
|
+
</ul>
|
|
72
|
+
</main>
|
|
73
|
+
|
|
74
|
+
<footer className="mx-auto w-full max-w-5xl px-6 py-8 tabular-nums text-[11px] text-muted-foreground">
|
|
75
|
+
{t('copyright', { year: YEAR, name: appConfig.name })}
|
|
76
|
+
</footer>
|
|
77
|
+
</div>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { useEffect } from 'react'
|
|
2
|
+
import { useForm } from 'react-hook-form'
|
|
3
|
+
import { zodResolver } from '@hookform/resolvers/zod'
|
|
4
|
+
import { useTranslation } from 'react-i18next'
|
|
5
|
+
import { Navigate, useNavigate, useSearchParams } from 'react-router'
|
|
6
|
+
import { toast } from 'sonner'
|
|
7
|
+
import { z } from 'zod'
|
|
8
|
+
|
|
9
|
+
import { Button } from '@/components/ui/button'
|
|
10
|
+
import { Card, CardContent } from '@/components/ui/card'
|
|
11
|
+
import { Field, FieldDescription, FieldGroup, FieldLabel } from '@/components/ui/field'
|
|
12
|
+
import { Input } from '@/components/ui/input'
|
|
13
|
+
import { Spinner } from '@/components/ui/spinner'
|
|
14
|
+
import { appConfig } from '@/app.config'
|
|
15
|
+
import { ApiError } from '@/core/api/http'
|
|
16
|
+
import { useAuth } from '@/core/auth/use-auth'
|
|
17
|
+
import { authMode } from '@/core/config/runtime'
|
|
18
|
+
import { FormFieldError } from '@/core/components/form-error'
|
|
19
|
+
import { LanguageSwitcher } from '@/core/i18n/language-switcher'
|
|
20
|
+
import { vmsg } from '@/core/i18n/keys'
|
|
21
|
+
import { ThemeToggle } from '@/core/theme/theme-toggle'
|
|
22
|
+
|
|
23
|
+
const schema = z.object({
|
|
24
|
+
email: z.email(vmsg('validation.email')),
|
|
25
|
+
password: z.string().min(1, vmsg('auth:signIn.passwordRequired')),
|
|
26
|
+
})
|
|
27
|
+
type Values = z.infer<typeof schema>
|
|
28
|
+
|
|
29
|
+
/** Only allow same-app redirects (no open redirect via ?redirect=https://…). */
|
|
30
|
+
function safeRedirect(value: string | null) {
|
|
31
|
+
return value && value.startsWith('/app') ? value : '/app'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default function LoginPage() {
|
|
35
|
+
const { isAuthenticated, login } = useAuth()
|
|
36
|
+
const [params] = useSearchParams()
|
|
37
|
+
const navigate = useNavigate()
|
|
38
|
+
const redirect = safeRedirect(params.get('redirect'))
|
|
39
|
+
const { t } = useTranslation('auth')
|
|
40
|
+
|
|
41
|
+
const { register, handleSubmit, formState } = useForm<Values>({
|
|
42
|
+
resolver: zodResolver(schema),
|
|
43
|
+
defaultValues: { email: 'owner@freakpunch.site', password: '' },
|
|
44
|
+
})
|
|
45
|
+
const { errors, isSubmitting } = formState
|
|
46
|
+
|
|
47
|
+
const title = t('signIn.title')
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
document.title = `${title} · ${appConfig.name}`
|
|
50
|
+
}, [title])
|
|
51
|
+
|
|
52
|
+
if (isAuthenticated && !isSubmitting) return <Navigate to={redirect} replace />
|
|
53
|
+
|
|
54
|
+
const onSubmit = handleSubmit(async (values) => {
|
|
55
|
+
try {
|
|
56
|
+
const session = await login(values)
|
|
57
|
+
toast.success(t('signIn.welcome', { name: session.user.firstName }))
|
|
58
|
+
navigate(redirect, { replace: true })
|
|
59
|
+
} catch (e) {
|
|
60
|
+
const inactive = e instanceof ApiError && e.status === 403
|
|
61
|
+
toast.error(t('signIn.failed'), { description: inactive ? t('signIn.inactive') : e instanceof Error ? e.message : undefined })
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
// Equal 1fr rows above and below keep the card exactly centered; the demo note sits in the bottom row.
|
|
67
|
+
<div className="relative grid min-h-svh grid-rows-[1fr_auto_1fr] justify-items-center bg-canvas px-4 py-10 md:px-10">
|
|
68
|
+
<div className="absolute top-3 right-3 flex items-center gap-1.5 sm:top-4 sm:right-4">
|
|
69
|
+
<LanguageSwitcher />
|
|
70
|
+
<ThemeToggle />
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
<Card className="row-start-2 w-full max-w-sm gap-0 rounded-(--radius-panel) py-0 shadow-(--shadow-panel) md:max-w-4xl">
|
|
74
|
+
<CardContent className="grid p-0 md:grid-cols-2">
|
|
75
|
+
<form onSubmit={onSubmit} noValidate className="p-6 sm:p-8 md:p-10">
|
|
76
|
+
<FieldGroup className="gap-4">
|
|
77
|
+
<div className="mb-2 flex flex-col items-center gap-2 text-center">
|
|
78
|
+
<h1 className="text-2xl font-semibold tracking-tight">{t('signIn.heading')}</h1>
|
|
79
|
+
<p className="text-sm text-balance text-muted-foreground">
|
|
80
|
+
{t('signIn.description', { name: appConfig.name })}
|
|
81
|
+
</p>
|
|
82
|
+
</div>
|
|
83
|
+
<Field data-invalid={!!errors.email}>
|
|
84
|
+
<FieldLabel htmlFor="email">{t('signIn.email')}</FieldLabel>
|
|
85
|
+
<Input
|
|
86
|
+
id="email"
|
|
87
|
+
type="email"
|
|
88
|
+
autoComplete="email"
|
|
89
|
+
size="lg"
|
|
90
|
+
aria-invalid={!!errors.email}
|
|
91
|
+
{...register('email')}
|
|
92
|
+
/>
|
|
93
|
+
<FormFieldError error={errors.email} />
|
|
94
|
+
</Field>
|
|
95
|
+
<Field data-invalid={!!errors.password}>
|
|
96
|
+
<FieldLabel htmlFor="password">{t('signIn.password')}</FieldLabel>
|
|
97
|
+
<Input
|
|
98
|
+
id="password"
|
|
99
|
+
type="password"
|
|
100
|
+
autoComplete="current-password"
|
|
101
|
+
autoFocus
|
|
102
|
+
size="lg"
|
|
103
|
+
aria-invalid={!!errors.password}
|
|
104
|
+
{...register('password')}
|
|
105
|
+
/>
|
|
106
|
+
<FormFieldError error={errors.password} />
|
|
107
|
+
</Field>
|
|
108
|
+
<Button type="submit" size="lg" className="mt-2 w-full" disabled={isSubmitting}>
|
|
109
|
+
{isSubmitting && <Spinner data-icon="inline-start" />}
|
|
110
|
+
{t('signIn.submit')}
|
|
111
|
+
</Button>
|
|
112
|
+
<FieldDescription className="text-center">{t('signIn.invitationOnly')}</FieldDescription>
|
|
113
|
+
</FieldGroup>
|
|
114
|
+
</form>
|
|
115
|
+
<BrandPanel />
|
|
116
|
+
</CardContent>
|
|
117
|
+
</Card>
|
|
118
|
+
|
|
119
|
+
{authMode === 'mock' && (
|
|
120
|
+
<p className="row-start-3 max-w-sm self-end pt-4 text-center text-xs text-balance text-muted-foreground md:max-w-md">
|
|
121
|
+
{t('signIn.demo')}
|
|
122
|
+
</p>
|
|
123
|
+
)}
|
|
124
|
+
</div>
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Image side of the split card: a neutral, token-only placeholder (no stock photo). Hidden on mobile. */
|
|
129
|
+
function BrandPanel() {
|
|
130
|
+
return (
|
|
131
|
+
<div aria-hidden className="relative hidden items-center justify-center overflow-hidden border-l bg-fill-1 md:flex">
|
|
132
|
+
<div className="absolute inset-0 bg-[radial-gradient(var(--border)_1px,transparent_1px)] bg-size-[16px_16px] mask-[radial-gradient(ellipse_at_center,black_30%,transparent_75%)]" />
|
|
133
|
+
<div className="relative flex size-24 items-center justify-center rounded-(--radius-panel) bg-raised shadow-(--shadow-raised) ring-1 ring-border">
|
|
134
|
+
<span className="flex size-12 items-center justify-center rounded-xl bg-foreground text-xl font-semibold text-background">
|
|
135
|
+
{appConfig.name[0]?.toUpperCase()}
|
|
136
|
+
</span>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next'
|
|
2
|
+
|
|
3
|
+
import { Message } from './not-found-page'
|
|
4
|
+
|
|
5
|
+
/** Shown (inside the app panel) when a route guard denies access. */
|
|
6
|
+
export default function NoAccessPage() {
|
|
7
|
+
const { t } = useTranslation('errors')
|
|
8
|
+
return (
|
|
9
|
+
<Message code={t('noAccess.code')} title={t('noAccess.title')} description={t('noAccess.description')} inset />
|
|
10
|
+
)
|
|
11
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useEffect } from 'react'
|
|
2
|
+
import { useTranslation } from 'react-i18next'
|
|
3
|
+
import { isRouteErrorResponse, useRouteError } from 'react-router'
|
|
4
|
+
import { ArrowLeft } from 'lucide-react'
|
|
5
|
+
|
|
6
|
+
import { appConfig } from '@/app.config'
|
|
7
|
+
import { ButtonLink } from '@/core/components/button-link'
|
|
8
|
+
import { cn } from '@/lib/utils'
|
|
9
|
+
|
|
10
|
+
/** Centered full-page message: 404, unexpected error, no access. */
|
|
11
|
+
export function Message({
|
|
12
|
+
code,
|
|
13
|
+
title,
|
|
14
|
+
description,
|
|
15
|
+
inset,
|
|
16
|
+
}: {
|
|
17
|
+
code: string
|
|
18
|
+
title: string
|
|
19
|
+
description: string
|
|
20
|
+
inset?: boolean
|
|
21
|
+
}) {
|
|
22
|
+
const { t } = useTranslation()
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
document.title = `${title} · ${appConfig.name}`
|
|
26
|
+
}, [title])
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div className={cn('flex flex-col items-center justify-center px-6 text-center', inset ? 'py-24' : 'min-h-svh bg-canvas')}>
|
|
30
|
+
<span className="label-caps">{code}</span>
|
|
31
|
+
<h1 className="mt-3 text-3xl font-semibold tracking-tight">{title}</h1>
|
|
32
|
+
<p className="mt-2 max-w-sm text-sm text-muted-foreground">{description}</p>
|
|
33
|
+
<ButtonLink to={inset ? '/app' : '/'} variant="outline" className="mt-8">
|
|
34
|
+
<ArrowLeft data-icon="inline-start" />
|
|
35
|
+
{inset ? t('actions.backToDashboard') : t('actions.backHome')}
|
|
36
|
+
</ButtonLink>
|
|
37
|
+
</div>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 404. `inset` renders it inside the app panel instead of full screen. */
|
|
42
|
+
export default function NotFoundPage({ inset }: { inset?: boolean }) {
|
|
43
|
+
const { t } = useTranslation('errors')
|
|
44
|
+
return (
|
|
45
|
+
<Message code={t('notFound.code')} title={t('notFound.title')} description={t('notFound.description')} inset={inset} />
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Route errorElement: 404s from loaders and unexpected render errors. */
|
|
50
|
+
export function RouteError({ inset }: { inset?: boolean }) {
|
|
51
|
+
const error = useRouteError()
|
|
52
|
+
const { t } = useTranslation('errors')
|
|
53
|
+
if (isRouteErrorResponse(error) && error.status === 404) return <NotFoundPage inset={inset} />
|
|
54
|
+
return (
|
|
55
|
+
<Message
|
|
56
|
+
code={t('unexpected.code')}
|
|
57
|
+
title={t('unexpected.title')}
|
|
58
|
+
description={error instanceof Error ? error.message : t('unexpected.description')}
|
|
59
|
+
inset={inset}
|
|
60
|
+
/>
|
|
61
|
+
)
|
|
62
|
+
}
|