@prenta/admin 2.9.3 → 2.11.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/CHANGELOG.md +63 -0
- package/dist/AdminRoot.d.ts.map +1 -1
- package/dist/AdminRoot.js +5 -3
- package/dist/AdminRoot.js.map +1 -1
- package/dist/__tests__/components/attribution-rows.test.js +1 -1
- package/dist/__tests__/components/attribution-rows.test.js.map +1 -1
- package/dist/__tests__/components/date-range-picker.test.d.ts +2 -0
- package/dist/__tests__/components/date-range-picker.test.d.ts.map +1 -0
- package/dist/__tests__/components/date-range-picker.test.js +59 -0
- package/dist/__tests__/components/date-range-picker.test.js.map +1 -0
- package/dist/__tests__/components/form-build-model.test.d.ts +2 -0
- package/dist/__tests__/components/form-build-model.test.d.ts.map +1 -0
- package/dist/__tests__/components/form-build-model.test.js +162 -0
- package/dist/__tests__/components/form-build-model.test.js.map +1 -0
- package/dist/__tests__/components/form-build.test.d.ts +2 -0
- package/dist/__tests__/components/form-build.test.d.ts.map +1 -0
- package/dist/__tests__/components/form-build.test.js +120 -0
- package/dist/__tests__/components/form-build.test.js.map +1 -0
- package/dist/__tests__/components/qa-a11y.render.test.js +1 -17
- package/dist/__tests__/components/qa-a11y.render.test.js.map +1 -1
- package/dist/__tests__/lib/batch-wizard.test.js +2 -0
- package/dist/__tests__/lib/batch-wizard.test.js.map +1 -1
- package/dist/__tests__/lib/forms-settings-normalize.test.d.ts +2 -0
- package/dist/__tests__/lib/forms-settings-normalize.test.d.ts.map +1 -0
- package/dist/__tests__/lib/forms-settings-normalize.test.js +16 -0
- package/dist/__tests__/lib/forms-settings-normalize.test.js.map +1 -0
- package/dist/__tests__/lib/recaptcha.test.d.ts +2 -0
- package/dist/__tests__/lib/recaptcha.test.d.ts.map +1 -0
- package/dist/__tests__/lib/recaptcha.test.js +57 -0
- package/dist/__tests__/lib/recaptcha.test.js.map +1 -0
- package/dist/__tests__/views/dashboard.test.js +105 -30
- package/dist/__tests__/views/dashboard.test.js.map +1 -1
- package/dist/__tests__/views/form-editor.render.test.js +17 -9
- package/dist/__tests__/views/form-editor.render.test.js.map +1 -1
- package/dist/__tests__/views/form-entries.render.test.js +23 -9
- package/dist/__tests__/views/form-entries.render.test.js.map +1 -1
- package/dist/__tests__/views/form-submissions.render.test.js +13 -14
- package/dist/__tests__/views/form-submissions.render.test.js.map +1 -1
- package/dist/__tests__/views/forms-list.render.test.js +139 -16
- package/dist/__tests__/views/forms-list.render.test.js.map +1 -1
- package/dist/__tests__/views/forms-settings.fixture.d.ts +3 -0
- package/dist/__tests__/views/forms-settings.fixture.d.ts.map +1 -0
- package/dist/__tests__/views/forms-settings.fixture.js +31 -0
- package/dist/__tests__/views/forms-settings.fixture.js.map +1 -0
- package/dist/__tests__/views/forms-settings.render.test.d.ts +2 -0
- package/dist/__tests__/views/forms-settings.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/forms-settings.render.test.js +226 -0
- package/dist/__tests__/views/forms-settings.render.test.js.map +1 -0
- package/dist/__tests__/views/inbox-format.test.d.ts +2 -0
- package/dist/__tests__/views/inbox-format.test.d.ts.map +1 -0
- package/dist/__tests__/views/inbox-format.test.js +47 -0
- package/dist/__tests__/views/inbox-format.test.js.map +1 -0
- package/dist/__tests__/views/jobs-wizard.render.test.js +17 -3
- package/dist/__tests__/views/jobs-wizard.render.test.js.map +1 -1
- package/dist/__tests__/views/login-captcha.render.test.d.ts +2 -0
- package/dist/__tests__/views/login-captcha.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/login-captcha.render.test.js +80 -0
- package/dist/__tests__/views/login-captcha.render.test.js.map +1 -0
- package/dist/__tests__/views/onboarding-block.render.test.js +9 -7
- package/dist/__tests__/views/onboarding-block.render.test.js.map +1 -1
- package/dist/components/forms/BlocklistDialog.d.ts +19 -0
- package/dist/components/forms/BlocklistDialog.d.ts.map +1 -0
- package/dist/components/forms/BlocklistDialog.js +225 -0
- package/dist/components/forms/BlocklistDialog.js.map +1 -0
- package/dist/components/forms/ExportMenu.d.ts +3 -1
- package/dist/components/forms/ExportMenu.d.ts.map +1 -1
- package/dist/components/forms/ExportMenu.js +2 -2
- package/dist/components/forms/ExportMenu.js.map +1 -1
- package/dist/components/forms/FieldOptions.d.ts +11 -0
- package/dist/components/forms/FieldOptions.d.ts.map +1 -0
- package/dist/components/forms/FieldOptions.js +106 -0
- package/dist/components/forms/FieldOptions.js.map +1 -0
- package/dist/components/forms/FormBuild.d.ts +11 -0
- package/dist/components/forms/FormBuild.d.ts.map +1 -0
- package/dist/components/forms/FormBuild.js +299 -0
- package/dist/components/forms/FormBuild.js.map +1 -0
- package/dist/components/forms/FormsListTable.d.ts +14 -0
- package/dist/components/forms/FormsListTable.d.ts.map +1 -0
- package/dist/components/forms/FormsListTable.js +84 -0
- package/dist/components/forms/FormsListTable.js.map +1 -0
- package/dist/components/forms/form-build-model.d.ts +74 -0
- package/dist/components/forms/form-build-model.d.ts.map +1 -0
- package/dist/components/forms/form-build-model.js +297 -0
- package/dist/components/forms/form-build-model.js.map +1 -0
- package/dist/components/forms/form-build-ui.d.ts +35 -0
- package/dist/components/forms/form-build-ui.d.ts.map +1 -0
- package/dist/components/forms/form-build-ui.js +59 -0
- package/dist/components/forms/form-build-ui.js.map +1 -0
- package/dist/components/forms/primitives.d.ts +3 -22
- package/dist/components/forms/primitives.d.ts.map +1 -1
- package/dist/components/forms/primitives.js +4 -19
- package/dist/components/forms/primitives.js.map +1 -1
- package/dist/components/ui/Badge.d.ts +1 -1
- package/dist/components/ui/Card.d.ts +1 -1
- package/dist/components/ui/DateRangePicker.d.ts +7 -0
- package/dist/components/ui/DateRangePicker.d.ts.map +1 -0
- package/dist/components/ui/DateRangePicker.js +112 -0
- package/dist/components/ui/DateRangePicker.js.map +1 -0
- package/dist/components/ui/Input.d.ts +1 -1
- package/dist/components/ui/Segmented.d.ts +3 -1
- package/dist/components/ui/Segmented.d.ts.map +1 -1
- package/dist/components/ui/Segmented.js +3 -3
- package/dist/components/ui/Segmented.js.map +1 -1
- package/dist/components/ui/StatusBadge.d.ts +3 -2
- package/dist/components/ui/StatusBadge.d.ts.map +1 -1
- package/dist/components/ui/StatusBadge.js +9 -3
- package/dist/components/ui/StatusBadge.js.map +1 -1
- package/dist/components/ui/Toggle.d.ts +1 -1
- package/dist/components/ui/Toggle.d.ts.map +1 -1
- package/dist/components/ui/Toggle.js +3 -0
- package/dist/components/ui/Toggle.js.map +1 -1
- package/dist/components/ui/UnderlineTabs.d.ts +5 -1
- package/dist/components/ui/UnderlineTabs.d.ts.map +1 -1
- package/dist/components/ui/UnderlineTabs.js +14 -11
- package/dist/components/ui/UnderlineTabs.js.map +1 -1
- package/dist/layout/Sidebar.js +3 -1
- package/dist/layout/Sidebar.js.map +1 -1
- package/dist/lib/batch-wizard.d.ts +1 -1
- package/dist/lib/batch-wizard.d.ts.map +1 -1
- package/dist/lib/batch-wizard.js +2 -2
- package/dist/lib/batch-wizard.js.map +1 -1
- package/dist/lib/entry-attribution.d.ts +13 -0
- package/dist/lib/entry-attribution.d.ts.map +1 -0
- package/dist/lib/entry-attribution.js +81 -0
- package/dist/lib/entry-attribution.js.map +1 -0
- package/dist/lib/forms-service.d.ts +133 -0
- package/dist/lib/forms-service.d.ts.map +1 -1
- package/dist/lib/forms-service.js +119 -0
- package/dist/lib/forms-service.js.map +1 -1
- package/dist/lib/job-drawer.d.ts +1 -0
- package/dist/lib/job-drawer.d.ts.map +1 -1
- package/dist/lib/job-drawer.js +23 -1
- package/dist/lib/job-drawer.js.map +1 -1
- package/dist/lib/job-view.d.ts +6 -0
- package/dist/lib/job-view.d.ts.map +1 -1
- package/dist/lib/job-view.js +7 -0
- package/dist/lib/job-view.js.map +1 -1
- package/dist/lib/recaptcha.d.ts +8 -0
- package/dist/lib/recaptcha.d.ts.map +1 -0
- package/dist/lib/recaptcha.js +73 -0
- package/dist/lib/recaptcha.js.map +1 -0
- package/dist/prenta-admin.css +1 -1
- package/dist/router/admin-routes.d.ts.map +1 -1
- package/dist/router/admin-routes.js +1 -0
- package/dist/router/admin-routes.js.map +1 -1
- package/dist/views/Dashboard.d.ts.map +1 -1
- package/dist/views/Dashboard.js +438 -309
- package/dist/views/Dashboard.js.map +1 -1
- package/dist/views/FormEditor.d.ts.map +1 -1
- package/dist/views/FormEditor.js +68 -13
- package/dist/views/FormEditor.js.map +1 -1
- package/dist/views/FormEntries.d.ts.map +1 -1
- package/dist/views/FormEntries.js +4 -190
- package/dist/views/FormEntries.js.map +1 -1
- package/dist/views/FormSubmissions.d.ts +1 -1
- package/dist/views/FormSubmissions.d.ts.map +1 -1
- package/dist/views/FormSubmissions.js +6 -195
- package/dist/views/FormSubmissions.js.map +1 -1
- package/dist/views/Forms.d.ts +11 -1
- package/dist/views/Forms.d.ts.map +1 -1
- package/dist/views/Forms.js +141 -93
- package/dist/views/Forms.js.map +1 -1
- package/dist/views/FormsSettings.d.ts +6 -1
- package/dist/views/FormsSettings.d.ts.map +1 -1
- package/dist/views/FormsSettings.js +527 -30
- package/dist/views/FormsSettings.js.map +1 -1
- package/dist/views/Jobs/DrawerReview.d.ts.map +1 -1
- package/dist/views/Jobs/DrawerReview.js +8 -7
- package/dist/views/Jobs/DrawerReview.js.map +1 -1
- package/dist/views/Jobs/NewBatchJob.d.ts.map +1 -1
- package/dist/views/Jobs/NewBatchJob.js +2 -1
- package/dist/views/Jobs/NewBatchJob.js.map +1 -1
- package/dist/views/Login.d.ts.map +1 -1
- package/dist/views/Login.js +30 -11
- package/dist/views/Login.js.map +1 -1
- package/dist/views/SpamFolder.js +1 -1
- package/dist/views/SpamFolder.js.map +1 -1
- package/dist/views/dashboard/Delta.d.ts +7 -0
- package/dist/views/dashboard/Delta.d.ts.map +1 -0
- package/dist/views/dashboard/Delta.js +21 -0
- package/dist/views/dashboard/Delta.js.map +1 -0
- package/dist/views/dashboard/KpiCard.d.ts +22 -0
- package/dist/views/dashboard/KpiCard.d.ts.map +1 -0
- package/dist/views/dashboard/KpiCard.js +15 -0
- package/dist/views/dashboard/KpiCard.js.map +1 -0
- package/dist/views/dashboard/Sparkline.d.ts +11 -0
- package/dist/views/dashboard/Sparkline.d.ts.map +1 -0
- package/dist/views/dashboard/Sparkline.js +15 -0
- package/dist/views/dashboard/Sparkline.js.map +1 -0
- package/dist/views/dashboard/TrendChart.d.ts +8 -0
- package/dist/views/dashboard/TrendChart.d.ts.map +1 -0
- package/dist/views/dashboard/TrendChart.js +98 -0
- package/dist/views/dashboard/TrendChart.js.map +1 -0
- package/dist/views/dashboard/dashboard-date.d.ts +33 -0
- package/dist/views/dashboard/dashboard-date.d.ts.map +1 -0
- package/dist/views/dashboard/dashboard-date.js +136 -0
- package/dist/views/dashboard/dashboard-date.js.map +1 -0
- package/dist/views/entries/EntriesInbox.d.ts +8 -0
- package/dist/views/entries/EntriesInbox.d.ts.map +1 -0
- package/dist/views/entries/EntriesInbox.js +516 -0
- package/dist/views/entries/EntriesInbox.js.map +1 -0
- package/dist/views/entries/inbox-format.d.ts +27 -0
- package/dist/views/entries/inbox-format.d.ts.map +1 -0
- package/dist/views/entries/inbox-format.js +119 -0
- package/dist/views/entries/inbox-format.js.map +1 -0
- package/dist/views/settings/CaptchaStatusCard.js +2 -2
- package/dist/views/settings/CaptchaStatusCard.js.map +1 -1
- package/package.json +4 -4
- package/src/AdminRoot.tsx +7 -3
- package/src/__tests__/components/attribution-rows.test.ts +1 -1
- package/src/__tests__/components/date-range-picker.test.tsx +69 -0
- package/src/__tests__/components/form-build-model.test.ts +200 -0
- package/src/__tests__/components/form-build.test.tsx +157 -0
- package/src/__tests__/components/qa-a11y.render.test.tsx +1 -29
- package/src/__tests__/lib/batch-wizard.test.ts +2 -0
- package/src/__tests__/lib/forms-settings-normalize.test.ts +17 -0
- package/src/__tests__/lib/recaptcha.test.ts +63 -0
- package/src/__tests__/views/dashboard.test.tsx +110 -32
- package/src/__tests__/views/form-editor.render.test.tsx +18 -10
- package/src/__tests__/views/form-entries.render.test.tsx +27 -9
- package/src/__tests__/views/form-submissions.render.test.tsx +15 -14
- package/src/__tests__/views/forms-list.render.test.tsx +157 -17
- package/src/__tests__/views/forms-settings.fixture.ts +32 -0
- package/src/__tests__/views/forms-settings.render.test.tsx +274 -0
- package/src/__tests__/views/inbox-format.test.ts +72 -0
- package/src/__tests__/views/jobs-wizard.render.test.tsx +18 -3
- package/src/__tests__/views/login-captcha.render.test.tsx +94 -0
- package/src/__tests__/views/onboarding-block.render.test.tsx +9 -7
- package/src/components/forms/BlocklistDialog.tsx +552 -0
- package/src/components/forms/ExportMenu.tsx +8 -2
- package/src/components/forms/FieldOptions.tsx +629 -0
- package/src/components/forms/FormBuild.tsx +900 -0
- package/src/components/forms/FormsListTable.tsx +300 -0
- package/src/components/forms/form-build-model.ts +365 -0
- package/src/components/forms/form-build-ui.tsx +130 -0
- package/src/components/forms/primitives.tsx +6 -55
- package/src/components/ui/DateRangePicker.tsx +358 -0
- package/src/components/ui/Segmented.tsx +9 -2
- package/src/components/ui/StatusBadge.tsx +17 -4
- package/src/components/ui/Toggle.tsx +3 -0
- package/src/components/ui/UnderlineTabs.tsx +20 -9
- package/src/layout/Sidebar.tsx +4 -2
- package/src/lib/batch-wizard.ts +2 -2
- package/src/lib/entry-attribution.ts +94 -0
- package/src/lib/forms-service.ts +243 -0
- package/src/lib/job-drawer.ts +21 -1
- package/src/lib/job-view.ts +7 -0
- package/src/lib/recaptcha.ts +84 -0
- package/src/router/admin-routes.ts +1 -0
- package/src/styles/theme.css +86 -0
- package/src/views/Dashboard.tsx +1183 -772
- package/src/views/FormEditor.tsx +397 -199
- package/src/views/FormEntries.tsx +3 -422
- package/src/views/FormSubmissions.tsx +5 -411
- package/src/views/Forms.tsx +333 -321
- package/src/views/FormsSettings.tsx +1616 -73
- package/src/views/Jobs/DrawerReview.tsx +14 -8
- package/src/views/Jobs/NewBatchJob.tsx +5 -1
- package/src/views/Login.tsx +35 -11
- package/src/views/SpamFolder.tsx +2 -2
- package/src/views/dashboard/Delta.tsx +44 -0
- package/src/views/dashboard/KpiCard.tsx +98 -0
- package/src/views/dashboard/Sparkline.tsx +51 -0
- package/src/views/dashboard/TrendChart.tsx +246 -0
- package/src/views/dashboard/dashboard-date.ts +168 -0
- package/src/views/entries/EntriesInbox.tsx +1277 -0
- package/src/views/entries/inbox-format.ts +128 -0
- package/src/views/settings/CaptchaStatusCard.tsx +2 -2
- package/dist/components/forms/EntriesTable.d.ts +0 -29
- package/dist/components/forms/EntriesTable.d.ts.map +0 -1
- package/dist/components/forms/EntriesTable.js +0 -29
- package/dist/components/forms/EntriesTable.js.map +0 -1
- package/dist/components/forms/FormEntryDetailPane.d.ts +0 -23
- package/dist/components/forms/FormEntryDetailPane.d.ts.map +0 -1
- package/dist/components/forms/FormEntryDetailPane.js +0 -208
- package/dist/components/forms/FormEntryDetailPane.js.map +0 -1
- package/dist/components/ui/PanelSection.d.ts +0 -16
- package/dist/components/ui/PanelSection.d.ts.map +0 -1
- package/dist/components/ui/PanelSection.js +0 -15
- package/dist/components/ui/PanelSection.js.map +0 -1
- package/src/components/forms/EntriesTable.tsx +0 -207
- package/src/components/forms/FormEntryDetailPane.tsx +0 -402
- package/src/components/ui/PanelSection.tsx +0 -53
package/dist/views/Dashboard.js
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
/**
|
|
4
|
-
* Dashboard
|
|
5
|
-
* ----------
|
|
6
|
-
* Single-file, lean dashboard implementation. Two API calls only
|
|
7
|
-
* (`/stats` + `/health`, both shared with the rest of the admin), everything
|
|
8
|
-
* else derived client-side via `useMemo`. No charting libraries on this view
|
|
9
|
-
* (the design uses plain progress bars + colored dots), keeping the bundle
|
|
10
|
-
* and TTI cost low.
|
|
4
|
+
* Dashboard — period report (design_handoff_dashboard).
|
|
11
5
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* 1025–1399: stat cards 2+3, main grid is `1fr 320px`
|
|
17
|
-
* ≥ 1400: stat cards in one row
|
|
6
|
+
* The page is driven by `/stats/dashboard`: pick a range and comparison and
|
|
7
|
+
* the KPIs, chart, tables and bars all recompute. Organic sessions and
|
|
8
|
+
* pageviews have no analytics source yet, so the endpoint returns them as
|
|
9
|
+
* null and those surfaces render the kit's "Connect analytics" state.
|
|
18
10
|
*/
|
|
19
11
|
import { useEffect, useMemo, useState } from 'react';
|
|
20
|
-
import {
|
|
21
|
-
import { FileText, File as FileIcon, Image as ImageIcon, ClipboardList, Search, Plus, Upload, Globe, ExternalLink, Activity, AlertTriangle, Clock, Zap, Database, ChevronRight, Loader2, TrendingUp, TrendingDown, Gauge, AlertCircle, } from 'lucide-react';
|
|
12
|
+
import { Activity, AlertCircle, AlertTriangle, Clock, Database, Download, Eye, FileText, Gauge, Globe, Inbox, Plus, Search, Target, Zap, } from 'lucide-react';
|
|
22
13
|
import { useApiData } from '../lib/useApiData.js';
|
|
23
14
|
import { editPathForDoc } from '../lib/collection-routes.js';
|
|
24
15
|
import { AuthorAvatar } from '../components/ui/AuthorAvatar.js';
|
|
25
|
-
import {
|
|
16
|
+
import { DateRangePicker } from '../components/ui/DateRangePicker.js';
|
|
17
|
+
import { Button } from '../components/ui/Button.js';
|
|
26
18
|
import { OnboardingBlock, shouldShowOnboarding } from './dashboard/OnboardingBlock.js';
|
|
27
19
|
import { kpiCardSpan, kpiGridClass } from './dashboard/kpi-grid.js';
|
|
28
|
-
|
|
20
|
+
import { comparisonFor, dateKey, inclusiveDays, isCompareMode, isMetricKey, rangeFromUrlValue, rangeLabel, rangeToUrlValue, } from './dashboard/dashboard-date.js';
|
|
21
|
+
import { Delta, deltaPercent } from './dashboard/Delta.js';
|
|
22
|
+
import { KpiCard } from './dashboard/KpiCard.js';
|
|
23
|
+
import { TrendChart } from './dashboard/TrendChart.js';
|
|
24
|
+
const METRIC_META = {
|
|
25
|
+
entries: { label: 'Form entries', icon: Inbox },
|
|
26
|
+
sessions: { label: 'Organic sessions', icon: Globe },
|
|
27
|
+
views: { label: 'Pageviews', icon: Eye },
|
|
28
|
+
published: { label: 'Content published', icon: FileText },
|
|
29
|
+
};
|
|
30
|
+
const number = new Intl.NumberFormat('en-US');
|
|
29
31
|
function resolveCollections(config) {
|
|
30
32
|
if (!config?.collections)
|
|
31
33
|
return [];
|
|
@@ -63,16 +65,10 @@ function timeOfDayGreeting() {
|
|
|
63
65
|
const h = new Date().getHours();
|
|
64
66
|
if (h < 12)
|
|
65
67
|
return 'Good morning';
|
|
66
|
-
if (h <
|
|
68
|
+
if (h < 18)
|
|
67
69
|
return 'Good afternoon';
|
|
68
70
|
return 'Good evening';
|
|
69
71
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Return the user's first name for the greeting. Falls back to the
|
|
72
|
-
* email local-part, then a generic "there". Strips role-style names
|
|
73
|
-
* like "Admin" / "Administrator" / "Editor" — a literal
|
|
74
|
-
* `Good morning, Admin` reads as bot-output, not a person.
|
|
75
|
-
*/
|
|
76
72
|
function firstNameForGreeting(session) {
|
|
77
73
|
const raw = (session?.user?.name ?? session?.name ?? '').trim();
|
|
78
74
|
const email = session?.user?.email ?? session?.email;
|
|
@@ -88,244 +84,163 @@ function firstNameForGreeting(session) {
|
|
|
88
84
|
}
|
|
89
85
|
return 'there';
|
|
90
86
|
}
|
|
91
|
-
function todayDateString() {
|
|
92
|
-
return new Date().toLocaleDateString('en-US', {
|
|
93
|
-
weekday: 'long',
|
|
94
|
-
month: 'long',
|
|
95
|
-
day: 'numeric',
|
|
96
|
-
year: 'numeric',
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Semantic state styling uses theme tokens (`success` / `warning` / `info`
|
|
101
|
-
* / `brand`) so the dashboard tracks the design system in both light and
|
|
102
|
-
* dark mode. One deliberate exception remains as raw values:
|
|
103
|
-
* - Error states keep `text-red-*` / `bg-red-*`. The `--destructive`
|
|
104
|
-
* token's dark value is intentionally dark (low contrast as TEXT on a
|
|
105
|
-
* dark card), so tokenizing error text here would regress contrast.
|
|
106
|
-
* Promoting error to a token is a separate, admin-wide change.
|
|
107
|
-
* Author avatar colors moved to the shared `AuthorAvatar` component.
|
|
108
|
-
*/
|
|
109
87
|
function statusBadge(status) {
|
|
110
88
|
switch (status) {
|
|
111
89
|
case 'PUBLISHED':
|
|
112
|
-
return { label: 'Published', cls: 'bg-
|
|
90
|
+
return { label: 'Published', cls: 'bg-[var(--suc-l)] text-[var(--suc)]' };
|
|
113
91
|
case 'DRAFT':
|
|
114
|
-
return { label: 'Draft', cls: 'bg-
|
|
92
|
+
return { label: 'Draft', cls: 'bg-[var(--warn-l)] text-[var(--warn)]' };
|
|
115
93
|
case 'SCHEDULED':
|
|
116
|
-
return { label: 'Scheduled', cls: 'bg-
|
|
94
|
+
return { label: 'Scheduled', cls: 'bg-[var(--bg)] text-[var(--sub)]' };
|
|
117
95
|
case 'IN_REVIEW':
|
|
118
|
-
return { label: 'In Review', cls: 'bg-info
|
|
96
|
+
return { label: 'In Review', cls: 'bg-[var(--info-l)] text-[var(--info)]' };
|
|
119
97
|
default:
|
|
120
|
-
return { label: status, cls: 'bg-
|
|
98
|
+
return { label: status, cls: 'bg-[var(--bg)] text-[var(--sub)]' };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function activityVerb(status) {
|
|
102
|
+
switch (status) {
|
|
103
|
+
case 'PUBLISHED':
|
|
104
|
+
return 'published';
|
|
105
|
+
case 'DRAFT':
|
|
106
|
+
return 'saved as draft';
|
|
107
|
+
case 'SCHEDULED':
|
|
108
|
+
return 'scheduled';
|
|
109
|
+
case 'IN_REVIEW':
|
|
110
|
+
return 'submitted for review';
|
|
111
|
+
default:
|
|
112
|
+
return 'updated';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function userPreferenceKey(session) {
|
|
116
|
+
const id = session?.user?.id ?? session?.user?.email ?? session?.userId ?? session?.email ?? 'anon';
|
|
117
|
+
return `prenta.dashboard.${String(id)}`;
|
|
118
|
+
}
|
|
119
|
+
function readPreference(session) {
|
|
120
|
+
try {
|
|
121
|
+
const raw = window.localStorage.getItem(userPreferenceKey(session));
|
|
122
|
+
if (!raw)
|
|
123
|
+
return null;
|
|
124
|
+
const parsed = JSON.parse(raw);
|
|
125
|
+
return {
|
|
126
|
+
range: typeof parsed.range === 'string' ? parsed.range : '28d',
|
|
127
|
+
compare: typeof parsed.compare === 'string' ? parsed.compare : 'prev',
|
|
128
|
+
metric: typeof parsed.metric === 'string' ? parsed.metric : 'entries',
|
|
129
|
+
};
|
|
121
130
|
}
|
|
131
|
+
catch {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function initialDashboardState(session) {
|
|
136
|
+
const today = dateKey(new Date());
|
|
137
|
+
let range = rangeFromUrlValue('28d', today);
|
|
138
|
+
let metric = 'entries';
|
|
139
|
+
if (typeof window !== 'undefined') {
|
|
140
|
+
const params = new URLSearchParams(window.location.search);
|
|
141
|
+
const preference = readPreference(session);
|
|
142
|
+
const urlRange = rangeFromUrlValue(params.get('range'), today);
|
|
143
|
+
const storedRange = preference ? rangeFromUrlValue(preference.range, today) : null;
|
|
144
|
+
range = urlRange ?? storedRange ?? range;
|
|
145
|
+
const compareValue = params.get('compare') ?? preference?.compare ?? range.compare;
|
|
146
|
+
if (isCompareMode(compareValue))
|
|
147
|
+
range = { ...range, compare: compareValue };
|
|
148
|
+
const metricValue = params.get('metric') ?? preference?.metric ?? metric;
|
|
149
|
+
if (isMetricKey(metricValue))
|
|
150
|
+
metric = metricValue;
|
|
151
|
+
}
|
|
152
|
+
return { range, metric };
|
|
153
|
+
}
|
|
154
|
+
function csvCell(value) {
|
|
155
|
+
if (value === null)
|
|
156
|
+
return '';
|
|
157
|
+
const text = String(value);
|
|
158
|
+
return /[",\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
|
|
122
159
|
}
|
|
123
|
-
// ─── Dashboard ───────────────────────────────────────────────────────────────
|
|
124
160
|
export function Dashboard({ config, session, onNavigate }) {
|
|
125
161
|
const nav = (path) => onNavigate?.(path);
|
|
126
|
-
// Cache responses for 30s so navigating away and back doesn't re-fire
|
|
127
|
-
// all four dashboard requests on every visit. First load is unaffected
|
|
128
|
-
// (cold cache) and each request still streams independently; `refetch`
|
|
129
|
-
// (the Retry button) bypasses the cache.
|
|
130
162
|
const DASH_CACHE_MS = 30_000;
|
|
131
|
-
const
|
|
163
|
+
const [initial] = useState(() => initialDashboardState(session));
|
|
164
|
+
const [range, setRange] = useState(initial.range);
|
|
165
|
+
const [metric, setMetric] = useState(initial.metric);
|
|
166
|
+
const reportEndpoint = `/stats/dashboard?start=${range.start}&end=${range.end}&compare=${range.compare}`;
|
|
167
|
+
const { data: stats, error, exhausted, refetch, } = useApiData('/stats', null, {
|
|
168
|
+
cacheMs: DASH_CACHE_MS,
|
|
169
|
+
});
|
|
170
|
+
const { data: report, loading: reportLoading } = useApiData(reportEndpoint, null, {
|
|
171
|
+
cacheMs: DASH_CACHE_MS,
|
|
172
|
+
});
|
|
173
|
+
const { data: scheduled } = useApiData('/stats/scheduled?limit=5', null, {
|
|
132
174
|
cacheMs: DASH_CACHE_MS,
|
|
133
175
|
});
|
|
134
176
|
const { data: health } = useApiData('/health', null, { cacheMs: DASH_CACHE_MS });
|
|
135
177
|
const { data: delivery, loading: deliveryLoading } = useApiData('/stats/api-delivery', null, { cacheMs: DASH_CACHE_MS });
|
|
136
178
|
const { data: contentHealthData, loading: contentHealthLoading } = useApiData('/stats/content-health', null, { cacheMs: DASH_CACHE_MS });
|
|
137
|
-
// A slow ticker (60s) so the greeting, calendar date, and "x minutes
|
|
138
|
-
// ago" relative times stay correct on a dashboard left open for hours
|
|
139
|
-
// — without it, a tab opened at 11:58am would read "Good morning" all
|
|
140
|
-
// afternoon and show stale activity timestamps.
|
|
141
179
|
const [now, setNow] = useState(() => Date.now());
|
|
142
180
|
useEffect(() => {
|
|
143
181
|
const id = setInterval(() => setNow(Date.now()), 60_000);
|
|
144
182
|
return () => clearInterval(id);
|
|
145
183
|
}, []);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const siteUrl = siteUrlLoading || !resolvedSiteUrl ? null : resolvedSiteUrl;
|
|
161
|
-
// ── Stat cards ──────────────────────────────────────────────────────────
|
|
162
|
-
const statCards = useMemo(() => {
|
|
163
|
-
const counts = stats?.collectionCounts ?? {};
|
|
164
|
-
// Prefer two real collections (the user's primary content types) over
|
|
165
|
-
// hard-coded Posts/Pages so the dashboard adapts to admin-managed types.
|
|
166
|
-
const primary = [];
|
|
167
|
-
const posts = collections.find((c) => c.slug === 'posts' || c.type === 'post');
|
|
168
|
-
const pages = collections.find((c) => c.slug === 'pages' || c.type === 'page');
|
|
169
|
-
if (posts)
|
|
170
|
-
primary.push(posts);
|
|
171
|
-
if (pages)
|
|
172
|
-
primary.push(pages);
|
|
173
|
-
if (primary.length < 2) {
|
|
174
|
-
for (const c of collections) {
|
|
175
|
-
if (primary.length >= 2)
|
|
176
|
-
break;
|
|
177
|
-
if (!primary.includes(c))
|
|
178
|
-
primary.push(c);
|
|
184
|
+
// Applied range/metric round-trip through the URL and the per-user
|
|
185
|
+
// preference. replaceState keeps these changes out of the history stack.
|
|
186
|
+
useEffect(() => {
|
|
187
|
+
try {
|
|
188
|
+
const params = new URLSearchParams(window.location.search);
|
|
189
|
+
params.set('range', rangeToUrlValue(range));
|
|
190
|
+
params.set('compare', range.compare);
|
|
191
|
+
params.set('metric', metric);
|
|
192
|
+
const nextUrl = `${window.location.pathname}?${params.toString()}`;
|
|
193
|
+
// Only write when something changed: Next's router intercepts
|
|
194
|
+
// replaceState as a navigation and remounts the admin panel, so an
|
|
195
|
+
// unconditional write here loops the page.
|
|
196
|
+
if (nextUrl !== `${window.location.pathname}${window.location.search}`) {
|
|
197
|
+
window.history.replaceState(null, '', nextUrl);
|
|
179
198
|
}
|
|
199
|
+
window.localStorage.setItem(userPreferenceKey(session), JSON.stringify({ range: rangeToUrlValue(range), compare: range.compare, metric }));
|
|
180
200
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
cards.push({
|
|
184
|
-
label: collectionLabel(primary[0]),
|
|
185
|
-
value: String(counts[primary[0].slug] ?? 0),
|
|
186
|
-
icon: primary[0].type === 'page' ? FileIcon : FileText,
|
|
187
|
-
iconBg: 'bg-chart-1/15',
|
|
188
|
-
iconColor: 'text-chart-1',
|
|
189
|
-
href: `/${primary[0].slug}`,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
cards.push({
|
|
194
|
-
label: 'Documents',
|
|
195
|
-
value: String(stats?.totalDocuments ?? 0),
|
|
196
|
-
icon: FileText,
|
|
197
|
-
iconBg: 'bg-chart-1/15',
|
|
198
|
-
iconColor: 'text-chart-1',
|
|
199
|
-
});
|
|
201
|
+
catch {
|
|
202
|
+
// Private-mode storage / non-browser test environments.
|
|
200
203
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
icon: primary[1].type === 'page' ? FileIcon : FileText,
|
|
206
|
-
iconBg: 'bg-chart-2/15',
|
|
207
|
-
iconColor: 'text-chart-2',
|
|
208
|
-
href: `/${primary[1].slug}`,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
cards.push({
|
|
212
|
-
label: 'Media',
|
|
213
|
-
value: String(stats?.totalMedia ?? 0),
|
|
214
|
-
hint: stats && stats.totalMedia > 0
|
|
215
|
-
? `${stats.totalMedia} file${stats.totalMedia === 1 ? '' : 's'}`
|
|
216
|
-
: undefined,
|
|
217
|
-
icon: ImageIcon,
|
|
218
|
-
iconBg: 'bg-chart-3/15',
|
|
219
|
-
iconColor: 'text-chart-3',
|
|
220
|
-
href: '/media',
|
|
221
|
-
});
|
|
222
|
-
// `formCount` in /stats is the *submission* count; the number of
|
|
223
|
-
// forms is the count of `collection: forms` documents.
|
|
224
|
-
const formsCount = stats?.formCount ?? counts['forms'] ?? 0;
|
|
225
|
-
const submissions = stats?.formSubmissionCount ?? 0;
|
|
226
|
-
cards.push({
|
|
227
|
-
label: 'Forms',
|
|
228
|
-
value: String(formsCount),
|
|
229
|
-
hint: submissions > 0 ? `${submissions} response${submissions === 1 ? '' : 's'}` : undefined,
|
|
230
|
-
icon: ClipboardList,
|
|
231
|
-
iconBg: 'bg-chart-4/15',
|
|
232
|
-
iconColor: 'text-chart-4',
|
|
233
|
-
href: '/forms',
|
|
234
|
-
});
|
|
235
|
-
const seo = stats?.avgSeoScore ?? 0;
|
|
236
|
-
cards.push({
|
|
237
|
-
label: 'SEO Score',
|
|
238
|
-
value: seo > 0 ? String(seo) : '—',
|
|
239
|
-
unit: seo > 0 ? '/100' : undefined,
|
|
240
|
-
hint: seo > 0 ? (seo >= 70 ? 'Good' : seo >= 40 ? 'Fair' : 'Needs work') : 'No content yet',
|
|
241
|
-
hintUp: seo >= 70,
|
|
242
|
-
icon: Search,
|
|
243
|
-
iconBg: 'bg-chart-5/15',
|
|
244
|
-
iconColor: 'text-chart-5',
|
|
245
|
-
href: '/seo',
|
|
246
|
-
});
|
|
247
|
-
return cards;
|
|
248
|
-
}, [stats, collections]);
|
|
249
|
-
// ── Quick actions ───────────────────────────────────────────────────────
|
|
250
|
-
// 5-button strip matching the reference dashboard. The "+ New Post" entry
|
|
251
|
-
// intentionally duplicates the top-bar primary action: the top bar
|
|
252
|
-
// surface is for chrome-level navigation, the quick-action row is the
|
|
253
|
-
// dashboard's content-creation toolbar. Order mirrors the natural
|
|
254
|
-
// authoring flow (post → page → media → form → integration).
|
|
204
|
+
}, [range, metric, session]);
|
|
205
|
+
const greeting = useMemo(() => timeOfDayGreeting(), [now]);
|
|
206
|
+
const userName = useMemo(() => firstNameForGreeting(session), [session]);
|
|
207
|
+
const collections = useMemo(() => resolveCollections(config), [config]);
|
|
255
208
|
const quickActions = useMemo(() => {
|
|
256
209
|
const postTypes = collections.filter((c) => c.type === 'post');
|
|
257
210
|
const pages = collections.find((c) => c.slug === 'pages' || c.type === 'page');
|
|
258
211
|
const pagesSlug = pages?.slug ?? 'pages';
|
|
259
|
-
// "New Post": one Post Type → straight to its editor; several →
|
|
260
|
-
// the picker; none → the Post Type setup instructions (avoids a
|
|
261
|
-
// broken slug-based new URL).
|
|
262
212
|
const newPostPath = postTypes.length === 1
|
|
263
213
|
? `/${postTypes[0].slug}/new`
|
|
264
214
|
: postTypes.length > 1
|
|
265
215
|
? '/posts/new'
|
|
266
216
|
: '/posts/types/new';
|
|
267
|
-
|
|
268
|
-
{
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
},
|
|
273
|
-
{ label: 'New Page', icon: Plus, onClick: () => nav(`/${pagesSlug}/new`) },
|
|
274
|
-
{ label: 'Upload Media', icon: Upload, onClick: () => nav('/media') },
|
|
275
|
-
{ label: 'New Form', icon: Plus, onClick: () => nav('/forms') },
|
|
276
|
-
{ label: 'View API', icon: Globe, onClick: () => nav('/settings?tab=api-keys') },
|
|
217
|
+
return [
|
|
218
|
+
{ label: 'New Post', onClick: () => nav(newPostPath) },
|
|
219
|
+
{ label: 'New Page', onClick: () => nav(`/${pagesSlug}/new`) },
|
|
220
|
+
{ label: 'Upload Media', onClick: () => nav('/media') },
|
|
221
|
+
{ label: 'New Form', onClick: () => nav('/forms') },
|
|
222
|
+
{ label: 'Run SEO Audit', onClick: () => nav('/seo?run=1') },
|
|
277
223
|
];
|
|
278
|
-
|
|
279
|
-
}, [collections, onNavigate]);
|
|
280
|
-
// ── Recent activity ─────────────────────────────────────────────────────
|
|
281
|
-
const [activityLimit, setActivityLimit] = useState(8);
|
|
224
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
225
|
+
}, [collections, onNavigate]);
|
|
282
226
|
const activity = useMemo(() => {
|
|
283
227
|
const docs = stats?.recentDocuments ?? [];
|
|
284
|
-
return docs.slice(0,
|
|
228
|
+
return docs.slice(0, 5).map((d) => {
|
|
285
229
|
const col = collections.find((c) => c.slug === d.collection);
|
|
286
230
|
return {
|
|
287
231
|
...d,
|
|
288
232
|
typeLabel: col ? collectionLabel(col, false) : d.collection,
|
|
289
233
|
relTime: relativeTime(d.updatedAt),
|
|
290
234
|
statusInfo: statusBadge(d.status),
|
|
291
|
-
|
|
292
|
-
};
|
|
293
|
-
});
|
|
294
|
-
// `now` keeps the relative timestamps fresh on a long-open tab.
|
|
295
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
296
|
-
}, [stats, collections, activityLimit, now]);
|
|
297
|
-
// ── Publishing queue (scheduled docs only) ──────────────────────────────
|
|
298
|
-
const publishQueue = useMemo(() => {
|
|
299
|
-
const docs = stats?.recentDocuments ?? [];
|
|
300
|
-
return docs
|
|
301
|
-
.filter((d) => d.status === 'SCHEDULED')
|
|
302
|
-
.slice(0, 5)
|
|
303
|
-
.map((d) => {
|
|
304
|
-
const col = collections.find((c) => c.slug === d.collection);
|
|
305
|
-
return {
|
|
306
|
-
id: d.id,
|
|
307
|
-
collection: d.collection,
|
|
308
|
-
title: d.title || 'Untitled',
|
|
309
|
-
type: col ? collectionLabel(col, false) : d.collection,
|
|
310
|
-
date: relativeTime(d.updatedAt),
|
|
311
|
-
author: d.author,
|
|
235
|
+
verb: activityVerb(d.status),
|
|
312
236
|
editPath: editPathForDoc(col, d.collection, d.id),
|
|
313
237
|
};
|
|
314
238
|
});
|
|
315
239
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
316
240
|
}, [stats, collections, now]);
|
|
317
|
-
// ── Content health (sourced from /stats/content-health) ─────────────────
|
|
318
|
-
// Persisted by the nightly content-health cron. The four issue rows
|
|
319
|
-
// map 1:1 to ContentIssueType in the schema; the labels are
|
|
320
|
-
// user-facing and intentionally read like the reference dashboard.
|
|
321
241
|
const contentHealth = useMemo(() => {
|
|
322
242
|
const counts = contentHealthData?.counts ?? {};
|
|
323
243
|
const score = contentHealthData?.score ?? 100;
|
|
324
|
-
const label = contentHealthData?.label ?? 'Good';
|
|
325
|
-
const tone = score >= 70 ? 'ok' : score >= 40 ? 'warn' : score > 0 ? 'err' : 'muted';
|
|
326
|
-
// Issue list — only render rows that have non-zero counts so the
|
|
327
|
-
// card stays compact when the corpus is healthy. The empty state
|
|
328
|
-
// below picks up when all four are zero.
|
|
329
244
|
const issues = [];
|
|
330
245
|
const missingMeta = counts['MISSING_META_DESCRIPTION'] ?? 0;
|
|
331
246
|
const brokenLinks = counts['BROKEN_INTERNAL_LINK'] ?? 0;
|
|
@@ -336,50 +251,41 @@ export function Dashboard({ config, session, onNavigate }) {
|
|
|
336
251
|
kind: 'MISSING_META_DESCRIPTION',
|
|
337
252
|
label: 'Missing meta descriptions',
|
|
338
253
|
count: missingMeta,
|
|
339
|
-
|
|
254
|
+
dot: 'var(--warn)',
|
|
340
255
|
});
|
|
341
256
|
if (brokenLinks > 0)
|
|
342
257
|
issues.push({
|
|
343
258
|
kind: 'BROKEN_INTERNAL_LINK',
|
|
344
259
|
label: 'Broken internal links',
|
|
345
260
|
count: brokenLinks,
|
|
346
|
-
|
|
261
|
+
dot: 'var(--err)',
|
|
347
262
|
});
|
|
348
263
|
if (missingAlt > 0)
|
|
349
264
|
issues.push({
|
|
350
265
|
kind: 'MISSING_ALT_TEXT',
|
|
351
266
|
label: 'Missing alt text',
|
|
352
267
|
count: missingAlt,
|
|
353
|
-
|
|
268
|
+
dot: 'var(--warn)',
|
|
354
269
|
});
|
|
355
270
|
if (outdated > 0)
|
|
356
271
|
issues.push({
|
|
357
272
|
kind: 'OUTDATED_CONTENT',
|
|
358
273
|
label: 'Outdated content (90+ days)',
|
|
359
274
|
count: outdated,
|
|
360
|
-
|
|
275
|
+
dot: 'var(--sub)',
|
|
361
276
|
});
|
|
362
277
|
return {
|
|
363
278
|
score,
|
|
364
|
-
label,
|
|
365
|
-
tone,
|
|
279
|
+
label: contentHealthData?.label ?? 'Good',
|
|
366
280
|
issues,
|
|
281
|
+
total: contentHealthData?.totalIssues ?? issues.reduce((sum, i) => sum + i.count, 0),
|
|
367
282
|
hasData: contentHealthData !== null,
|
|
368
283
|
loading: contentHealthLoading,
|
|
369
284
|
};
|
|
370
285
|
}, [contentHealthData, contentHealthLoading]);
|
|
371
|
-
const totalIssues = contentHealth.issues.reduce((s, i) => s + i.count, 0);
|
|
372
|
-
// ── Onboarding (empty-site getting-started block) ───────────────────────
|
|
373
|
-
// Signals come exclusively from data already fetched above (/stats +
|
|
374
|
-
// /stats/api-delivery) — see OnboardingBlock.tsx for the per-step
|
|
375
|
-
// derivation rationale. When the site is effectively empty (zero
|
|
376
|
-
// posts+pages AND zero media) the onboarding block REPLACES the
|
|
377
|
-
// Recent Activity / Publishing Queue / Content Health grid.
|
|
378
286
|
const onboardingSignals = useMemo(() => {
|
|
379
287
|
const counts = stats?.collectionCounts ?? {};
|
|
380
288
|
const contentCollections = collections.filter((c) => c.type === 'post' || c.type === 'page' || c.slug === 'posts' || c.slug === 'pages');
|
|
381
|
-
// No post/page collections configured → fall back to the total document
|
|
382
|
-
// count so a populated site never regresses to the onboarding view.
|
|
383
289
|
const postsAndPagesCount = contentCollections.length > 0
|
|
384
290
|
? contentCollections.reduce((sum, c) => sum + (counts[c.slug] ?? 0), 0)
|
|
385
291
|
: (stats?.totalDocuments ?? 0);
|
|
@@ -391,59 +297,278 @@ export function Dashboard({ config, session, onNavigate }) {
|
|
|
391
297
|
hasApiTraffic: delivery?.hasData ?? false,
|
|
392
298
|
};
|
|
393
299
|
}, [stats, collections, delivery]);
|
|
394
|
-
// Belt-and-braces: any recent activity means the site is not empty even
|
|
395
|
-
// if collection counts are missing/stale, so never hide it behind
|
|
396
|
-
// onboarding.
|
|
397
300
|
const showOnboarding = stats !== null &&
|
|
398
301
|
(stats.recentDocuments?.length ?? 0) === 0 &&
|
|
399
302
|
shouldShowOnboarding(onboardingSignals);
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
303
|
+
const analyticsConnected = report?.analyticsConnected ?? false;
|
|
304
|
+
const comparing = Boolean(report?.compareRange);
|
|
305
|
+
const comparisonRange = comparisonFor(range.compare, range.start, range.end);
|
|
306
|
+
const effectiveMetric = (metric === 'sessions' || metric === 'views') && !analyticsConnected ? 'entries' : metric;
|
|
307
|
+
const metricMeta = METRIC_META[effectiveMetric];
|
|
308
|
+
const totals = report?.totals;
|
|
309
|
+
const entriesCur = totals?.entries.cur ?? 0;
|
|
310
|
+
const entriesPrev = totals?.entries.prev ?? null;
|
|
311
|
+
const sessionsCur = totals?.sessions.cur ?? null;
|
|
312
|
+
const sessionsPrev = totals?.sessions.prev ?? null;
|
|
313
|
+
const viewsCur = totals?.views.cur ?? null;
|
|
314
|
+
const viewsPrev = totals?.views.prev ?? null;
|
|
315
|
+
const publishedCur = totals?.published.cur ?? 0;
|
|
316
|
+
const publishedPrev = totals?.published.prev ?? null;
|
|
317
|
+
const convCur = sessionsCur !== null && sessionsCur !== 0
|
|
318
|
+
? (entriesCur / sessionsCur) * 100
|
|
319
|
+
: sessionsCur === 0
|
|
320
|
+
? 0
|
|
321
|
+
: null;
|
|
322
|
+
const convPrev = sessionsPrev !== null && sessionsPrev !== 0 && entriesPrev !== null
|
|
323
|
+
? (entriesPrev / sessionsPrev) * 100
|
|
324
|
+
: sessionsPrev === 0
|
|
325
|
+
? 0
|
|
326
|
+
: null;
|
|
327
|
+
const chartSeries = report?.series[effectiveMetric] ?? [];
|
|
328
|
+
const chartCompare = report?.compare?.[effectiveMetric] ?? null;
|
|
329
|
+
const chartCurTotal = effectiveMetric === 'entries'
|
|
330
|
+
? entriesCur
|
|
331
|
+
: effectiveMetric === 'published'
|
|
332
|
+
? publishedCur
|
|
333
|
+
: effectiveMetric === 'sessions'
|
|
334
|
+
? (sessionsCur ?? 0)
|
|
335
|
+
: (viewsCur ?? 0);
|
|
336
|
+
const chartPrevTotal = effectiveMetric === 'entries'
|
|
337
|
+
? entriesPrev
|
|
338
|
+
: effectiveMetric === 'published'
|
|
339
|
+
? publishedPrev
|
|
340
|
+
: effectiveMetric === 'sessions'
|
|
341
|
+
? sessionsPrev
|
|
342
|
+
: viewsPrev;
|
|
343
|
+
const chartDelta = chartPrevTotal !== null ? deltaPercent(chartCurTotal, chartPrevTotal) : null;
|
|
344
|
+
const chartAria = chartDelta === null || !comparing
|
|
345
|
+
? `${metricMeta.label}, ${number.format(chartCurTotal)} this period`
|
|
346
|
+
: `${metricMeta.label}, ${number.format(chartCurTotal)} this period, ${chartDelta >= 0 ? 'up' : 'down'} ${Math.abs(chartDelta).toFixed(1)}% from ${number.format(chartPrevTotal ?? 0)}`;
|
|
347
|
+
const unread = report?.unreadEntries ?? 0;
|
|
348
|
+
function exportCsv() {
|
|
349
|
+
if (!report)
|
|
350
|
+
return;
|
|
351
|
+
const lines = [];
|
|
352
|
+
lines.push([
|
|
353
|
+
'date',
|
|
354
|
+
'entries',
|
|
355
|
+
'entries_comparison',
|
|
356
|
+
'sessions',
|
|
357
|
+
'sessions_comparison',
|
|
358
|
+
'pageviews',
|
|
359
|
+
'pageviews_comparison',
|
|
360
|
+
'published',
|
|
361
|
+
'published_comparison',
|
|
362
|
+
].join(','));
|
|
363
|
+
report.series.entries?.forEach((point, index) => {
|
|
364
|
+
lines.push([
|
|
365
|
+
point.date,
|
|
366
|
+
point.v,
|
|
367
|
+
report.compare?.entries?.[index]?.v ?? '',
|
|
368
|
+
report.series.sessions?.[index]?.v ?? '',
|
|
369
|
+
report.compare?.sessions?.[index]?.v ?? '',
|
|
370
|
+
report.series.views?.[index]?.v ?? '',
|
|
371
|
+
report.compare?.views?.[index]?.v ?? '',
|
|
372
|
+
report.series.published?.[index]?.v ?? '',
|
|
373
|
+
report.compare?.published?.[index]?.v ?? '',
|
|
374
|
+
]
|
|
375
|
+
.map(csvCell)
|
|
376
|
+
.join(','));
|
|
377
|
+
});
|
|
378
|
+
lines.push('');
|
|
379
|
+
lines.push('measure,this_period,comparison');
|
|
380
|
+
lines.push(['Form entries', entriesCur, entriesPrev].map(csvCell).join(','));
|
|
381
|
+
lines.push(['Organic sessions', sessionsCur, sessionsPrev].map(csvCell).join(','));
|
|
382
|
+
lines.push(['Pageviews', viewsCur, viewsPrev].map(csvCell).join(','));
|
|
383
|
+
lines.push([
|
|
384
|
+
'Entries / day',
|
|
385
|
+
(entriesCur / report.range.days).toFixed(1),
|
|
386
|
+
entriesPrev !== null ? (entriesPrev / report.range.days).toFixed(1) : '',
|
|
387
|
+
]
|
|
388
|
+
.map(csvCell)
|
|
389
|
+
.join(','));
|
|
390
|
+
lines.push([
|
|
391
|
+
'Conversion rate',
|
|
392
|
+
convCur !== null ? `${convCur.toFixed(2)}%` : '',
|
|
393
|
+
convPrev !== null ? `${convPrev.toFixed(2)}%` : '',
|
|
394
|
+
]
|
|
395
|
+
.map(csvCell)
|
|
396
|
+
.join(','));
|
|
397
|
+
lines.push('');
|
|
398
|
+
lines.push('path,title,sessions,sessions_comparison,entries,entries_comparison');
|
|
399
|
+
for (const page of report.topPages) {
|
|
400
|
+
lines.push([page.path, page.title, page.sessions, page.sessionsPrev, page.entries, page.entriesPrev]
|
|
401
|
+
.map(csvCell)
|
|
402
|
+
.join(','));
|
|
403
|
+
}
|
|
404
|
+
const blob = new Blob([lines.join('\n')], { type: 'text/csv;charset=utf-8' });
|
|
405
|
+
const url = URL.createObjectURL(blob);
|
|
406
|
+
const anchor = document.createElement('a');
|
|
407
|
+
anchor.href = url;
|
|
408
|
+
anchor.download = `prenta-dashboard_${report.range.start}_${report.range.end}.csv`;
|
|
409
|
+
anchor.click();
|
|
410
|
+
URL.revokeObjectURL(url);
|
|
403
411
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
412
|
+
const kpis = [
|
|
413
|
+
{
|
|
414
|
+
key: 'entries',
|
|
415
|
+
label: 'Form entries',
|
|
416
|
+
icon: Inbox,
|
|
417
|
+
value: number.format(entriesCur),
|
|
418
|
+
cur: entriesCur,
|
|
419
|
+
prev: entriesPrev,
|
|
420
|
+
prevLabel: entriesPrev !== null ? number.format(entriesPrev) : '',
|
|
421
|
+
series: report?.series.entries ?? [],
|
|
422
|
+
compareSeries: report?.compare?.entries ?? null,
|
|
423
|
+
selectable: true,
|
|
424
|
+
unavailable: false,
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
key: 'sessions',
|
|
428
|
+
label: 'Organic sessions',
|
|
429
|
+
icon: Globe,
|
|
430
|
+
value: sessionsCur !== null ? number.format(sessionsCur) : '—',
|
|
431
|
+
cur: sessionsCur,
|
|
432
|
+
prev: sessionsPrev,
|
|
433
|
+
prevLabel: sessionsPrev !== null ? number.format(sessionsPrev) : '',
|
|
434
|
+
series: report?.series.sessions ?? null,
|
|
435
|
+
compareSeries: report?.compare?.sessions ?? null,
|
|
436
|
+
selectable: analyticsConnected,
|
|
437
|
+
unavailable: !analyticsConnected,
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
key: 'views',
|
|
441
|
+
label: 'Pageviews',
|
|
442
|
+
icon: Eye,
|
|
443
|
+
value: viewsCur !== null ? number.format(viewsCur) : '—',
|
|
444
|
+
cur: viewsCur,
|
|
445
|
+
prev: viewsPrev,
|
|
446
|
+
prevLabel: viewsPrev !== null ? number.format(viewsPrev) : '',
|
|
447
|
+
series: report?.series.views ?? null,
|
|
448
|
+
compareSeries: report?.compare?.views ?? null,
|
|
449
|
+
selectable: analyticsConnected,
|
|
450
|
+
unavailable: !analyticsConnected,
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
key: 'published',
|
|
454
|
+
label: 'Content published',
|
|
455
|
+
icon: FileText,
|
|
456
|
+
value: number.format(publishedCur),
|
|
457
|
+
cur: publishedCur,
|
|
458
|
+
prev: publishedPrev,
|
|
459
|
+
prevLabel: publishedPrev !== null ? number.format(publishedPrev) : '',
|
|
460
|
+
series: report?.series.published ?? [],
|
|
461
|
+
compareSeries: report?.compare?.published ?? null,
|
|
462
|
+
selectable: true,
|
|
463
|
+
unavailable: false,
|
|
464
|
+
},
|
|
465
|
+
];
|
|
466
|
+
return (_jsx("div", { className: "mx-auto w-full max-w-[1520px] p-[20px_24px_48px]", children: _jsxs("div", { className: "flex flex-col gap-[14px]", children: [health && health.status === 'degraded' && (_jsxs("div", { className: "flex items-start gap-3 rounded-[10px] border border-[var(--info)] bg-[var(--info-l)] p-4", children: [_jsx(Database, { className: "mt-0.5 h-5 w-5 shrink-0 text-[var(--info)]", "aria-hidden": true }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("span", { className: "text-sm font-medium text-[var(--info)]", children: "Database setup required" }), _jsx("p", { className: "mt-0.5 text-xs text-[var(--sub)]", children: !health.databaseConnected
|
|
467
|
+
? 'Cannot connect to the database. Check your DATABASE_URL environment variable.'
|
|
468
|
+
: !health.secretConfigured
|
|
469
|
+
? 'CMS secret not configured. Set CMS_SECRET or CMS_SESSION_SECRET (min 32 characters).'
|
|
470
|
+
: `Some CMS models are missing: ${Object.entries(health.models)
|
|
471
|
+
.filter(([, v]) => !v)
|
|
472
|
+
.map(([k]) => k)
|
|
473
|
+
.join(', ')}. Run your database migrations.` })] })] })), error && exhausted && (_jsxs("div", { className: "flex items-center gap-3 rounded-[10px] border border-[var(--warn)] bg-[var(--warn-l)] p-4", children: [_jsx(AlertTriangle, { className: "h-5 w-5 shrink-0 text-[var(--warn)]", "aria-hidden": true }), _jsx("span", { className: "flex-1 text-sm text-[var(--warn)]", children: "Some dashboard data may be unavailable." }), _jsx(Button, { type: "button", variant: "secondary", size: "sm", onClick: refetch, children: "Retry" })] })), _jsxs("header", { className: "mb-[4px] flex flex-wrap items-end gap-4", children: [_jsxs("div", { children: [_jsxs("h1", { className: "text-[23px] leading-[1.15] font-bold tracking-[-0.6px] text-[var(--txt)]", children: [greeting, ", ", userName] }), _jsx("p", { className: "mt-1 text-[13px] text-[var(--sub)]", children: unread === 0 ? (_jsxs(_Fragment, { children: ["No unread leads \u00B7", ' ', _jsx("button", { type: "button", className: "text-[var(--acc)] hover:underline", onClick: () => nav('/forms/entries?filter=unread'), children: "open the inbox" })] })) : (_jsxs(_Fragment, { children: [unread, " unread lead", unread === 1 ? '' : 's', " waiting \u00B7", ' ', _jsx("button", { type: "button", className: "text-[var(--acc)] hover:underline", onClick: () => nav('/forms/entries?filter=unread'), children: "open the inbox" })] })) })] }), _jsxs("div", { className: "ml-auto flex flex-wrap items-center gap-2", children: [_jsx(DateRangePicker, { value: range, onChange: setRange }), _jsx(Button, { type: "button", variant: "secondary", "aria-label": "Export", onClick: exportCsv, disabled: !report, className: "h-11 px-[11px]", leftIcon: _jsx(Download, { size: 14, "aria-hidden": true }), children: _jsx("span", { className: "max-[1024px]:hidden", children: "Export" }) })] })] }), _jsx("div", { className: "grid [grid-template-columns:repeat(auto-fit,minmax(146px,1fr))] gap-2 max-[768px]:flex max-[768px]:overflow-x-auto max-[768px]:pb-1", children: quickActions.map((action) => (_jsxs("button", { type: "button", onClick: action.onClick, className: "flex shrink-0 items-center gap-2 rounded-[9px] border border-[var(--bdr)] bg-[var(--card)] px-[13px] py-[11px] text-[13px] font-medium whitespace-nowrap text-[var(--txt)] transition hover:-translate-y-px hover:border-[var(--acc-m)] hover:bg-[var(--acc-l)] hover:text-[var(--acc)]", children: [_jsx(Plus, { size: 14, className: "shrink-0 text-[var(--acc)]", "aria-hidden": true }), action.label] }, action.label))) }), _jsx("div", { "data-kpi-grid": "", className: kpiGridClass(5), children: reportLoading && !report
|
|
474
|
+
? [0, 1, 2, 3, 4].map((index) => (_jsxs("div", { "aria-hidden": true, className: `rounded-[10px] border border-[var(--bdr)] bg-[var(--card)] p-[14px_15px_10px] shadow-[var(--shd)] ${kpiCardSpan(index, 5)}`, children: [_jsx("div", { className: "h-[14px] w-24 rounded bg-[var(--bg)]" }), _jsx("div", { className: "mt-[10px] h-[32px] w-[70%] rounded bg-[var(--bg)]" }), _jsx("div", { className: "mt-[10px] ml-auto h-[30px] w-[76px] rounded bg-[var(--bg)]" })] }, index)))
|
|
475
|
+
: [
|
|
476
|
+
...kpis.slice(0, 3),
|
|
477
|
+
{
|
|
478
|
+
key: 'conv',
|
|
479
|
+
label: 'Conversion rate',
|
|
480
|
+
icon: Target,
|
|
481
|
+
value: convCur !== null ? convCur.toFixed(2) : '—',
|
|
482
|
+
unit: convCur !== null ? '%' : undefined,
|
|
483
|
+
cur: convCur,
|
|
484
|
+
prev: convPrev,
|
|
485
|
+
prevLabel: convPrev !== null ? `${convPrev.toFixed(2)}%` : '',
|
|
486
|
+
series: null,
|
|
487
|
+
compareSeries: null,
|
|
488
|
+
selectable: false,
|
|
489
|
+
unavailable: !analyticsConnected,
|
|
490
|
+
},
|
|
491
|
+
kpis[3],
|
|
492
|
+
].map((kpi, index) => (_jsx(KpiCard, { label: kpi.label, icon: kpi.icon, value: kpi.value, unit: 'unit' in kpi ? kpi.unit : undefined, cur: kpi.cur, prev: kpi.prev, prevLabel: kpi.prevLabel, compare: comparing, series: kpi.series, compareSeries: kpi.compareSeries, selected: kpi.key === effectiveMetric, selectable: kpi.selectable, unavailable: kpi.unavailable, onSelect: () => {
|
|
493
|
+
if (kpi.key !== 'conv')
|
|
494
|
+
setMetric(kpi.key);
|
|
495
|
+
}, onConnect: () => nav('/settings'), spanClass: kpiCardSpan(index, 5) }, kpi.key))) }), _jsx(DashboardCard, { title: `${metricMeta.label} over time`, subtitle: `${report?.range.days ?? inclusiveDays(range.start, range.end)} days · ${rangeLabel(range.start, range.end)}${comparing && comparisonRange
|
|
496
|
+
? ` vs ${rangeLabel(comparisonRange[0], comparisonRange[1])}`
|
|
497
|
+
: ''}`, action: _jsxs("div", { className: "flex flex-wrap items-center gap-[14px]", children: [_jsxs("span", { className: "flex items-center gap-[6px] text-[11.5px] text-[var(--sub)]", children: [_jsx("i", { className: "block h-[3px] w-[14px] rounded-[2px] bg-[var(--acc)]", "aria-hidden": true }), "This period", ' ', _jsx("b", { className: "ml-[2px] text-[var(--txt)]", children: number.format(chartCurTotal) })] }), comparing ? (_jsxs(_Fragment, { children: [_jsxs("span", { className: "flex items-center gap-[6px] text-[11.5px] text-[var(--sub)]", children: [_jsx("i", { className: "block h-[2px] w-[14px] rounded-[2px] bg-[repeating-linear-gradient(90deg,var(--muted)_0_4px,transparent_4px_7px)]", "aria-hidden": true }), "Comparison", ' ', _jsx("b", { className: "ml-[2px] text-[var(--sub)]", children: number.format(chartPrevTotal ?? 0) })] }), chartPrevTotal !== null ? (_jsx(Delta, { cur: chartCurTotal, prev: chartPrevTotal })) : null] })) : null] }), children: reportLoading && !report ? (_jsx("div", { className: "relative px-2 pt-[14px] pb-1", "aria-hidden": true, children: _jsx("div", { className: "flex h-[244px] flex-col justify-between py-3", children: [0, 1, 2, 3, 4].map((line) => (_jsx("div", { className: "h-px bg-[var(--bdr)]" }, line))) }) })) : (_jsx(TrendChart, { cur: chartSeries, prev: comparing ? chartCompare : null, format: (value) => number.format(Math.round(value)), ariaLabel: chartAria })) }), showOnboarding ? (_jsx(OnboardingBlock, { signals: onboardingSignals, onNavigate: onNavigate })) : (_jsxs(_Fragment, { children: [_jsxs("div", { className: "grid gap-[14px] min-[1181px]:grid-cols-[1.45fr_1fr]", children: [_jsx(DashboardCard, { title: "Top landing pages", subtitle: "Sessions and entries, measured against the comparison period", children: !analyticsConnected ? (_jsx(EmptyState, { icon: Globe, title: "Analytics isn't connected", subtitle: "Connect analytics to see sessions and entries by landing page.", action: _jsx("button", { type: "button", onClick: () => nav('/settings'), className: "text-[12.5px] font-semibold text-[var(--acc)] hover:underline", children: "Connect analytics" }) })) : report?.topPages.length ? (_jsx("div", { className: "overflow-x-auto", tabIndex: 0, role: "region", "aria-label": "Top landing pages table", children: _jsxs("table", { className: "w-full min-w-[560px] border-collapse", "aria-label": "Top landing pages", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { className: "sticky left-0 bg-[var(--bg)] px-[14px] py-2 text-left text-[10px] font-bold tracking-[0.6px] text-[var(--sub)] uppercase", children: "Page" }), _jsx("th", { className: "bg-[var(--bg)] px-[14px] py-2 text-right text-[10px] font-bold tracking-[0.6px] text-[var(--sub)] uppercase", children: "Sessions" }), _jsx("th", { className: "bg-[var(--bg)] px-[14px] py-2 text-right text-[10px] font-bold tracking-[0.6px] text-[var(--sub)] uppercase", children: "Entries" }), _jsx("th", { className: "bg-[var(--bg)] px-[14px] py-2 text-right text-[10px] font-bold tracking-[0.6px] text-[var(--sub)] uppercase", children: "Conv." }), _jsx("th", { className: "bg-[var(--bg)] px-[14px] py-2 text-right text-[10px] font-bold tracking-[0.6px] text-[var(--sub)] uppercase", children: "Change" })] }) }), _jsx("tbody", { children: report.topPages.map((page) => {
|
|
498
|
+
const col = page.collection
|
|
499
|
+
? collections.find((item) => item.slug === page.collection)
|
|
500
|
+
: undefined;
|
|
501
|
+
const pageCell = (_jsxs(_Fragment, { children: [_jsx("span", { className: "block max-w-[280px] truncate text-[12.5px] font-medium text-[var(--txt)]", children: page.title }), _jsx("span", { className: "mt-[1px] block font-mono text-[11px] text-[var(--sub)]", children: page.path })] }));
|
|
502
|
+
return (_jsxs("tr", { className: "group hover:bg-[var(--bg)]", children: [_jsx("td", { className: "sticky left-0 bg-[var(--card)] px-[14px] py-[10px] group-hover:bg-[var(--bg)]", children: page.docId ? (_jsx("button", { type: "button", className: "block text-left", onClick: () => nav(editPathForDoc(col, page.collection ?? '', page.docId)), children: pageCell })) : (pageCell) }), _jsxs("td", { className: "px-[14px] py-[10px] text-right align-middle tabular-nums", children: [_jsx("span", { className: "text-[13.5px] font-[650] text-[var(--txt)]", children: number.format(page.sessions) }), comparing && page.sessionsPrev !== null ? (_jsxs("div", { className: "text-[11px] text-[var(--sub)]", children: ["was ", number.format(page.sessionsPrev)] })) : null] }), _jsxs("td", { className: "px-[14px] py-[10px] text-right align-middle tabular-nums", children: [_jsx("span", { className: "text-[13.5px] font-[650] text-[var(--txt)]", children: number.format(page.entries) }), comparing && page.entriesPrev !== null ? (_jsxs("div", { className: "text-[11px] text-[var(--sub)]", children: ["was ", number.format(page.entriesPrev)] })) : null] }), _jsxs("td", { className: "px-[14px] py-[10px] text-right text-[13.5px] font-[650] text-[var(--txt)] tabular-nums", children: [page.sessions
|
|
503
|
+
? ((page.entries / page.sessions) * 100).toFixed(2)
|
|
504
|
+
: '0.00', "%"] }), _jsx("td", { className: "px-[14px] py-[10px] text-right", children: comparing && page.sessionsPrev !== null ? (_jsx(Delta, { cur: page.sessions, prev: page.sessionsPrev })) : (_jsx("span", { className: "text-[11px] text-[var(--sub)]", children: "\u2014" })) })] }, page.path));
|
|
505
|
+
}) })] }) })) : (_jsx(EmptyState, { icon: Search, title: "No landing pages yet", subtitle: "Pages with sessions in this period will appear here." })) }), _jsx(DashboardCard, { title: "Entries by form", subtitle: "Solid bar this period, grey bar comparison", children: _jsxs("div", { className: "flex flex-col gap-[13px] px-4 pt-3 pb-[14px]", children: [(report?.entriesByForm ?? []).map((form) => {
|
|
506
|
+
const max = Math.max(...(report?.entriesByForm.map((item) => Math.max(item.cur, item.prev ?? 0)) ?? [1]), 1);
|
|
507
|
+
return (_jsxs("button", { type: "button", onClick: () => nav(`/forms/entries?form=${encodeURIComponent(form.slug)}`), className: "block w-full text-left", children: [_jsxs("div", { className: "flex items-baseline gap-2 text-[12.5px]", children: [_jsx("b", { className: "font-[550] text-[var(--txt)]", children: form.name }), comparing && form.prev !== null ? (_jsx(Delta, { cur: form.cur, prev: form.prev })) : null, _jsx("span", { className: "ml-auto text-[13px] font-bold text-[var(--txt)] tabular-nums", children: number.format(form.cur) })] }), _jsxs("div", { className: "relative mt-[6px] h-4", children: [comparing && form.prev !== null ? (_jsx("div", { className: "absolute top-0 left-0 h-[6px] rounded-full bg-[var(--bdr)]", style: { width: `${(form.prev / max) * 100}%` }, "aria-hidden": true })) : null, _jsx("div", { className: "absolute left-0 h-2 rounded-full bg-[var(--acc)] transition-[width] duration-300", style: {
|
|
508
|
+
width: `${(form.cur / max) * 100}%`,
|
|
509
|
+
top: comparing ? 8 : 4,
|
|
510
|
+
}, "aria-hidden": true })] })] }, form.slug || form.name));
|
|
511
|
+
}), (report?.entriesByForm.length ?? 0) === 0 ? (_jsx("p", { className: "py-4 text-center text-[12.5px] text-[var(--sub)]", children: "No forms yet. Entries will be grouped here once a form exists." })) : null] }) })] }), _jsxs("div", { className: "grid gap-[14px] min-[1181px]:grid-cols-[1.45fr_1fr]", children: [_jsx(DashboardCard, { title: "Recent activity", subtitle: "Across all content types", action: _jsx("button", { type: "button", className: "text-[12.5px] text-[var(--acc)] hover:underline", onClick: () => nav('/posts'), children: "View all" }), children: activity.length === 0 ? (_jsx(EmptyState, { icon: Activity, title: "No activity yet", subtitle: "Content changes will appear here as your team works." })) : (_jsx("ul", { role: "list", children: activity.map((item) => (_jsx("li", { className: "border-b border-[var(--bdr)] last:border-b-0", children: _jsxs("button", { type: "button", onClick: () => nav(item.editPath), className: "flex w-full items-start gap-[11px] px-4 py-[10px] text-left transition hover:bg-[var(--bg)]", children: [_jsx(AuthorAvatar, { name: item.author, size: 28, className: "shrink-0" }), _jsxs("span", { className: "min-w-0 flex-1", children: [_jsx("span", { className: "block truncate text-[13px] font-medium text-[var(--txt)]", children: item.title || 'Untitled' }), _jsxs("span", { className: "mt-[2px] block text-[11.5px] text-[var(--sub)]", children: [item.typeLabel, " ", item.verb, " by ", item.author] })] }), _jsxs("span", { className: "flex shrink-0 flex-col items-end gap-1", children: [_jsx("span", { className: `inline-flex rounded-[4px] px-[6px] py-[1.5px] text-[10px] font-bold tracking-[0.2px] ${item.statusInfo.cls}`, children: item.statusInfo.label }), _jsx("span", { className: "text-[11px] text-[var(--sub)]", children: item.relTime === 'Yesterday' ||
|
|
512
|
+
item.relTime === 'just now' ||
|
|
513
|
+
item.relTime.endsWith(' ago') ||
|
|
514
|
+
item.relTime.includes('/')
|
|
515
|
+
? item.relTime
|
|
516
|
+
: `${item.relTime} ago` })] })] }) }, item.id))) })) }), _jsx(DashboardCard, { title: "Period summary", subtitle: rangeLabel(range.start, range.end), children: _jsx("div", { className: "overflow-x-auto", tabIndex: 0, role: "region", "aria-label": "Period summary table", children: _jsxs("table", { className: "w-full min-w-[420px] border-collapse", "aria-label": "Period summary", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { className: "bg-[var(--bg)] px-[14px] py-2 text-left text-[10px] font-bold tracking-[0.6px] text-[var(--sub)] uppercase", children: "Measure" }), _jsx("th", { className: "bg-[var(--bg)] px-[14px] py-2 text-right text-[10px] font-bold tracking-[0.6px] text-[var(--sub)] uppercase", children: "This period" }), _jsx("th", { className: "bg-[var(--bg)] px-[14px] py-2 text-right text-[10px] font-bold tracking-[0.6px] text-[var(--sub)] uppercase", children: "Comparison" }), _jsx("th", { className: "bg-[var(--bg)] px-[14px] py-2 text-right text-[10px] font-bold tracking-[0.6px] text-[var(--sub)] uppercase", children: "\u0394" })] }) }), _jsx("tbody", { children: [
|
|
517
|
+
{
|
|
518
|
+
label: 'Form entries',
|
|
519
|
+
cur: entriesCur,
|
|
520
|
+
prev: entriesPrev,
|
|
521
|
+
fmt: (value) => number.format(Math.round(value)),
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
label: 'Organic sessions',
|
|
525
|
+
cur: sessionsCur,
|
|
526
|
+
prev: sessionsPrev,
|
|
527
|
+
fmt: (value) => number.format(Math.round(value)),
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
label: 'Pageviews',
|
|
531
|
+
cur: viewsCur,
|
|
532
|
+
prev: viewsPrev,
|
|
533
|
+
fmt: (value) => number.format(Math.round(value)),
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
label: 'Entries / day',
|
|
537
|
+
cur: entriesCur /
|
|
538
|
+
(report?.range.days ?? inclusiveDays(range.start, range.end)),
|
|
539
|
+
prev: entriesPrev !== null
|
|
540
|
+
? entriesPrev /
|
|
541
|
+
(report?.range.days ?? inclusiveDays(range.start, range.end))
|
|
542
|
+
: null,
|
|
543
|
+
fmt: (value) => value.toFixed(1),
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
label: 'Conversion rate',
|
|
547
|
+
cur: convCur,
|
|
548
|
+
prev: convPrev,
|
|
549
|
+
fmt: (value) => `${value.toFixed(2)}%`,
|
|
550
|
+
},
|
|
551
|
+
].map((row) => (_jsxs("tr", { className: "hover:bg-[var(--bg)]", children: [_jsx("td", { className: "px-[14px] py-[10px] text-[13px] text-[var(--sub)]", children: row.label }), _jsx("td", { className: "px-[14px] py-[10px] text-right text-[13.5px] font-[650] text-[var(--txt)] tabular-nums", children: row.cur !== null ? row.fmt(row.cur) : '—' }), _jsx("td", { className: "px-[14px] py-[10px] text-right text-[11px] text-[var(--sub)] tabular-nums", children: comparing && row.prev !== null ? row.fmt(row.prev) : '—' }), _jsx("td", { className: "px-[14px] py-[10px] text-right", children: comparing && row.cur !== null && row.prev !== null ? (_jsx(Delta, { cur: row.cur, prev: row.prev })) : (_jsx("span", { className: "text-[11px] text-[var(--sub)]", children: "\u2014" })) })] }, row.label))) })] }) }) })] }), _jsxs("div", { className: "grid gap-[14px] min-[821px]:max-[1180px]:grid-cols-2 min-[1181px]:grid-cols-3", children: [_jsxs(DashboardCard, { title: "Content health", subtitle: "SEO & quality issues", action: _jsx("button", { type: "button", className: "text-[12.5px] text-[var(--acc)] hover:underline", onClick: () => nav('/seo'), children: "Open SEO" }), children: [_jsxs("div", { className: "flex items-center gap-[14px] border-b border-[var(--bdr)] px-4 py-[15px]", children: [_jsx(HealthRing, { score: contentHealth.score }), _jsxs("div", { children: [_jsxs("div", { className: "text-[13.5px] font-semibold text-[var(--txt)]", children: [contentHealth.score, "/100 \u00B7 ", contentHealth.label] }), _jsxs("div", { className: "mt-[3px] text-[11.5px] leading-[1.5] text-[var(--sub)]", children: [contentHealth.total, " issues across ", contentHealth.issues.length, " categories"] })] })] }), contentHealth.loading && !contentHealth.hasData ? (_jsx("div", { className: "flex flex-col gap-2 px-4 py-3", "aria-hidden": true, children: [0, 1, 2].map((row) => (_jsx("div", { className: "h-[18px] rounded bg-[var(--bg)]" }, row))) })) : contentHealth.issues.length === 0 ? (_jsx("p", { className: "px-4 py-4 text-[12.5px] text-[var(--sub)]", children: "No outstanding issues. Nice work." })) : (contentHealth.issues.map((issue) => (_jsxs("button", { type: "button", onClick: () => nav('/seo'), className: "flex w-full items-center gap-[9px] border-b border-[var(--bdr)] px-4 py-[9px] text-left text-[12.5px] text-[var(--sub)] transition last:border-b-0 hover:bg-[var(--bg)]", children: [_jsx("span", { className: "h-[7px] w-[7px] shrink-0 rounded-full", style: { background: issue.dot }, "aria-hidden": true }), issue.label, _jsx("b", { className: "ml-auto font-bold text-[var(--txt)] tabular-nums", children: issue.count })] }, issue.kind))))] }), _jsx(DashboardCard, { title: "Delivery API", subtitle: "Headless content delivery \u00B7 last 24 hours", action: _jsx("button", { type: "button", className: "text-[12.5px] text-[var(--acc)] hover:underline", onClick: () => nav('/settings?tab=api-keys'), children: "API docs" }), children: _jsx(DeliveryGrid, { delivery: delivery, loading: deliveryLoading }) }), _jsx("div", { className: "min-[821px]:max-[1180px]:col-span-full", children: _jsx(DashboardCard, { title: "Publishing queue", subtitle: `${scheduled?.total ?? 0} items scheduled`, action: _jsx("button", { type: "button", className: "text-[12.5px] text-[var(--acc)] hover:underline", onClick: () => nav('/posts?status=scheduled'), children: "Manage" }), children: (scheduled?.items.length ?? 0) === 0 ? (_jsx(EmptyState, { icon: Clock, title: "No scheduled content", subtitle: "Scheduled posts and pages appear here.", compact: true })) : (_jsx("ul", { role: "list", children: scheduled.items.map((item) => {
|
|
552
|
+
const col = collections.find((entry) => entry.slug === item.collection);
|
|
553
|
+
const date = new Date(item.scheduledFor);
|
|
554
|
+
return (_jsx("li", { className: "border-b border-[var(--bdr)] last:border-b-0", children: _jsxs("button", { type: "button", onClick: () => nav(editPathForDoc(col, item.collection, item.id)), className: "flex w-full items-center gap-[11px] px-4 py-[11px] text-left transition hover:bg-[var(--bg)]", children: [_jsxs("span", { className: "w-[42px] shrink-0 rounded-[8px] bg-[var(--acc-l)] px-0 py-[5px] text-center leading-[1.1]", children: [_jsx("b", { className: "block text-[15px] font-bold text-[var(--acc)]", children: date.getDate() }), _jsx("span", { className: "block text-[9.5px] font-bold tracking-[0.5px] text-[var(--acc)] uppercase opacity-75", children: date.toLocaleDateString('en-US', { month: 'short' }) })] }), _jsxs("span", { className: "min-w-0", children: [_jsx("span", { className: "block truncate text-[13px] font-medium text-[var(--txt)]", children: item.title }), _jsxs("span", { className: "mt-[2px] block truncate text-[11.5px] text-[var(--sub)]", children: [col ? collectionLabel(col, false) : item.collection, " \u00B7", ' ', item.author] })] })] }) }, item.id));
|
|
555
|
+
}) })) }) })] })] }))] }) }));
|
|
556
|
+
}
|
|
557
|
+
function DashboardCard({ title, subtitle, action, children, }) {
|
|
558
|
+
return (_jsxs("section", { className: "overflow-hidden rounded-[10px] border border-[var(--bdr)] bg-[var(--card)] shadow-[var(--shd)]", children: [_jsxs("header", { className: "flex items-center gap-[10px] border-b border-[var(--bdr)] px-4 py-[13px]", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("h2", { className: "text-[14px] font-semibold text-[var(--txt)]", children: title }), subtitle ? _jsx("p", { className: "mt-[2px] text-[11.5px] text-[var(--sub)]", children: subtitle }) : null] }), action ? _jsx("div", { className: "ml-auto", children: action }) : null] }), children] }));
|
|
559
|
+
}
|
|
560
|
+
function HealthRing({ score }) {
|
|
561
|
+
const radius = 26;
|
|
562
|
+
const circumference = 2 * Math.PI * radius;
|
|
563
|
+
const color = score >= 70 ? 'var(--suc)' : score >= 40 ? 'var(--warn)' : 'var(--err)';
|
|
564
|
+
return (_jsxs("div", { className: "relative h-16 w-16 shrink-0", "aria-hidden": true, children: [_jsxs("svg", { width: "64", height: "64", children: [_jsx("circle", { cx: "32", cy: "32", r: radius, fill: "none", stroke: "var(--bdr)", strokeWidth: "6" }), _jsx("circle", { cx: "32", cy: "32", r: radius, fill: "none", stroke: color, strokeWidth: "6", strokeLinecap: "round", strokeDasharray: circumference, strokeDashoffset: circumference * (1 - Math.max(0, Math.min(100, score)) / 100), transform: "rotate(-90 32 32)" })] }), _jsx("div", { className: "absolute inset-0 flex items-center justify-center text-[20px] font-bold tracking-[-0.5px]", style: { color }, children: score })] }));
|
|
565
|
+
}
|
|
566
|
+
function EmptyState({ icon: Icon, title, subtitle, compact = false, action, }) {
|
|
567
|
+
return (_jsxs("div", { className: `flex flex-col items-center justify-center gap-1.5 text-center ${compact ? 'px-4 py-6' : 'px-6 py-10'}`, children: [_jsx(Icon, { className: "mb-1 h-7 w-7 text-[var(--muted)]", "aria-hidden": true }), _jsx("p", { className: "text-sm font-medium text-[var(--txt)]", children: title }), _jsx("p", { className: "max-w-xs text-xs text-[var(--sub)]", children: subtitle }), action] }));
|
|
442
568
|
}
|
|
443
|
-
// ─── Delivery API grid ──────────────────────────────────────────────────────
|
|
444
569
|
function DeliveryGrid({ delivery, loading }) {
|
|
445
570
|
if (loading && !delivery) {
|
|
446
|
-
return (_jsx("div", { className: "
|
|
571
|
+
return (_jsx("div", { className: "grid grid-cols-2 gap-px bg-[var(--bdr)]", "aria-busy": true, children: [0, 1, 2, 3].map((tile) => (_jsxs("div", { className: "bg-[var(--card)] p-[13px_16px]", children: [_jsx("div", { className: "mb-2 h-3 w-24 rounded bg-[var(--bg)]" }), _jsx("div", { className: "mb-1.5 h-6 w-20 rounded bg-[var(--bg)]" }), _jsx("div", { className: "h-3 w-28 rounded bg-[var(--bg)]" })] }, tile))) }));
|
|
447
572
|
}
|
|
448
573
|
const hasData = delivery?.hasData ?? false;
|
|
449
574
|
const requests = delivery?.requests24h ?? 0;
|
|
@@ -453,29 +578,47 @@ function DeliveryGrid({ delivery, loading }) {
|
|
|
453
578
|
const p95Latency = delivery?.p95LatencyMs ?? 0;
|
|
454
579
|
const webhookTotal = delivery?.webhookCount ?? 0;
|
|
455
580
|
const webhookActive = delivery?.webhookActiveCount ?? 0;
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
581
|
+
const tiles = [
|
|
582
|
+
{
|
|
583
|
+
icon: Activity,
|
|
584
|
+
label: 'Requests (24h)',
|
|
585
|
+
value: hasData ? formatLargeNumber(requests) : '—',
|
|
586
|
+
sub: !hasData
|
|
587
|
+
? 'no traffic recorded yet'
|
|
588
|
+
: delta === null
|
|
589
|
+
? 'no prior baseline'
|
|
590
|
+
: `${delta >= 0 ? '+' : ''}${delta.toFixed(1)}% vs yesterday`,
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
icon: AlertCircle,
|
|
594
|
+
label: 'Error rate',
|
|
595
|
+
value: hasData ? `${(errorRate * 100).toFixed(2)}%` : '—',
|
|
596
|
+
sub: !hasData
|
|
597
|
+
? 'no traffic recorded yet'
|
|
598
|
+
: errorRate < 0.005
|
|
599
|
+
? 'healthy'
|
|
600
|
+
: errorRate < 0.05
|
|
601
|
+
? 'elevated'
|
|
602
|
+
: 'investigate',
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
icon: Gauge,
|
|
606
|
+
label: 'Avg response',
|
|
607
|
+
value: hasData ? `${Math.round(avgLatency)}ms` : '—',
|
|
608
|
+
sub: hasData ? `p95 · ${p95Latency}ms` : 'no traffic recorded yet',
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
icon: Zap,
|
|
612
|
+
label: 'Webhooks',
|
|
613
|
+
value: `${webhookActive} / ${webhookTotal}`,
|
|
614
|
+
sub: webhookTotal === 0
|
|
615
|
+
? 'none configured'
|
|
616
|
+
: webhookActive === webhookTotal
|
|
617
|
+
? 'All active'
|
|
618
|
+
: `${webhookTotal - webhookActive} paused`,
|
|
619
|
+
},
|
|
620
|
+
];
|
|
621
|
+
return (_jsx("div", { className: "grid grid-cols-2 gap-px bg-[var(--bdr)]", children: tiles.map((tile) => (_jsxs("div", { className: "bg-[var(--card)] p-[13px_16px]", children: [_jsxs("div", { className: "flex items-center gap-[6px] text-[10.5px] font-bold tracking-[0.5px] text-[var(--sub)] uppercase", children: [_jsx(tile.icon, { size: 13, "aria-hidden": true }), tile.label] }), _jsx("p", { className: "mt-[5px] text-[20px] leading-tight font-bold tracking-[-0.5px] text-[var(--txt)] tabular-nums", children: tile.value }), _jsx("p", { className: "mt-[2px] text-[11px] text-[var(--sub)]", children: tile.sub })] }, tile.label))) }));
|
|
479
622
|
}
|
|
480
623
|
function formatLargeNumber(n) {
|
|
481
624
|
if (n < 1000)
|
|
@@ -486,18 +629,4 @@ function formatLargeNumber(n) {
|
|
|
486
629
|
return `${(n / 1000).toFixed(0)}K`;
|
|
487
630
|
return `${(n / 1_000_000).toFixed(1)}M`;
|
|
488
631
|
}
|
|
489
|
-
// ─── Sub-components (kept in-file: smaller bundle, no extra module hops) ────
|
|
490
|
-
function EmptyState({ icon: Icon, title, subtitle, compact = false, }) {
|
|
491
|
-
return (_jsxs("div", { className: `flex flex-col items-center justify-center gap-1.5 text-center ${compact ? 'px-4 py-6' : 'px-6 py-10'}`, children: [_jsx(Icon, { className: "text-muted-foreground/50 mb-1 h-7 w-7", "aria-hidden": true }), _jsx("p", { className: "text-foreground text-sm font-medium", children: title }), _jsx("p", { className: "text-muted-foreground max-w-xs text-xs", children: subtitle })] }));
|
|
492
|
-
}
|
|
493
|
-
function DeliveryTile({ icon: Icon, label, value, sub, subIcon: SubIcon, tone = 'muted', }) {
|
|
494
|
-
const subTone = tone === 'ok'
|
|
495
|
-
? 'text-success'
|
|
496
|
-
: tone === 'warn'
|
|
497
|
-
? 'text-warning'
|
|
498
|
-
: tone === 'err'
|
|
499
|
-
? 'text-destructive dark:text-red-400'
|
|
500
|
-
: 'text-muted-foreground';
|
|
501
|
-
return (_jsxs("div", { className: "px-6 py-4", children: [_jsxs("div", { className: "text-muted-foreground mb-1 flex items-center gap-1.5", children: [_jsx(Icon, { className: "h-3.5 w-3.5", "aria-hidden": true }), _jsx("span", { className: "text-[11px] font-medium", children: label })] }), _jsx("p", { className: "text-foreground text-xl leading-tight font-medium tracking-tight", children: value }), sub && (_jsxs("p", { className: `mt-0.5 inline-flex items-center gap-1 text-[11px] ${subTone}`, children: [SubIcon && _jsx(SubIcon, { className: "h-3 w-3 shrink-0", "aria-hidden": true }), sub] }))] }));
|
|
502
|
-
}
|
|
503
632
|
//# sourceMappingURL=Dashboard.js.map
|