medusa-analytics 0.0.23 → 0.0.25
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/.medusa/server/src/admin/index.js +375 -3760
- package/.medusa/server/src/admin/index.mjs +380 -3765
- package/.medusa/server/src/api/admin/analytics/customers-over-time/route.js +7 -14
- package/.medusa/server/src/api/admin/analytics/customers-summary/route.js +7 -14
- package/.medusa/server/src/api/admin/analytics/orders-over-time/route.js +100 -192
- package/.medusa/server/src/api/admin/analytics/orders-over-time/types.js +1 -1
- package/.medusa/server/src/api/admin/analytics/orders-summary/route.js +38 -9
- package/README.md +255 -131
- package/package.json +1 -1
- package/.medusa/server/src/api/admin/analytics/fetch-orders-for-analytics.js +0 -117
- package/.medusa/server/src/api/admin/analytics/orders-analytics-helpers.js +0 -64
- package/.medusa/server/src/api/admin/analytics/orders-insights/route.js +0 -261
- package/.medusa/server/src/api/admin/analytics/orders-insights/types.js +0 -3
- package/.medusa/server/src/api/admin/analytics/products/shared.js +0 -719
- package/.medusa/server/src/api/admin/analytics/products-filters/route.js +0 -21
- package/.medusa/server/src/api/admin/analytics/products-filters/types.js +0 -3
- package/.medusa/server/src/api/admin/analytics/products-over-time/route.js +0 -28
- package/.medusa/server/src/api/admin/analytics/products-over-time/types.js +0 -3
- package/.medusa/server/src/api/admin/analytics/products-performance/route.js +0 -51
- package/.medusa/server/src/api/admin/analytics/products-performance/types.js +0 -3
- package/.medusa/server/src/api/admin/analytics/products-summary/route.js +0 -36
- package/.medusa/server/src/api/admin/analytics/products-summary/types.js +0 -3
- package/.medusa/server/src/api/admin/analytics/products-top-sellers/route.js +0 -48
- package/.medusa/server/src/api/admin/analytics/products-top-sellers/types.js +0 -3
- package/.medusa/server/src/api/admin/analytics/repeat-customers/route.js +0 -77
- package/.medusa/server/src/api/admin/analytics/repeat-customers/types.js +0 -3
- package/index.js +0 -5
|
@@ -1,276 +1,53 @@
|
|
|
1
|
-
import { jsx, jsxs
|
|
2
|
-
import { useState,
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
3
|
import { defineRouteConfig } from "@medusajs/admin-sdk";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ResponsiveContainer,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
band: "from-sky-400/70 via-blue-400/30 to-transparent"
|
|
12
|
-
},
|
|
13
|
-
purple: {
|
|
14
|
-
border: "border-fuchsia-400/25",
|
|
15
|
-
glow: "shadow-[0_0_0_1px_rgba(217,70,239,0.10),0_18px_40px_-28px_rgba(168,85,247,0.5)]",
|
|
16
|
-
band: "from-fuchsia-400/65 via-violet-400/25 to-transparent"
|
|
17
|
-
},
|
|
18
|
-
green: {
|
|
19
|
-
border: "border-emerald-400/25",
|
|
20
|
-
glow: "shadow-[0_0_0_1px_rgba(52,211,153,0.10),0_18px_40px_-28px_rgba(16,185,129,0.45)]",
|
|
21
|
-
band: "from-emerald-400/65 via-teal-400/25 to-transparent"
|
|
22
|
-
},
|
|
23
|
-
amber: {
|
|
24
|
-
border: "border-amber-400/25",
|
|
25
|
-
glow: "shadow-[0_0_0_1px_rgba(251,191,36,0.10),0_18px_40px_-28px_rgba(245,158,11,0.45)]",
|
|
26
|
-
band: "from-amber-400/65 via-orange-400/25 to-transparent"
|
|
27
|
-
},
|
|
28
|
-
rose: {
|
|
29
|
-
border: "border-rose-400/25",
|
|
30
|
-
glow: "shadow-[0_0_0_1px_rgba(251,113,133,0.10),0_18px_40px_-28px_rgba(244,63,94,0.45)]",
|
|
31
|
-
band: "from-rose-400/65 via-pink-400/25 to-transparent"
|
|
32
|
-
},
|
|
33
|
-
slate: {
|
|
34
|
-
border: "border-ui-border-strong",
|
|
35
|
-
glow: "shadow-[0_0_0_1px_rgba(15,23,42,0.05),0_18px_40px_-28px_rgba(15,23,42,0.22)]",
|
|
36
|
-
band: "from-ui-border-strong via-ui-border-base to-transparent"
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
function getAccentStyle(accent) {
|
|
40
|
-
return ACCENT_STYLES[accent];
|
|
41
|
-
}
|
|
42
|
-
function AnalyticsDashboardShell({ children, className }) {
|
|
43
|
-
return /* @__PURE__ */ jsx("div", { className: ["space-y-2.5 md:space-y-3", className].filter(Boolean).join(" "), children });
|
|
44
|
-
}
|
|
45
|
-
function AnalyticsDashboardHeader({
|
|
46
|
-
title,
|
|
47
|
-
description,
|
|
48
|
-
actions,
|
|
49
|
-
variant = "default",
|
|
50
|
-
actionsBare = false,
|
|
51
|
-
appearance = "card",
|
|
52
|
-
actionsClassName
|
|
53
|
-
}) {
|
|
54
|
-
const isPremium = variant === "premium";
|
|
55
|
-
const isInset = appearance === "inset";
|
|
56
|
-
const headerRow = /* @__PURE__ */ jsxs(
|
|
57
|
-
"div",
|
|
58
|
-
{
|
|
59
|
-
className: `flex flex-col gap-2 px-4 py-2.5 lg:flex-row lg:items-center lg:justify-between lg:gap-4 ${isPremium ? "border-b border-ui-border-base/80" : "border-b border-ui-border-base"}`.trim(),
|
|
60
|
-
children: [
|
|
61
|
-
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 space-y-0.5", children: [
|
|
62
|
-
/* @__PURE__ */ jsx(Heading, { level: "h2", className: isPremium ? "text-lg font-semibold tracking-tight" : "tracking-tight", children: title }),
|
|
63
|
-
description ? /* @__PURE__ */ jsx(Text, { className: `text-ui-fg-muted ${isPremium ? "max-w-2xl text-xs leading-snug" : "text-sm"}`.trim(), children: description }) : null
|
|
64
|
-
] }),
|
|
65
|
-
actions ? actionsBare ? /* @__PURE__ */ jsx(
|
|
66
|
-
"div",
|
|
67
|
-
{
|
|
68
|
-
className: [
|
|
69
|
-
"flex flex-wrap items-center gap-3 self-start lg:shrink-0 lg:self-auto",
|
|
70
|
-
actionsClassName ?? ""
|
|
71
|
-
].join(" ").trim(),
|
|
72
|
-
children: actions
|
|
73
|
-
}
|
|
74
|
-
) : /* @__PURE__ */ jsx(
|
|
75
|
-
"div",
|
|
76
|
-
{
|
|
77
|
-
className: `flex self-start rounded-xl border px-2 py-1.5 lg:self-auto ${isPremium ? "border-ui-border-strong bg-ui-bg-subtle shadow-[inset_0_1px_0_rgba(255,255,255,0.35)]" : "border-ui-border-base bg-ui-bg-subtle"}`.trim(),
|
|
78
|
-
children: actions
|
|
79
|
-
}
|
|
80
|
-
) : null
|
|
81
|
-
]
|
|
82
|
-
}
|
|
83
|
-
);
|
|
84
|
-
if (isInset) {
|
|
85
|
-
return /* @__PURE__ */ jsx("div", { className: "border-0 bg-transparent p-0 shadow-none", children: headerRow });
|
|
86
|
-
}
|
|
87
|
-
return /* @__PURE__ */ jsxs(
|
|
88
|
-
Container,
|
|
89
|
-
{
|
|
90
|
-
className: `overflow-hidden rounded-2xl border bg-ui-bg-base p-0 ${isPremium ? "border-ui-border-strong shadow-sm" : "border-ui-border-base shadow-sm"}`.trim(),
|
|
91
|
-
children: [
|
|
92
|
-
headerRow,
|
|
93
|
-
/* @__PURE__ */ jsx(
|
|
94
|
-
"div",
|
|
95
|
-
{
|
|
96
|
-
className: `h-px w-full ${isPremium ? "bg-gradient-to-r from-transparent via-ui-border-strong to-transparent" : "bg-ui-bg-subtle"}`.trim()
|
|
97
|
-
}
|
|
98
|
-
)
|
|
99
|
-
]
|
|
100
|
-
}
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
function AnalyticsStatCard({
|
|
104
|
-
label,
|
|
105
|
-
value,
|
|
106
|
-
helper,
|
|
107
|
-
className,
|
|
108
|
-
valueClassName,
|
|
109
|
-
variant = "default",
|
|
110
|
-
accent = "slate"
|
|
111
|
-
}) {
|
|
112
|
-
const accentStyle = getAccentStyle(accent);
|
|
113
|
-
const isHero = variant === "hero";
|
|
114
|
-
const isCompact = variant === "compact";
|
|
115
|
-
return /* @__PURE__ */ jsxs(
|
|
116
|
-
Container,
|
|
117
|
-
{
|
|
118
|
-
className: `relative h-full overflow-hidden rounded-2xl border bg-ui-bg-base transition-shadow ${isHero ? `p-3 ${accentStyle.border} ${accentStyle.glow} shadow-sm` : isCompact ? "border-ui-border-base bg-ui-bg-subtle/70 p-2.5 shadow-none" : "border-ui-border-base p-4 shadow-sm"} ${className ?? ""}`.trim(),
|
|
119
|
-
children: [
|
|
120
|
-
isHero ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
121
|
-
/* @__PURE__ */ jsx(
|
|
122
|
-
"div",
|
|
123
|
-
{
|
|
124
|
-
className: `pointer-events-none absolute inset-x-3 top-0 h-10 rounded-b-full bg-gradient-to-r ${accentStyle.band} blur-xl`
|
|
125
|
-
}
|
|
126
|
-
),
|
|
127
|
-
/* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-x-3 top-0 h-px bg-gradient-to-r from-transparent via-white/40 to-transparent" })
|
|
128
|
-
] }) : null,
|
|
129
|
-
/* @__PURE__ */ jsxs(
|
|
130
|
-
"div",
|
|
131
|
-
{
|
|
132
|
-
className: `relative flex flex-col justify-between gap-1 ${isCompact ? "min-h-[64px]" : isHero ? "min-h-[72px]" : "min-h-[92px]"}`.trim(),
|
|
133
|
-
children: [
|
|
134
|
-
/* @__PURE__ */ jsx(
|
|
135
|
-
Text,
|
|
136
|
-
{
|
|
137
|
-
className: `text-ui-fg-muted font-medium ${isHero ? "text-[10px] uppercase tracking-[0.16em]" : "text-xs"}`.trim(),
|
|
138
|
-
children: label
|
|
139
|
-
}
|
|
140
|
-
),
|
|
141
|
-
/* @__PURE__ */ jsx(
|
|
142
|
-
Heading,
|
|
143
|
-
{
|
|
144
|
-
level: "h2",
|
|
145
|
-
className: `leading-tight tracking-tight ${isHero ? "text-xl sm:text-2xl" : isCompact ? "text-lg" : "text-2xl"} ${valueClassName ?? ""}`.trim(),
|
|
146
|
-
children: value
|
|
147
|
-
}
|
|
148
|
-
),
|
|
149
|
-
helper ? /* @__PURE__ */ jsx(Text, { className: `text-ui-fg-muted leading-snug ${isHero ? "text-[10px]" : "text-xs"}`.trim(), children: helper }) : null
|
|
150
|
-
]
|
|
151
|
-
}
|
|
152
|
-
)
|
|
153
|
-
]
|
|
154
|
-
}
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
function AnalyticsSection({
|
|
158
|
-
title,
|
|
159
|
-
description,
|
|
160
|
-
actions,
|
|
161
|
-
children,
|
|
162
|
-
className,
|
|
163
|
-
variant = "default",
|
|
164
|
-
actionsBare = false
|
|
165
|
-
}) {
|
|
166
|
-
const isAtlas = variant === "atlas";
|
|
167
|
-
const isPremium = variant !== "default" && !isAtlas;
|
|
168
|
-
const shellClass = isAtlas ? "min-w-0 overflow-x-clip overflow-y-visible rounded-lg border border-ui-border-base bg-ui-bg-base shadow-sm" : `overflow-hidden rounded-2xl border bg-ui-bg-base p-0 ${isPremium ? "border-ui-border-strong shadow-sm" : "border-ui-border-base shadow-sm"}`.trim();
|
|
169
|
-
const headerClass = isAtlas ? "flex flex-col gap-1 border-b border-ui-border-base bg-ui-bg-subtle/40 px-3 py-2 lg:flex-row lg:items-center lg:justify-between" : `flex flex-col gap-2 px-4 py-2.5 lg:flex-row lg:items-center lg:justify-between ${isPremium ? "border-b border-ui-border-base/80" : "border-b border-ui-border-base"}`.trim();
|
|
170
|
-
const titleClass = isAtlas ? "text-sm font-semibold tracking-tight text-ui-fg-base" : isPremium ? "text-base font-semibold tracking-tight" : "tracking-tight";
|
|
171
|
-
const descClass = isAtlas ? "max-w-2xl text-[11px] leading-snug text-ui-fg-muted" : isPremium ? "max-w-2xl text-xs leading-snug" : "text-sm";
|
|
172
|
-
const actionsShellClass = isAtlas ? "flex shrink-0 flex-wrap items-center gap-1.5 rounded-md border border-ui-border-base bg-ui-bg-base px-2 py-1" : `flex shrink-0 flex-wrap items-center gap-1.5 rounded-xl border px-2 py-1.5 ${isPremium ? "border-ui-border-strong bg-ui-bg-subtle shadow-[inset_0_1px_0_rgba(255,255,255,0.32)]" : "border-ui-border-base bg-ui-bg-subtle"}`.trim();
|
|
173
|
-
const bodyClass = isAtlas ? "p-2" : variant === "hero" ? "px-4 py-3" : "px-4 py-3";
|
|
174
|
-
return /* @__PURE__ */ jsxs(Container, { className: `${shellClass} ${className ?? ""}`.trim(), children: [
|
|
175
|
-
/* @__PURE__ */ jsxs("div", { className: headerClass, children: [
|
|
176
|
-
/* @__PURE__ */ jsxs("div", { className: "min-w-0 space-y-0.5", children: [
|
|
177
|
-
/* @__PURE__ */ jsx(Heading, { level: "h3", className: titleClass, children: title }),
|
|
178
|
-
description ? /* @__PURE__ */ jsx(Text, { className: `text-ui-fg-muted ${descClass}`.trim(), children: description }) : null
|
|
179
|
-
] }),
|
|
180
|
-
actions ? actionsBare ? /* @__PURE__ */ jsx("div", { className: "flex shrink-0 flex-wrap items-center gap-2", children: actions }) : /* @__PURE__ */ jsx("div", { className: actionsShellClass, children: actions }) : null
|
|
181
|
-
] }),
|
|
182
|
-
/* @__PURE__ */ jsx("div", { className: bodyClass, children })
|
|
183
|
-
] });
|
|
184
|
-
}
|
|
185
|
-
function AnalyticsChartSurface({
|
|
186
|
-
children,
|
|
187
|
-
className,
|
|
188
|
-
variant = "default"
|
|
189
|
-
}) {
|
|
190
|
-
const surfaceClassName = variant === "atlas" ? "rounded-lg border border-ui-border-base bg-ui-bg-subtle/50 p-2 shadow-sm" : variant === "glass" ? "rounded-xl border border-ui-border-strong bg-[linear-gradient(180deg,rgba(255,255,255,0.12),rgba(255,255,255,0.03))] p-2.5 shadow-[inset_0_1px_0_rgba(255,255,255,0.22)]" : variant === "panel" ? "rounded-xl border border-ui-border-base/90 bg-ui-bg-base p-2.5 shadow-[inset_0_1px_0_rgba(255,255,255,0.18)]" : "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-2 shadow-inner";
|
|
191
|
-
return /* @__PURE__ */ jsx(
|
|
192
|
-
"div",
|
|
193
|
-
{
|
|
194
|
-
className: `${surfaceClassName} ${className ?? ""}`.trim(),
|
|
195
|
-
children
|
|
196
|
-
}
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
function AnalyticsTableSurface({ children, className }) {
|
|
200
|
-
return /* @__PURE__ */ jsx(
|
|
201
|
-
"div",
|
|
202
|
-
{
|
|
203
|
-
className: [
|
|
204
|
-
"min-w-0 overflow-x-auto overflow-y-visible rounded-xl border border-ui-border-base bg-ui-bg-base",
|
|
205
|
-
"[scrollbar-width:thin]",
|
|
206
|
-
className ?? ""
|
|
207
|
-
].join(" ").trim(),
|
|
208
|
-
children
|
|
209
|
-
}
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
function AnalyticsTooltipCard({
|
|
213
|
-
title,
|
|
214
|
-
children,
|
|
215
|
-
variant = "default"
|
|
4
|
+
import { ChartBar } from "@medusajs/icons";
|
|
5
|
+
import { Text, Container, Heading, Label, Button } from "@medusajs/ui";
|
|
6
|
+
import { ResponsiveContainer, PieChart, Pie, Cell, Tooltip, Legend, LineChart, CartesianGrid, XAxis, YAxis, Line } from "recharts";
|
|
7
|
+
function OrdersOverTimeTooltip({
|
|
8
|
+
active,
|
|
9
|
+
payload,
|
|
10
|
+
label
|
|
216
11
|
}) {
|
|
217
|
-
|
|
12
|
+
var _a, _b;
|
|
13
|
+
if (!active || !(payload == null ? void 0 : payload.length)) return null;
|
|
14
|
+
const row = (_a = payload[0]) == null ? void 0 : _a.payload;
|
|
15
|
+
const displayLabel = (row == null ? void 0 : row.label) ?? (label ? new Date(label).toLocaleDateString() : label);
|
|
16
|
+
const value = ((_b = payload[0]) == null ? void 0 : _b.value) ?? 0;
|
|
218
17
|
return /* @__PURE__ */ jsxs(
|
|
219
18
|
"div",
|
|
220
19
|
{
|
|
221
20
|
style: {
|
|
222
|
-
|
|
21
|
+
backgroundColor: "rgb(250, 234, 234)",
|
|
223
22
|
color: "#111827",
|
|
224
|
-
border: "1px solid
|
|
225
|
-
borderRadius:
|
|
226
|
-
padding:
|
|
227
|
-
boxShadow:
|
|
228
|
-
fontSize:
|
|
229
|
-
lineHeight:
|
|
230
|
-
minWidth: compact ? 0 : 176,
|
|
231
|
-
maxWidth: compact ? "min(92vw, 200px)" : "min(96vw, 380px)"
|
|
23
|
+
border: "1px solid rgb(229, 231, 235)",
|
|
24
|
+
borderRadius: "8px",
|
|
25
|
+
padding: "12px 16px",
|
|
26
|
+
boxShadow: "0 4px 14px rgba(102, 102, 102, 0.99)",
|
|
27
|
+
fontSize: "14px",
|
|
28
|
+
lineHeight: 1.5
|
|
232
29
|
},
|
|
233
30
|
children: [
|
|
234
|
-
/* @__PURE__ */ jsx(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
marginBottom: compact ? "2px" : "6px",
|
|
240
|
-
fontSize: compact ? "10px" : "inherit",
|
|
241
|
-
lineHeight: compact ? 1.25 : 1.35,
|
|
242
|
-
wordBreak: "break-word"
|
|
243
|
-
},
|
|
244
|
-
children: title
|
|
245
|
-
}
|
|
246
|
-
),
|
|
247
|
-
children
|
|
31
|
+
/* @__PURE__ */ jsx("div", { style: { fontWeight: 600, marginBottom: "6px", color: "#111827" }, children: displayLabel }),
|
|
32
|
+
/* @__PURE__ */ jsxs("div", { style: { color: "#374151" }, children: [
|
|
33
|
+
"Orders: ",
|
|
34
|
+
/* @__PURE__ */ jsx("strong", { style: { color: "#1f2937" }, children: value })
|
|
35
|
+
] })
|
|
248
36
|
]
|
|
249
37
|
}
|
|
250
38
|
);
|
|
251
39
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
return Math.max(0, d.total_revenue - (d.revenue_cancelled ?? 0));
|
|
264
|
-
}
|
|
265
|
-
function bucketAov(d) {
|
|
266
|
-
const ordNc = d.orders_count - d.cancelled_count;
|
|
267
|
-
if (ordNc <= 0) return 0;
|
|
268
|
-
return nonCancelledRevenue(d) / ordNc;
|
|
269
|
-
}
|
|
270
|
-
function isOrdersTodayPoint(value) {
|
|
271
|
-
return isDailyOrderRow(value) && "isToday" in value && typeof value.isToday === "boolean";
|
|
272
|
-
}
|
|
273
|
-
function formatCurrency$1(value) {
|
|
40
|
+
const STATUS_COLORS = {
|
|
41
|
+
pending: "#F59E0B",
|
|
42
|
+
cancelled: "#EF4444",
|
|
43
|
+
delivered: "#10B981"
|
|
44
|
+
};
|
|
45
|
+
const ORDER_CHART_STATUSES = [
|
|
46
|
+
{ key: "pending", label: "Pending", color: STATUS_COLORS.pending },
|
|
47
|
+
{ key: "cancelled", label: "Cancelled", color: STATUS_COLORS.cancelled },
|
|
48
|
+
{ key: "delivered", label: "Delivered", color: STATUS_COLORS.delivered }
|
|
49
|
+
];
|
|
50
|
+
function formatCurrency(value) {
|
|
274
51
|
return new Intl.NumberFormat("en-IN", {
|
|
275
52
|
style: "currency",
|
|
276
53
|
currency: "INR",
|
|
@@ -278,243 +55,7 @@ function formatCurrency$1(value) {
|
|
|
278
55
|
maximumFractionDigits: 0
|
|
279
56
|
}).format(value);
|
|
280
57
|
}
|
|
281
|
-
|
|
282
|
-
return new Intl.NumberFormat("en-IN", {
|
|
283
|
-
style: "currency",
|
|
284
|
-
currency: "INR",
|
|
285
|
-
notation: "compact",
|
|
286
|
-
maximumFractionDigits: 1
|
|
287
|
-
}).format(value);
|
|
288
|
-
}
|
|
289
|
-
function formatChartLabel$2(value) {
|
|
290
|
-
if (!value) return "";
|
|
291
|
-
const parsed = new Date(value);
|
|
292
|
-
if (Number.isNaN(parsed.getTime())) return value;
|
|
293
|
-
return `${parsed.getUTCMonth() + 1}/${parsed.getUTCDate()}`;
|
|
294
|
-
}
|
|
295
|
-
function formatPercent(value) {
|
|
296
|
-
return `${value.toFixed(1)}%`;
|
|
297
|
-
}
|
|
298
|
-
function formatShortNumber$1(value) {
|
|
299
|
-
return new Intl.NumberFormat("en-IN", {
|
|
300
|
-
notation: "compact",
|
|
301
|
-
maximumFractionDigits: value < 10 ? 1 : 0
|
|
302
|
-
}).format(value);
|
|
303
|
-
}
|
|
304
|
-
const SALES_GRANULARITY_TABS = [
|
|
305
|
-
{ value: "hour", label: "Hour" },
|
|
306
|
-
{ value: "day", label: "Day" },
|
|
307
|
-
{ value: "week", label: "Week" },
|
|
308
|
-
{ value: "month", label: "Month" }
|
|
309
|
-
];
|
|
310
|
-
function getSalesBreakdownOtPeriod(g) {
|
|
311
|
-
if (g === "day") return "one_week";
|
|
312
|
-
if (g === "week") return "two_months";
|
|
313
|
-
if (g === "month") return "one_year";
|
|
314
|
-
return null;
|
|
315
|
-
}
|
|
316
|
-
function monthKeyFromDateStr(dateStr) {
|
|
317
|
-
if (dateStr.length >= 7) return dateStr.slice(0, 7);
|
|
318
|
-
return dateStr;
|
|
319
|
-
}
|
|
320
|
-
function utcSundayWeekStartKeyFromDateStr(dateStr) {
|
|
321
|
-
const parsed = new Date(dateStr);
|
|
322
|
-
if (Number.isNaN(parsed.getTime())) return dateStr;
|
|
323
|
-
const y = parsed.getUTCFullYear();
|
|
324
|
-
const m = parsed.getUTCMonth();
|
|
325
|
-
const day = parsed.getUTCDate();
|
|
326
|
-
const dow = parsed.getUTCDay();
|
|
327
|
-
const start = new Date(Date.UTC(y, m, day - dow));
|
|
328
|
-
const ys = start.getUTCFullYear();
|
|
329
|
-
const ms = String(start.getUTCMonth() + 1).padStart(2, "0");
|
|
330
|
-
const ds = String(start.getUTCDate()).padStart(2, "0");
|
|
331
|
-
return `${ys}-${ms}-${ds}`;
|
|
332
|
-
}
|
|
333
|
-
function formatWeekStartDm(weekStartKey) {
|
|
334
|
-
const parsed = /* @__PURE__ */ new Date(`${weekStartKey}T00:00:00.000Z`);
|
|
335
|
-
if (Number.isNaN(parsed.getTime())) return weekStartKey;
|
|
336
|
-
return `${parsed.getUTCDate()}/${parsed.getUTCMonth() + 1}`;
|
|
337
|
-
}
|
|
338
|
-
function formatDayBreakdownDm(dateStr) {
|
|
339
|
-
const parsed = new Date(dateStr);
|
|
340
|
-
if (Number.isNaN(parsed.getTime())) return dateStr;
|
|
341
|
-
return `${parsed.getUTCDate()}/${parsed.getUTCMonth() + 1}`;
|
|
342
|
-
}
|
|
343
|
-
function toDateKeyUtcFromDate(d) {
|
|
344
|
-
const y = d.getUTCFullYear();
|
|
345
|
-
const m = String(d.getUTCMonth() + 1).padStart(2, "0");
|
|
346
|
-
const day = String(d.getUTCDate()).padStart(2, "0");
|
|
347
|
-
return `${y}-${m}-${day}`;
|
|
348
|
-
}
|
|
349
|
-
function lastNWeekStartKeysUtc(n) {
|
|
350
|
-
const now = /* @__PURE__ */ new Date();
|
|
351
|
-
const todayUtc = new Date(
|
|
352
|
-
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())
|
|
353
|
-
);
|
|
354
|
-
const dow = todayUtc.getUTCDay();
|
|
355
|
-
const currentWeekStart = new Date(todayUtc);
|
|
356
|
-
currentWeekStart.setUTCDate(currentWeekStart.getUTCDate() - dow);
|
|
357
|
-
const keys = [];
|
|
358
|
-
for (let i = n - 1; i >= 0; i -= 1) {
|
|
359
|
-
const d = new Date(currentWeekStart);
|
|
360
|
-
d.setUTCDate(d.getUTCDate() - 7 * i);
|
|
361
|
-
keys.push(toDateKeyUtcFromDate(d));
|
|
362
|
-
}
|
|
363
|
-
return keys;
|
|
364
|
-
}
|
|
365
|
-
function formatMonthBucketLabel(ymKey) {
|
|
366
|
-
const [ys, ms] = ymKey.split("-");
|
|
367
|
-
const y = Number(ys);
|
|
368
|
-
const m = Number(ms);
|
|
369
|
-
if (!Number.isFinite(y) || !Number.isFinite(m)) return ymKey;
|
|
370
|
-
return new Intl.DateTimeFormat("en-IN", {
|
|
371
|
-
month: "short",
|
|
372
|
-
timeZone: "UTC"
|
|
373
|
-
}).format(new Date(Date.UTC(y, m - 1, 1)));
|
|
374
|
-
}
|
|
375
|
-
function isSalesBreakdownBarRow(value) {
|
|
376
|
-
if (typeof value !== "object" || value === null) return false;
|
|
377
|
-
const v = value;
|
|
378
|
-
return typeof v.key === "string" && typeof v.label === "string" && typeof v.orders_count === "number" && typeof v.revenue === "number";
|
|
379
|
-
}
|
|
380
|
-
function SalesBreakdownTooltip({
|
|
381
|
-
active,
|
|
382
|
-
payload
|
|
383
|
-
}) {
|
|
384
|
-
var _a, _b;
|
|
385
|
-
if (!active || !(payload == null ? void 0 : payload.length)) return null;
|
|
386
|
-
const row = isSalesBreakdownBarRow((_a = payload[0]) == null ? void 0 : _a.payload) ? (_b = payload[0]) == null ? void 0 : _b.payload : void 0;
|
|
387
|
-
if (!row) return null;
|
|
388
|
-
return /* @__PURE__ */ jsxs(AnalyticsTooltipCard, { variant: "compact", title: row.label, children: [
|
|
389
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
390
|
-
"Revenue: ",
|
|
391
|
-
/* @__PURE__ */ jsx("strong", { children: formatCurrency$1(row.revenue) })
|
|
392
|
-
] }),
|
|
393
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
394
|
-
"Orders:",
|
|
395
|
-
" ",
|
|
396
|
-
/* @__PURE__ */ jsx("strong", { children: Math.floor(row.orders_count).toLocaleString() })
|
|
397
|
-
] })
|
|
398
|
-
] });
|
|
399
|
-
}
|
|
400
|
-
function OrdersTodayTooltip({
|
|
401
|
-
active,
|
|
402
|
-
payload,
|
|
403
|
-
label
|
|
404
|
-
}) {
|
|
405
|
-
var _a, _b, _c;
|
|
406
|
-
if (!active || !(payload == null ? void 0 : payload.length)) return null;
|
|
407
|
-
const row = isOrdersTodayPoint((_a = payload[0]) == null ? void 0 : _a.payload) ? (_b = payload[0]) == null ? void 0 : _b.payload : void 0;
|
|
408
|
-
const displayLabel = (row == null ? void 0 : row.label) ?? (label ? new Date(label).toLocaleDateString() : "");
|
|
409
|
-
const orders = ((_c = payload[0]) == null ? void 0 : _c.value) ?? 0;
|
|
410
|
-
return /* @__PURE__ */ jsxs(AnalyticsTooltipCard, { variant: "compact", title: displayLabel, children: [
|
|
411
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
412
|
-
"Orders: ",
|
|
413
|
-
/* @__PURE__ */ jsx("strong", { children: Math.floor(orders).toLocaleString() })
|
|
414
|
-
] }),
|
|
415
|
-
(row == null ? void 0 : row.isToday) ? /* @__PURE__ */ jsx("div", { style: { color: "#6B7280" }, children: "Current day" }) : null
|
|
416
|
-
] });
|
|
417
|
-
}
|
|
418
|
-
function OutcomesTrendTooltip({
|
|
419
|
-
active,
|
|
420
|
-
payload,
|
|
421
|
-
label
|
|
422
|
-
}) {
|
|
423
|
-
var _a, _b;
|
|
424
|
-
if (!active || !(payload == null ? void 0 : payload.length)) return null;
|
|
425
|
-
const row = isDailyOrderRow((_a = payload[0]) == null ? void 0 : _a.payload) ? (_b = payload[0]) == null ? void 0 : _b.payload : void 0;
|
|
426
|
-
const displayLabel = (row == null ? void 0 : row.label) ?? (label ? new Date(label).toLocaleDateString() : "");
|
|
427
|
-
return /* @__PURE__ */ jsx(AnalyticsTooltipCard, { variant: "compact", title: displayLabel, children: payload.map((entry) => /* @__PURE__ */ jsxs("div", { children: [
|
|
428
|
-
entry.name,
|
|
429
|
-
":",
|
|
430
|
-
" ",
|
|
431
|
-
/* @__PURE__ */ jsx("strong", { children: Math.floor(Number(entry.value) || 0).toLocaleString() })
|
|
432
|
-
] }, String(entry.name))) });
|
|
433
|
-
}
|
|
434
|
-
function isTrendRowDetailed(value) {
|
|
435
|
-
if (!isDailyOrderRow(value)) return false;
|
|
436
|
-
const v = value;
|
|
437
|
-
return typeof v.aov === "number" && typeof v.prev_revenue === "number" && typeof v.prev_orders === "number" && typeof v.prev_aov === "number";
|
|
438
|
-
}
|
|
439
|
-
function CombinedMetricsTooltip({
|
|
440
|
-
active,
|
|
441
|
-
payload
|
|
442
|
-
}) {
|
|
443
|
-
var _a, _b;
|
|
444
|
-
if (!active || !(payload == null ? void 0 : payload.length)) return null;
|
|
445
|
-
const row = isTrendRowDetailed((_a = payload[0]) == null ? void 0 : _a.payload) ? (_b = payload[0]) == null ? void 0 : _b.payload : void 0;
|
|
446
|
-
if (!row) return null;
|
|
447
|
-
const title = row.label ?? formatChartLabel$2(row.date);
|
|
448
|
-
return /* @__PURE__ */ jsxs(AnalyticsTooltipCard, { variant: "compact", title, children: [
|
|
449
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
450
|
-
"Revenue:",
|
|
451
|
-
" ",
|
|
452
|
-
/* @__PURE__ */ jsx("strong", { children: formatCompactCurrency$1(row.total_revenue) }),
|
|
453
|
-
/* @__PURE__ */ jsxs("span", { className: "text-ui-fg-muted", children: [
|
|
454
|
-
" ",
|
|
455
|
-
"· prev ",
|
|
456
|
-
formatCompactCurrency$1(row.prev_revenue)
|
|
457
|
-
] })
|
|
458
|
-
] }),
|
|
459
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
460
|
-
"Orders:",
|
|
461
|
-
" ",
|
|
462
|
-
/* @__PURE__ */ jsx("strong", { children: Math.floor(row.orders_count).toLocaleString() }),
|
|
463
|
-
/* @__PURE__ */ jsxs("span", { className: "text-ui-fg-muted", children: [
|
|
464
|
-
" ",
|
|
465
|
-
"· prev ",
|
|
466
|
-
Math.floor(row.prev_orders).toLocaleString()
|
|
467
|
-
] })
|
|
468
|
-
] }),
|
|
469
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
470
|
-
"AOV (non-canc.):",
|
|
471
|
-
" ",
|
|
472
|
-
/* @__PURE__ */ jsx("strong", { children: formatCurrency$1(row.aov) }),
|
|
473
|
-
/* @__PURE__ */ jsxs("span", { className: "text-ui-fg-muted", children: [
|
|
474
|
-
" ",
|
|
475
|
-
"· prev ",
|
|
476
|
-
formatCurrency$1(row.prev_aov)
|
|
477
|
-
] })
|
|
478
|
-
] })
|
|
479
|
-
] });
|
|
480
|
-
}
|
|
481
|
-
const KPI_ICON_BG$2 = {
|
|
482
|
-
green: "bg-emerald-500/20",
|
|
483
|
-
blue: "bg-sky-500/20",
|
|
484
|
-
purple: "bg-violet-500/20",
|
|
485
|
-
amber: "bg-amber-500/20"
|
|
486
|
-
};
|
|
487
|
-
const KPI_ICONS$2 = {
|
|
488
|
-
green: CurrencyDollar,
|
|
489
|
-
blue: ShoppingCart,
|
|
490
|
-
purple: TruckFast,
|
|
491
|
-
amber: Cash
|
|
492
|
-
};
|
|
493
|
-
const PIE_PALETTE = ["#6366F1", "#94A3B8", "#10B981", "#F59E0B"];
|
|
494
|
-
function AtlasKpiCard$2({
|
|
495
|
-
label,
|
|
496
|
-
value,
|
|
497
|
-
helper,
|
|
498
|
-
accent
|
|
499
|
-
}) {
|
|
500
|
-
const Icon = KPI_ICONS$2[accent];
|
|
501
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex h-full min-h-[112px] min-w-0 flex-col rounded-xl border border-ui-border-base/80 bg-ui-bg-subtle/25 p-4 shadow-sm", children: [
|
|
502
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-2", children: [
|
|
503
|
-
/* @__PURE__ */ jsx(Text, { className: "min-w-0 flex-1 text-left text-xs font-medium leading-snug text-ui-fg-base", children: label }),
|
|
504
|
-
/* @__PURE__ */ jsx(
|
|
505
|
-
"div",
|
|
506
|
-
{
|
|
507
|
-
className: `flex h-8 w-8 shrink-0 items-center justify-center rounded-lg ${KPI_ICON_BG$2[accent]}`,
|
|
508
|
-
"aria-hidden": true,
|
|
509
|
-
children: /* @__PURE__ */ jsx(Icon, { className: "h-4 w-4 text-ui-fg-base" })
|
|
510
|
-
}
|
|
511
|
-
)
|
|
512
|
-
] }),
|
|
513
|
-
/* @__PURE__ */ jsx("div", { className: "mt-3 text-xl font-semibold tabular-nums tracking-tight text-ui-fg-base sm:text-2xl", children: value }),
|
|
514
|
-
helper ? /* @__PURE__ */ jsx(Text, { className: "mt-2 text-[11px] leading-snug text-ui-fg-muted", children: helper }) : null
|
|
515
|
-
] });
|
|
516
|
-
}
|
|
517
|
-
const SUMMARY_PERIODS$1 = [
|
|
58
|
+
const SUMMARY_PERIODS = [
|
|
518
59
|
{ value: "all", label: "All time" },
|
|
519
60
|
{ value: "0", label: "Today's orders" },
|
|
520
61
|
{ value: "7", label: "Last 7 days" },
|
|
@@ -526,128 +67,21 @@ const OVER_TIME_PERIODS = [
|
|
|
526
67
|
{ value: "one_month", label: "One month" },
|
|
527
68
|
{ value: "one_year", label: "One year" }
|
|
528
69
|
];
|
|
529
|
-
const STATUS_BAR_COLORS = {
|
|
530
|
-
delivered: "#10B981",
|
|
531
|
-
cancelled: "#EF4444",
|
|
532
|
-
exchange: "#F59E0B",
|
|
533
|
-
return: "#8B5CF6",
|
|
534
|
-
today: "var(--medusa-color-ui-fg-interactive)",
|
|
535
|
-
todayMuted: "#BFDBFE",
|
|
536
|
-
orders: "#38BDF8",
|
|
537
|
-
revenue: "#D946EF"
|
|
538
|
-
};
|
|
539
|
-
const CHART_AXIS_TICK$2 = { fontSize: 10, fill: "#e5e7eb" };
|
|
540
|
-
const CHART_AXIS_TICK_SM$1 = { fontSize: 9, fill: "#e5e7eb" };
|
|
541
|
-
const CHART_AXIS_LINE$2 = "#94a3b8";
|
|
542
|
-
const SELECT_CLASS_NAME$2 = "h-9 min-w-[132px] cursor-pointer appearance-none rounded border border-ui-border-base bg-ui-bg-base py-1.5 pl-3 pr-8 text-xs text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive";
|
|
543
|
-
function EmptyAnalyticsPanel$1({
|
|
544
|
-
title,
|
|
545
|
-
description
|
|
546
|
-
}) {
|
|
547
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex min-h-[88px] flex-col gap-1.5 rounded-lg border border-dashed border-ui-border-base px-3 py-3", children: [
|
|
548
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-xs font-semibold", children: title }),
|
|
549
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[11px] leading-snug", children: description })
|
|
550
|
-
] });
|
|
551
|
-
}
|
|
552
70
|
function OrdersDashboard() {
|
|
553
|
-
var _a, _b;
|
|
554
71
|
const [data, setData] = useState(null);
|
|
555
72
|
const [loading, setLoading] = useState(true);
|
|
556
73
|
const [error, setError] = useState(null);
|
|
557
74
|
const [filter, setFilter] = useState("all");
|
|
558
75
|
const [dailyOrders, setDailyOrders] = useState([]);
|
|
559
|
-
const [previousPeriodDailyOrders, setPreviousPeriodDailyOrders] = useState([]);
|
|
560
76
|
const [overTimePeriod, setOverTimePeriod] = useState("one_week");
|
|
561
77
|
const [overTimeLoading, setOverTimeLoading] = useState(true);
|
|
562
78
|
const [overTimeError, setOverTimeError] = useState(null);
|
|
563
|
-
const [ordersInsights, setOrdersInsights] = useState(null);
|
|
564
|
-
const [insightsLoading, setInsightsLoading] = useState(true);
|
|
565
|
-
const [insightsError, setInsightsError] = useState(null);
|
|
566
|
-
const [todayContext, setTodayContext] = useState([]);
|
|
567
|
-
const [todayContextLoading, setTodayContextLoading] = useState(true);
|
|
568
|
-
const [todayContextError, setTodayContextError] = useState(null);
|
|
569
|
-
const [salesGranularity, setSalesGranularity] = useState("day");
|
|
570
|
-
const [salesBreakdownDaily, setSalesBreakdownDaily] = useState(
|
|
571
|
-
[]
|
|
572
|
-
);
|
|
573
|
-
const [salesBreakdownOtLoading, setSalesBreakdownOtLoading] = useState(true);
|
|
574
|
-
const [salesBreakdownOtError, setSalesBreakdownOtError] = useState(null);
|
|
575
|
-
const [salesBreakdownHourlyRolling, setSalesBreakdownHourlyRolling] = useState([]);
|
|
576
|
-
const [salesBreakdownHourlyLoading, setSalesBreakdownHourlyLoading] = useState(false);
|
|
577
|
-
const [salesBreakdownHourlyError, setSalesBreakdownHourlyError] = useState(null);
|
|
578
|
-
const salesBreakdownOtPeriod = useMemo(
|
|
579
|
-
() => getSalesBreakdownOtPeriod(salesGranularity),
|
|
580
|
-
[salesGranularity]
|
|
581
|
-
);
|
|
582
|
-
useEffect(() => {
|
|
583
|
-
if (salesBreakdownOtPeriod === null) {
|
|
584
|
-
setSalesBreakdownDaily([]);
|
|
585
|
-
setSalesBreakdownOtLoading(false);
|
|
586
|
-
setSalesBreakdownOtError(null);
|
|
587
|
-
return;
|
|
588
|
-
}
|
|
589
|
-
let cancelled = false;
|
|
590
|
-
setSalesBreakdownOtLoading(true);
|
|
591
|
-
setSalesBreakdownOtError(null);
|
|
592
|
-
fetch(
|
|
593
|
-
`/admin/analytics/orders-over-time?period=${salesBreakdownOtPeriod}`,
|
|
594
|
-
{ credentials: "include" }
|
|
595
|
-
).then((res) => {
|
|
596
|
-
if (!res.ok) throw new Error(res.statusText);
|
|
597
|
-
return res.json();
|
|
598
|
-
}).then((body) => {
|
|
599
|
-
if (!cancelled) {
|
|
600
|
-
setSalesBreakdownDaily(body.dailyOrders ?? []);
|
|
601
|
-
}
|
|
602
|
-
}).catch((e) => {
|
|
603
|
-
if (!cancelled) {
|
|
604
|
-
setSalesBreakdownOtError(e instanceof Error ? e.message : String(e));
|
|
605
|
-
}
|
|
606
|
-
}).finally(() => {
|
|
607
|
-
if (!cancelled) setSalesBreakdownOtLoading(false);
|
|
608
|
-
});
|
|
609
|
-
return () => {
|
|
610
|
-
cancelled = true;
|
|
611
|
-
};
|
|
612
|
-
}, [salesBreakdownOtPeriod]);
|
|
613
|
-
useEffect(() => {
|
|
614
|
-
if (salesGranularity !== "hour") {
|
|
615
|
-
setSalesBreakdownHourlyRolling([]);
|
|
616
|
-
setSalesBreakdownHourlyLoading(false);
|
|
617
|
-
setSalesBreakdownHourlyError(null);
|
|
618
|
-
return;
|
|
619
|
-
}
|
|
620
|
-
let cancelled = false;
|
|
621
|
-
setSalesBreakdownHourlyLoading(true);
|
|
622
|
-
setSalesBreakdownHourlyError(null);
|
|
623
|
-
fetch("/admin/analytics/orders-insights?last_hours=24", {
|
|
624
|
-
credentials: "include"
|
|
625
|
-
}).then((res) => {
|
|
626
|
-
if (!res.ok) throw new Error(res.statusText);
|
|
627
|
-
return res.json();
|
|
628
|
-
}).then((body) => {
|
|
629
|
-
if (!cancelled) {
|
|
630
|
-
setSalesBreakdownHourlyRolling(body.hourly_rolling ?? []);
|
|
631
|
-
}
|
|
632
|
-
}).catch((e) => {
|
|
633
|
-
if (!cancelled) {
|
|
634
|
-
setSalesBreakdownHourlyError(
|
|
635
|
-
e instanceof Error ? e.message : String(e)
|
|
636
|
-
);
|
|
637
|
-
}
|
|
638
|
-
}).finally(() => {
|
|
639
|
-
if (!cancelled) setSalesBreakdownHourlyLoading(false);
|
|
640
|
-
});
|
|
641
|
-
return () => {
|
|
642
|
-
cancelled = true;
|
|
643
|
-
};
|
|
644
|
-
}, [salesGranularity]);
|
|
645
79
|
useEffect(() => {
|
|
646
80
|
let cancelled = false;
|
|
647
81
|
setLoading(true);
|
|
648
82
|
setError(null);
|
|
649
83
|
const url = `/admin/analytics/orders-summary?days=${filter}`;
|
|
650
|
-
fetch(url
|
|
84
|
+
fetch(url).then((res) => {
|
|
651
85
|
if (!res.ok) throw new Error(res.statusText);
|
|
652
86
|
return res.json();
|
|
653
87
|
}).then((body) => {
|
|
@@ -666,14 +100,11 @@ function OrdersDashboard() {
|
|
|
666
100
|
setOverTimeLoading(true);
|
|
667
101
|
setOverTimeError(null);
|
|
668
102
|
const url = `/admin/analytics/orders-over-time?period=${overTimePeriod}`;
|
|
669
|
-
fetch(url
|
|
103
|
+
fetch(url).then((res) => {
|
|
670
104
|
if (!res.ok) throw new Error(res.statusText);
|
|
671
105
|
return res.json();
|
|
672
106
|
}).then((body) => {
|
|
673
|
-
if (!cancelled)
|
|
674
|
-
setDailyOrders(body.dailyOrders ?? []);
|
|
675
|
-
setPreviousPeriodDailyOrders(body.previousPeriodDailyOrders ?? []);
|
|
676
|
-
}
|
|
107
|
+
if (!cancelled) setDailyOrders(body.dailyOrders ?? []);
|
|
677
108
|
}).catch((e) => {
|
|
678
109
|
if (!cancelled) setOverTimeError(e instanceof Error ? e.message : String(e));
|
|
679
110
|
}).finally(() => {
|
|
@@ -683,287 +114,11 @@ function OrdersDashboard() {
|
|
|
683
114
|
cancelled = true;
|
|
684
115
|
};
|
|
685
116
|
}, [overTimePeriod]);
|
|
686
|
-
const insightsWindowDays = useMemo(() => {
|
|
687
|
-
if (overTimePeriod === "one_week") return 7;
|
|
688
|
-
if (overTimePeriod === "one_month") return 30;
|
|
689
|
-
return 365;
|
|
690
|
-
}, [overTimePeriod]);
|
|
691
|
-
useEffect(() => {
|
|
692
|
-
let cancelled = false;
|
|
693
|
-
setInsightsLoading(true);
|
|
694
|
-
setInsightsError(null);
|
|
695
|
-
fetch(`/admin/analytics/orders-insights?days=${insightsWindowDays}`, {
|
|
696
|
-
credentials: "include"
|
|
697
|
-
}).then((res) => {
|
|
698
|
-
if (!res.ok) throw new Error(res.statusText);
|
|
699
|
-
return res.json();
|
|
700
|
-
}).then((body) => {
|
|
701
|
-
if (!cancelled) setOrdersInsights(body);
|
|
702
|
-
}).catch((e) => {
|
|
703
|
-
if (!cancelled) setInsightsError(e instanceof Error ? e.message : String(e));
|
|
704
|
-
}).finally(() => {
|
|
705
|
-
if (!cancelled) setInsightsLoading(false);
|
|
706
|
-
});
|
|
707
|
-
return () => {
|
|
708
|
-
cancelled = true;
|
|
709
|
-
};
|
|
710
|
-
}, [insightsWindowDays]);
|
|
711
|
-
useEffect(() => {
|
|
712
|
-
let cancelled = false;
|
|
713
|
-
setTodayContextLoading(true);
|
|
714
|
-
setTodayContextError(null);
|
|
715
|
-
fetch("/admin/analytics/orders-over-time?period=one_week", {
|
|
716
|
-
credentials: "include"
|
|
717
|
-
}).then((res) => {
|
|
718
|
-
if (!res.ok) throw new Error(res.statusText);
|
|
719
|
-
return res.json();
|
|
720
|
-
}).then((body) => {
|
|
721
|
-
if (!cancelled) setTodayContext(body.dailyOrders ?? []);
|
|
722
|
-
}).catch((e) => {
|
|
723
|
-
if (!cancelled) {
|
|
724
|
-
setTodayContextError(e instanceof Error ? e.message : String(e));
|
|
725
|
-
}
|
|
726
|
-
}).finally(() => {
|
|
727
|
-
if (!cancelled) setTodayContextLoading(false);
|
|
728
|
-
});
|
|
729
|
-
return () => {
|
|
730
|
-
cancelled = true;
|
|
731
|
-
};
|
|
732
|
-
}, []);
|
|
733
|
-
const selectedSummaryPeriod = ((_a = SUMMARY_PERIODS$1.find((period) => period.value === filter)) == null ? void 0 : _a.label) ?? "All time";
|
|
734
|
-
const operationsBreakdown = (data == null ? void 0 : data.operationalCounts) ?? {
|
|
735
|
-
cancelled: (data == null ? void 0 : data.cancelledOrders) ?? 0,
|
|
736
|
-
delivered: (data == null ? void 0 : data.deliveredOrders) ?? 0,
|
|
737
|
-
exchange: (data == null ? void 0 : data.exchangeOrders) ?? 0,
|
|
738
|
-
return: (data == null ? void 0 : data.returnOrders) ?? 0
|
|
739
|
-
};
|
|
740
|
-
const outcomesTimeSeriesHasPoints = useMemo(
|
|
741
|
-
() => dailyOrders.some(
|
|
742
|
-
(d) => d.delivered_count > 0 || d.cancelled_count > 0 || d.exchange_count > 0 || d.return_count > 0
|
|
743
|
-
),
|
|
744
|
-
[dailyOrders]
|
|
745
|
-
);
|
|
746
|
-
const totalResolvedOrders = operationsBreakdown.delivered + operationsBreakdown.cancelled;
|
|
747
|
-
const deliveryRate = totalResolvedOrders > 0 ? operationsBreakdown.delivered / totalResolvedOrders * 100 : 0;
|
|
748
|
-
const primaryStats = data ? [
|
|
749
|
-
{
|
|
750
|
-
label: "Total revenue",
|
|
751
|
-
value: formatCurrency$1(data.totalRevenue),
|
|
752
|
-
helper: "Non-cancelled orders",
|
|
753
|
-
accent: "green"
|
|
754
|
-
},
|
|
755
|
-
{
|
|
756
|
-
label: "Total orders",
|
|
757
|
-
value: data.totalOrders.toLocaleString(),
|
|
758
|
-
helper: selectedSummaryPeriod,
|
|
759
|
-
accent: "blue"
|
|
760
|
-
},
|
|
761
|
-
{
|
|
762
|
-
label: "Delivery rate",
|
|
763
|
-
value: formatPercent(deliveryRate),
|
|
764
|
-
helper: "Delivered vs cancelled",
|
|
765
|
-
accent: "purple"
|
|
766
|
-
},
|
|
767
|
-
{
|
|
768
|
-
label: "Average order value",
|
|
769
|
-
value: formatCurrency$1(data.aov),
|
|
770
|
-
helper: "Per non-cancelled order",
|
|
771
|
-
accent: "amber"
|
|
772
|
-
}
|
|
773
|
-
] : [];
|
|
774
|
-
const secondaryStats = data ? [
|
|
775
|
-
{ label: "Orders today", value: data.ordersToday.toLocaleString() },
|
|
776
|
-
{ label: "Pending orders", value: data.pendingOrders.toLocaleString() },
|
|
777
|
-
{ label: "Delivered orders", value: data.deliveredOrders.toLocaleString() },
|
|
778
|
-
{ label: "Cancelled orders", value: data.cancelledOrders.toLocaleString() },
|
|
779
|
-
{ label: "Exchange orders", value: data.exchangeOrders.toLocaleString() },
|
|
780
|
-
{
|
|
781
|
-
label: "Avg. fulfillment time",
|
|
782
|
-
value: data.avgFulfillmentTimeHours != null ? `${data.avgFulfillmentTimeHours}h` : "—",
|
|
783
|
-
helper: "Measured in hours"
|
|
784
|
-
}
|
|
785
|
-
] : [];
|
|
786
|
-
const todayChartData = useMemo(
|
|
787
|
-
() => todayContext.map((point, index) => ({
|
|
788
|
-
...point,
|
|
789
|
-
isToday: index === todayContext.length - 1
|
|
790
|
-
})),
|
|
791
|
-
[todayContext]
|
|
792
|
-
);
|
|
793
|
-
const todayOrdersAverage = todayChartData.length > 0 ? todayChartData.reduce((sum, point) => sum + point.orders_count, 0) / todayChartData.length : 0;
|
|
794
|
-
const todayPoint = todayChartData[todayChartData.length - 1] ?? null;
|
|
795
|
-
const todayDelta = todayPoint && todayOrdersAverage > 0 ? todayPoint.orders_count - todayOrdersAverage : null;
|
|
796
|
-
const trendRevenueTotal = dailyOrders.reduce(
|
|
797
|
-
(sum, point) => sum + point.total_revenue,
|
|
798
|
-
0
|
|
799
|
-
);
|
|
800
|
-
const trendOrdersTotal = dailyOrders.reduce(
|
|
801
|
-
(sum, point) => sum + point.orders_count,
|
|
802
|
-
0
|
|
803
|
-
);
|
|
804
|
-
const trendAverageRevenue = dailyOrders.length > 0 ? trendRevenueTotal / dailyOrders.length : 0;
|
|
805
|
-
const trendAverageOrders = dailyOrders.length > 0 ? trendOrdersTotal / dailyOrders.length : 0;
|
|
806
|
-
const peakRevenuePoint = dailyOrders.length > 0 ? dailyOrders.reduce(
|
|
807
|
-
(peak, point) => point.total_revenue > peak.total_revenue ? point : peak
|
|
808
|
-
) : null;
|
|
809
|
-
const previousPeriodRevenueTotal = useMemo(
|
|
810
|
-
() => previousPeriodDailyOrders.reduce((s, d) => s + d.total_revenue, 0),
|
|
811
|
-
[previousPeriodDailyOrders]
|
|
812
|
-
);
|
|
813
|
-
const previousPeriodOrdersTotal = useMemo(
|
|
814
|
-
() => previousPeriodDailyOrders.reduce((s, d) => s + d.orders_count, 0),
|
|
815
|
-
[previousPeriodDailyOrders]
|
|
816
|
-
);
|
|
817
|
-
const revenueVsPreviousPercent = previousPeriodRevenueTotal > 0 ? (trendRevenueTotal - previousPeriodRevenueTotal) / previousPeriodRevenueTotal * 100 : null;
|
|
818
|
-
const ordersVsPreviousPercent = previousPeriodOrdersTotal > 0 ? (trendOrdersTotal - previousPeriodOrdersTotal) / previousPeriodOrdersTotal * 100 : null;
|
|
819
|
-
const trendRowsDetailed = useMemo(() => {
|
|
820
|
-
return dailyOrders.map((d, i) => {
|
|
821
|
-
const prev = previousPeriodDailyOrders[i];
|
|
822
|
-
return {
|
|
823
|
-
...d,
|
|
824
|
-
aov: bucketAov(d),
|
|
825
|
-
prev_revenue: (prev == null ? void 0 : prev.total_revenue) ?? 0,
|
|
826
|
-
prev_orders: (prev == null ? void 0 : prev.orders_count) ?? 0,
|
|
827
|
-
prev_aov: prev ? bucketAov(prev) : 0
|
|
828
|
-
};
|
|
829
|
-
});
|
|
830
|
-
}, [dailyOrders, previousPeriodDailyOrders]);
|
|
831
|
-
const salesBreakdownChartRows = useMemo(() => {
|
|
832
|
-
if (salesGranularity === "hour") {
|
|
833
|
-
return salesBreakdownHourlyRolling.map((b, i) => ({
|
|
834
|
-
key: `rolling-${i}`,
|
|
835
|
-
label: b.label,
|
|
836
|
-
orders_count: b.orders_count,
|
|
837
|
-
revenue: b.revenue
|
|
838
|
-
}));
|
|
839
|
-
}
|
|
840
|
-
if (salesGranularity === "week") {
|
|
841
|
-
const targetKeys = lastNWeekStartKeysUtc(7);
|
|
842
|
-
const agg = /* @__PURE__ */ new Map();
|
|
843
|
-
for (const d of salesBreakdownDaily) {
|
|
844
|
-
const wk = utcSundayWeekStartKeyFromDateStr(d.date);
|
|
845
|
-
const cur = agg.get(wk) ?? { orders: 0, revenue: 0 };
|
|
846
|
-
cur.orders += d.orders_count;
|
|
847
|
-
cur.revenue += d.total_revenue;
|
|
848
|
-
agg.set(wk, cur);
|
|
849
|
-
}
|
|
850
|
-
return targetKeys.map((key) => {
|
|
851
|
-
var _a2, _b2;
|
|
852
|
-
return {
|
|
853
|
-
key,
|
|
854
|
-
label: formatWeekStartDm(key),
|
|
855
|
-
orders_count: ((_a2 = agg.get(key)) == null ? void 0 : _a2.orders) ?? 0,
|
|
856
|
-
revenue: ((_b2 = agg.get(key)) == null ? void 0 : _b2.revenue) ?? 0
|
|
857
|
-
};
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
if (salesGranularity === "month") {
|
|
861
|
-
return salesBreakdownDaily.map((d) => ({
|
|
862
|
-
key: d.date,
|
|
863
|
-
label: d.label ?? formatMonthBucketLabel(monthKeyFromDateStr(d.date)),
|
|
864
|
-
orders_count: d.orders_count,
|
|
865
|
-
revenue: d.total_revenue
|
|
866
|
-
}));
|
|
867
|
-
}
|
|
868
|
-
return salesBreakdownDaily.map((d) => ({
|
|
869
|
-
key: d.date,
|
|
870
|
-
label: formatDayBreakdownDm(d.date),
|
|
871
|
-
orders_count: d.orders_count,
|
|
872
|
-
revenue: d.total_revenue
|
|
873
|
-
}));
|
|
874
|
-
}, [
|
|
875
|
-
salesGranularity,
|
|
876
|
-
salesBreakdownDaily,
|
|
877
|
-
salesBreakdownHourlyRolling
|
|
878
|
-
]);
|
|
879
|
-
const salesBreakdownDescription = useMemo(() => {
|
|
880
|
-
switch (salesGranularity) {
|
|
881
|
-
case "hour":
|
|
882
|
-
return "Last 24 hours from now (UTC): one bar per clock hour in the rolling window.";
|
|
883
|
-
case "day":
|
|
884
|
-
return "Last 7 calendar days (UTC), one bar per day — axis day/month.";
|
|
885
|
-
case "week":
|
|
886
|
-
return "Last 7 weeks (UTC, weeks start Sunday); axis shows each week’s start as day/month.";
|
|
887
|
-
case "month":
|
|
888
|
-
return "Last 12 calendar months through the current month (UTC) — Jan, Feb, Mar, …";
|
|
889
|
-
default:
|
|
890
|
-
return "";
|
|
891
|
-
}
|
|
892
|
-
}, [salesGranularity]);
|
|
893
|
-
const salesBreakdownXAxisInterval = useMemo(() => {
|
|
894
|
-
const n = salesBreakdownChartRows.length;
|
|
895
|
-
if (salesGranularity === "hour") return 3;
|
|
896
|
-
if (salesGranularity === "day" && n > 24)
|
|
897
|
-
return Math.max(0, Math.ceil(n / 10) - 1);
|
|
898
|
-
return 0;
|
|
899
|
-
}, [salesGranularity, salesBreakdownChartRows.length]);
|
|
900
|
-
const ordersVsDraftsPie = useMemo(() => {
|
|
901
|
-
var _a2;
|
|
902
|
-
if (!ordersInsights) return [];
|
|
903
|
-
const placed = ((_a2 = ordersInsights.funnel[0]) == null ? void 0 : _a2.count) ?? 0;
|
|
904
|
-
const draftsCount = ordersInsights.drafts.available === true ? ordersInsights.drafts.count : 0;
|
|
905
|
-
return [
|
|
906
|
-
{ name: "Orders placed (window)", value: placed, key: "placed" },
|
|
907
|
-
{
|
|
908
|
-
name: ordersInsights.drafts.available === true ? "Open draft orders (snapshot)" : "Draft orders (unavailable)",
|
|
909
|
-
value: draftsCount,
|
|
910
|
-
key: "drafts"
|
|
911
|
-
}
|
|
912
|
-
];
|
|
913
|
-
}, [ordersInsights]);
|
|
914
|
-
const funnelTimeSeriesRows = useMemo(() => {
|
|
915
|
-
return dailyOrders.map((d) => {
|
|
916
|
-
const placed = d.orders_count;
|
|
917
|
-
const notCancelled = Math.max(0, d.orders_count - d.cancelled_count);
|
|
918
|
-
const shipped = d.shipped_count ?? 0;
|
|
919
|
-
const delivered = d.delivered_count;
|
|
920
|
-
const pctNotCancelled = placed > 0 ? notCancelled / placed * 100 : 0;
|
|
921
|
-
const pctShippedOfNc = notCancelled > 0 ? shipped / notCancelled * 100 : 0;
|
|
922
|
-
const pctDeliveredOfShipped = shipped > 0 ? delivered / shipped * 100 : 0;
|
|
923
|
-
return {
|
|
924
|
-
date: d.date,
|
|
925
|
-
label: d.label ?? formatChartLabel$2(d.date),
|
|
926
|
-
placed,
|
|
927
|
-
not_cancelled: notCancelled,
|
|
928
|
-
shipped,
|
|
929
|
-
delivered,
|
|
930
|
-
pct_not_cancelled: Math.round(pctNotCancelled * 10) / 10,
|
|
931
|
-
pct_shipped_of_active: Math.round(pctShippedOfNc * 10) / 10,
|
|
932
|
-
pct_delivered_of_shipped: Math.round(pctDeliveredOfShipped * 10) / 10
|
|
933
|
-
};
|
|
934
|
-
});
|
|
935
|
-
}, [dailyOrders]);
|
|
936
|
-
const quickPulseMetrics = [
|
|
937
|
-
{
|
|
938
|
-
label: "Range revenue",
|
|
939
|
-
value: formatCompactCurrency$1(trendRevenueTotal),
|
|
940
|
-
helper: selectedSummaryPeriod,
|
|
941
|
-
accentClassName: "border-emerald-400/25 bg-emerald-500/5"
|
|
942
|
-
},
|
|
943
|
-
{
|
|
944
|
-
label: "Range orders",
|
|
945
|
-
value: formatShortNumber$1(trendOrdersTotal),
|
|
946
|
-
helper: "Current trend window",
|
|
947
|
-
accentClassName: "border-sky-400/25 bg-sky-500/5"
|
|
948
|
-
},
|
|
949
|
-
{
|
|
950
|
-
label: "Avg/day orders",
|
|
951
|
-
value: trendAverageOrders.toFixed(1),
|
|
952
|
-
helper: "Across selected chart range",
|
|
953
|
-
accentClassName: "border-violet-400/25 bg-violet-500/5"
|
|
954
|
-
},
|
|
955
|
-
{
|
|
956
|
-
label: "Peak revenue day",
|
|
957
|
-
value: peakRevenuePoint ? formatCompactCurrency$1(peakRevenuePoint.total_revenue) : "—",
|
|
958
|
-
helper: (peakRevenuePoint == null ? void 0 : peakRevenuePoint.label) ?? formatChartLabel$2(peakRevenuePoint == null ? void 0 : peakRevenuePoint.date),
|
|
959
|
-
accentClassName: "border-amber-400/25 bg-amber-500/5"
|
|
960
|
-
}
|
|
961
|
-
];
|
|
962
117
|
if (loading) {
|
|
963
118
|
return /* @__PURE__ */ jsx(
|
|
964
119
|
"div",
|
|
965
120
|
{
|
|
966
|
-
className: "flex
|
|
121
|
+
className: "flex items-center justify-center min-h-[320px]",
|
|
967
122
|
role: "status",
|
|
968
123
|
"aria-label": "Loading analytics",
|
|
969
124
|
children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted", children: "Loading…" })
|
|
@@ -973,1104 +128,216 @@ function OrdersDashboard() {
|
|
|
973
128
|
if (error || !data) {
|
|
974
129
|
return /* @__PURE__ */ jsx(Container, { className: "p-6", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger", children: error ?? "Failed to load analytics" }) });
|
|
975
130
|
}
|
|
976
|
-
const
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
{
|
|
989
|
-
|
|
990
|
-
description: "Nothing to show for this view and range."
|
|
991
|
-
}
|
|
992
|
-
);
|
|
993
|
-
}
|
|
994
|
-
return /* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsx("div", { className: "h-[min(200px,30vh)] min-h-[160px] w-full sm:h-[min(220px,32vh)]", children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
|
|
995
|
-
BarChart,
|
|
996
|
-
{
|
|
997
|
-
data: salesBreakdownChartRows,
|
|
998
|
-
margin: { top: 4, right: 8, left: 4, bottom: 4 },
|
|
999
|
-
children: [
|
|
1000
|
-
/* @__PURE__ */ jsx(
|
|
1001
|
-
CartesianGrid,
|
|
1002
|
-
{
|
|
1003
|
-
strokeDasharray: "3 3",
|
|
1004
|
-
vertical: false,
|
|
1005
|
-
stroke: "rgba(148,163,184,0.12)"
|
|
1006
|
-
}
|
|
1007
|
-
),
|
|
1008
|
-
/* @__PURE__ */ jsx(
|
|
1009
|
-
XAxis,
|
|
1010
|
-
{
|
|
1011
|
-
dataKey: "label",
|
|
1012
|
-
tick: CHART_AXIS_TICK_SM$1,
|
|
1013
|
-
tickLine: false,
|
|
1014
|
-
axisLine: false,
|
|
1015
|
-
interval: salesBreakdownXAxisInterval
|
|
1016
|
-
}
|
|
1017
|
-
),
|
|
1018
|
-
/* @__PURE__ */ jsx(
|
|
1019
|
-
YAxis,
|
|
1020
|
-
{
|
|
1021
|
-
width: 44,
|
|
1022
|
-
tick: CHART_AXIS_TICK_SM$1,
|
|
1023
|
-
tickLine: false,
|
|
1024
|
-
axisLine: false,
|
|
1025
|
-
tickFormatter: (v) => formatCompactCurrency$1(Number(v))
|
|
1026
|
-
}
|
|
1027
|
-
),
|
|
131
|
+
const pieData = ORDER_CHART_STATUSES.map(({ key, label, color }) => {
|
|
132
|
+
const value = key === "delivered" ? data.statusCounts.delivered ?? data.deliveredOrders ?? 0 : key === "cancelled" ? data.statusCounts.cancelled ?? data.cancelledOrders ?? 0 : data.statusCounts.pending ?? data.pendingOrders ?? 0;
|
|
133
|
+
return { name: label, value, color };
|
|
134
|
+
}).filter((d) => d.value > 0);
|
|
135
|
+
const returnsExchangesData = [
|
|
136
|
+
{ name: "Return orders", value: data.returnOrders, color: "#EF4444" },
|
|
137
|
+
{ name: "Exchange orders", value: data.exchangeOrders, color: "#F59E0B" }
|
|
138
|
+
].filter((d) => d.value > 0);
|
|
139
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-8", children: [
|
|
140
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-4", children: [
|
|
141
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: "Orders" }),
|
|
142
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
143
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
144
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "analytics-period", className: "text-ui-fg-muted text-sm", children: "Period" }),
|
|
1028
145
|
/* @__PURE__ */ jsx(
|
|
1029
|
-
|
|
146
|
+
"select",
|
|
1030
147
|
{
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
Bar,
|
|
1037
|
-
{
|
|
1038
|
-
dataKey: "revenue",
|
|
1039
|
-
name: "Revenue",
|
|
1040
|
-
fill: "#D946EF",
|
|
1041
|
-
radius: [6, 6, 0, 0]
|
|
148
|
+
id: "analytics-period",
|
|
149
|
+
value: filter,
|
|
150
|
+
onChange: (e) => setFilter(e.target.value),
|
|
151
|
+
className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive",
|
|
152
|
+
children: SUMMARY_PERIODS.map((p) => /* @__PURE__ */ jsx("option", { value: p.value, children: p.label }, p.value))
|
|
1042
153
|
}
|
|
1043
154
|
)
|
|
1044
|
-
]
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
155
|
+
] }),
|
|
156
|
+
filter !== "all" && /* @__PURE__ */ jsx(
|
|
157
|
+
"button",
|
|
158
|
+
{
|
|
159
|
+
type: "button",
|
|
160
|
+
onClick: () => setFilter("all"),
|
|
161
|
+
className: "text-xs text-ui-fg-muted hover:text-ui-fg-base transition-colors",
|
|
162
|
+
"aria-label": "Show all orders (clear filter)",
|
|
163
|
+
children: "Clear filter"
|
|
164
|
+
}
|
|
165
|
+
)
|
|
166
|
+
] })
|
|
167
|
+
] }),
|
|
168
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4", children: [
|
|
169
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
170
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Total orders" }),
|
|
171
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: data.totalOrders.toLocaleString() })
|
|
172
|
+
] }),
|
|
173
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
174
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Total revenue" }),
|
|
175
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: formatCurrency(data.totalRevenue) })
|
|
176
|
+
] }),
|
|
177
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
178
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Average order value" }),
|
|
179
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: formatCurrency(data.aov) })
|
|
180
|
+
] }),
|
|
181
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
182
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Orders today" }),
|
|
183
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: data.ordersToday.toLocaleString() })
|
|
184
|
+
] })
|
|
185
|
+
] }),
|
|
186
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 lg:grid-cols-2 gap-6", children: [
|
|
187
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
188
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm mb-2", children: "Pending orders" }),
|
|
189
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: data.pendingOrders.toLocaleString() })
|
|
190
|
+
] }),
|
|
191
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
192
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm mb-2", children: "Avg. fulfillment time (hours)" }),
|
|
193
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: data.avgFulfillmentTimeHours != null ? `${data.avgFulfillmentTimeHours}h` : "—" })
|
|
194
|
+
] })
|
|
195
|
+
] }),
|
|
196
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4", children: [
|
|
197
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
198
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Cancelled orders" }),
|
|
199
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: data.cancelledOrders.toLocaleString() })
|
|
200
|
+
] }),
|
|
201
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
202
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Delivered orders" }),
|
|
203
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: data.deliveredOrders.toLocaleString() })
|
|
204
|
+
] }),
|
|
205
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
206
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Exchange orders" }),
|
|
207
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: data.exchangeOrders.toLocaleString() })
|
|
208
|
+
] }),
|
|
209
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
210
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Return orders" }),
|
|
211
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: data.returnOrders.toLocaleString() })
|
|
212
|
+
] })
|
|
213
|
+
] }),
|
|
214
|
+
/* @__PURE__ */ jsx(Container, { className: "p-6", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col sm:flex-row flex-wrap gap-6 items-stretch", children: [
|
|
215
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0 flex flex-col", style: { minWidth: "280px" }, children: [
|
|
216
|
+
/* @__PURE__ */ jsx(Heading, { level: "h3", className: "mb-3", children: "Orders by status" }),
|
|
217
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 min-h-[280px] flex items-center justify-center", children: pieData.length > 0 ? /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: 280, children: /* @__PURE__ */ jsxs(PieChart, { margin: { top: 8, right: 8, bottom: 8, left: 8 }, children: [
|
|
218
|
+
/* @__PURE__ */ jsx(
|
|
219
|
+
Pie,
|
|
1080
220
|
{
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
221
|
+
data: pieData,
|
|
222
|
+
cx: "50%",
|
|
223
|
+
cy: "50%",
|
|
224
|
+
innerRadius: 52,
|
|
225
|
+
outerRadius: 78,
|
|
226
|
+
paddingAngle: 2,
|
|
227
|
+
dataKey: "value",
|
|
228
|
+
nameKey: "name",
|
|
229
|
+
isAnimationActive: true,
|
|
230
|
+
children: pieData.map((entry, index) => /* @__PURE__ */ jsx(Cell, { fill: entry.color }, `cell-${index}`))
|
|
1086
231
|
}
|
|
1087
|
-
)
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-3 p-3 pt-0 md:p-4 md:pt-0", children: [
|
|
1092
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
|
|
1093
|
-
/* @__PURE__ */ jsx("div", { className: "px-0.5", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.16em]", children: "Order overview" }) }),
|
|
1094
|
-
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 gap-3 lg:grid-cols-4", children: primaryStats.map((stat) => /* @__PURE__ */ jsx(
|
|
1095
|
-
AtlasKpiCard$2,
|
|
1096
|
-
{
|
|
1097
|
-
label: stat.label,
|
|
1098
|
-
value: stat.value,
|
|
1099
|
-
helper: stat.helper,
|
|
1100
|
-
accent: stat.accent
|
|
1101
|
-
},
|
|
1102
|
-
stat.label
|
|
1103
|
-
)) })
|
|
232
|
+
),
|
|
233
|
+
/* @__PURE__ */ jsx(Tooltip, { formatter: (value) => [value ?? 0, "Orders"] }),
|
|
234
|
+
/* @__PURE__ */ jsx(Legend, { verticalAlign: "bottom", height: 36 })
|
|
235
|
+
] }) }) : /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "No orders in this period" }) })
|
|
1104
236
|
] }),
|
|
1105
|
-
/* @__PURE__ */ jsxs("div", { className: "
|
|
1106
|
-
/* @__PURE__ */ jsx(
|
|
1107
|
-
|
|
1108
|
-
{
|
|
1109
|
-
variant: "atlas",
|
|
1110
|
-
actionsBare: true,
|
|
1111
|
-
title: "Revenue & orders",
|
|
1112
|
-
description: "Time series for the selected range. Window totals below match this chart.",
|
|
1113
|
-
actions: /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
1114
|
-
/* @__PURE__ */ jsx(
|
|
1115
|
-
Label,
|
|
1116
|
-
{
|
|
1117
|
-
htmlFor: "over-time-period",
|
|
1118
|
-
className: "shrink-0 text-ui-fg-muted text-xs font-medium",
|
|
1119
|
-
children: "Range"
|
|
1120
|
-
}
|
|
1121
|
-
),
|
|
1122
|
-
/* @__PURE__ */ jsx(
|
|
1123
|
-
"select",
|
|
1124
|
-
{
|
|
1125
|
-
id: "over-time-period",
|
|
1126
|
-
value: overTimePeriod,
|
|
1127
|
-
onChange: (e) => setOverTimePeriod(e.target.value),
|
|
1128
|
-
className: SELECT_CLASS_NAME$2,
|
|
1129
|
-
children: OVER_TIME_PERIODS.map((p) => /* @__PURE__ */ jsx("option", { value: p.value, children: p.label }, p.value))
|
|
1130
|
-
}
|
|
1131
|
-
)
|
|
1132
|
-
] }),
|
|
1133
|
-
children: /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
|
|
1134
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-1.5 sm:grid-cols-3", children: [
|
|
1135
|
-
/* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
1136
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "Window revenue" }),
|
|
1137
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-lg font-semibold tracking-tight", children: formatCompactCurrency$1(trendRevenueTotal) }),
|
|
1138
|
-
/* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-muted text-[10px]", children: [
|
|
1139
|
-
"Avg/day ",
|
|
1140
|
-
formatCompactCurrency$1(trendAverageRevenue)
|
|
1141
|
-
] })
|
|
1142
|
-
] }) }),
|
|
1143
|
-
/* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
1144
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "Window orders" }),
|
|
1145
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-lg font-semibold tracking-tight", children: trendOrdersTotal.toLocaleString() }),
|
|
1146
|
-
/* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-muted text-[10px]", children: [
|
|
1147
|
-
"Avg/day ",
|
|
1148
|
-
trendAverageOrders.toFixed(1)
|
|
1149
|
-
] })
|
|
1150
|
-
] }) }),
|
|
1151
|
-
/* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
1152
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "vs previous period" }),
|
|
1153
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-lg font-semibold tracking-tight", children: revenueVsPreviousPercent === null ? "—" : `${revenueVsPreviousPercent >= 0 ? "+" : ""}${revenueVsPreviousPercent.toFixed(1)}% rev` }),
|
|
1154
|
-
/* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-muted text-[10px] leading-snug", children: [
|
|
1155
|
-
"Orders",
|
|
1156
|
-
" ",
|
|
1157
|
-
ordersVsPreviousPercent === null ? "—" : `${ordersVsPreviousPercent >= 0 ? "+" : ""}${ordersVsPreviousPercent.toFixed(1)}%`
|
|
1158
|
-
] })
|
|
1159
|
-
] }) })
|
|
1160
|
-
] }),
|
|
1161
|
-
!overTimeLoading && !overTimeError && dailyOrders.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1162
|
-
/* @__PURE__ */ jsxs(AnalyticsChartSurface, { variant: "atlas", children: [
|
|
1163
|
-
/* @__PURE__ */ jsxs("div", { className: "mb-1 flex flex-col gap-0.5 sm:flex-row sm:items-start sm:justify-between", children: [
|
|
1164
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
1165
|
-
/* @__PURE__ */ jsx(Text, { className: "text-[10px] font-medium uppercase tracking-[0.14em] text-ui-fg-muted", children: "Revenue, orders & AOV" }),
|
|
1166
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[9px] leading-snug", children: "One timeline · solid = this range, dashed = previous period (same length)" })
|
|
1167
|
-
] }),
|
|
1168
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-x-3 gap-y-0.5 text-[9px] text-ui-fg-muted sm:justify-end", children: [
|
|
1169
|
-
/* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1", children: [
|
|
1170
|
-
/* @__PURE__ */ jsx("span", { className: "h-2 w-2 shrink-0 rounded-full bg-fuchsia-500" }),
|
|
1171
|
-
"Revenue"
|
|
1172
|
-
] }),
|
|
1173
|
-
/* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1", children: [
|
|
1174
|
-
/* @__PURE__ */ jsx("span", { className: "h-2 w-2 shrink-0 rounded-full bg-sky-400" }),
|
|
1175
|
-
"Orders"
|
|
1176
|
-
] }),
|
|
1177
|
-
/* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1", children: [
|
|
1178
|
-
/* @__PURE__ */ jsx("span", { className: "h-2 w-2 shrink-0 rounded-full bg-amber-500" }),
|
|
1179
|
-
"AOV"
|
|
1180
|
-
] }),
|
|
1181
|
-
/* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1", children: [
|
|
1182
|
-
/* @__PURE__ */ jsx(
|
|
1183
|
-
"span",
|
|
1184
|
-
{
|
|
1185
|
-
className: "h-0 w-4 shrink-0 border-t border-dashed border-slate-400",
|
|
1186
|
-
"aria-hidden": true
|
|
1187
|
-
}
|
|
1188
|
-
),
|
|
1189
|
-
"Previous"
|
|
1190
|
-
] })
|
|
1191
|
-
] })
|
|
1192
|
-
] }),
|
|
1193
|
-
/* @__PURE__ */ jsx("div", { className: "h-[min(220px,32vh)] min-h-[156px] w-full", children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
|
|
1194
|
-
ComposedChart,
|
|
1195
|
-
{
|
|
1196
|
-
data: trendRowsDetailed,
|
|
1197
|
-
margin: { top: 6, right: 8, left: 2, bottom: 4 },
|
|
1198
|
-
children: [
|
|
1199
|
-
/* @__PURE__ */ jsx(
|
|
1200
|
-
CartesianGrid,
|
|
1201
|
-
{
|
|
1202
|
-
strokeDasharray: "3 3",
|
|
1203
|
-
vertical: false,
|
|
1204
|
-
stroke: "rgba(148,163,184,0.12)"
|
|
1205
|
-
}
|
|
1206
|
-
),
|
|
1207
|
-
/* @__PURE__ */ jsx(
|
|
1208
|
-
XAxis,
|
|
1209
|
-
{
|
|
1210
|
-
dataKey: "date",
|
|
1211
|
-
tick: CHART_AXIS_TICK_SM$1,
|
|
1212
|
-
tickLine: false,
|
|
1213
|
-
axisLine: false,
|
|
1214
|
-
tickFormatter: (value, index) => {
|
|
1215
|
-
const row = trendRowsDetailed[index];
|
|
1216
|
-
return (row == null ? void 0 : row.label) ?? formatChartLabel$2(String(value));
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
),
|
|
1220
|
-
/* @__PURE__ */ jsx(
|
|
1221
|
-
YAxis,
|
|
1222
|
-
{
|
|
1223
|
-
yAxisId: "orders",
|
|
1224
|
-
width: 30,
|
|
1225
|
-
tick: CHART_AXIS_TICK_SM$1,
|
|
1226
|
-
tickLine: false,
|
|
1227
|
-
axisLine: false,
|
|
1228
|
-
allowDecimals: false,
|
|
1229
|
-
tickFormatter: (v) => Math.floor(Number(v) || 0).toLocaleString()
|
|
1230
|
-
}
|
|
1231
|
-
),
|
|
1232
|
-
/* @__PURE__ */ jsx(
|
|
1233
|
-
YAxis,
|
|
1234
|
-
{
|
|
1235
|
-
yAxisId: "revenue",
|
|
1236
|
-
orientation: "right",
|
|
1237
|
-
width: 42,
|
|
1238
|
-
tick: CHART_AXIS_TICK_SM$1,
|
|
1239
|
-
tickLine: false,
|
|
1240
|
-
axisLine: false,
|
|
1241
|
-
tickFormatter: (v) => formatCompactCurrency$1(Number(v))
|
|
1242
|
-
}
|
|
1243
|
-
),
|
|
1244
|
-
/* @__PURE__ */ jsx(
|
|
1245
|
-
YAxis,
|
|
1246
|
-
{
|
|
1247
|
-
yAxisId: "aov",
|
|
1248
|
-
orientation: "right",
|
|
1249
|
-
width: 40,
|
|
1250
|
-
tick: CHART_AXIS_TICK_SM$1,
|
|
1251
|
-
tickLine: false,
|
|
1252
|
-
axisLine: false,
|
|
1253
|
-
tickFormatter: (v) => formatCompactCurrency$1(Number(v))
|
|
1254
|
-
}
|
|
1255
|
-
),
|
|
1256
|
-
/* @__PURE__ */ jsx(
|
|
1257
|
-
Tooltip,
|
|
1258
|
-
{
|
|
1259
|
-
content: /* @__PURE__ */ jsx(CombinedMetricsTooltip, {}),
|
|
1260
|
-
cursor: {
|
|
1261
|
-
stroke: "rgba(248, 250, 252, 0.35)",
|
|
1262
|
-
strokeWidth: 1
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
),
|
|
1266
|
-
/* @__PURE__ */ jsx(
|
|
1267
|
-
Line,
|
|
1268
|
-
{
|
|
1269
|
-
yAxisId: "orders",
|
|
1270
|
-
type: "natural",
|
|
1271
|
-
dataKey: "orders_count",
|
|
1272
|
-
name: "Orders",
|
|
1273
|
-
stroke: "#38BDF8",
|
|
1274
|
-
strokeWidth: 2,
|
|
1275
|
-
dot: false
|
|
1276
|
-
}
|
|
1277
|
-
),
|
|
1278
|
-
/* @__PURE__ */ jsx(
|
|
1279
|
-
Line,
|
|
1280
|
-
{
|
|
1281
|
-
yAxisId: "orders",
|
|
1282
|
-
type: "natural",
|
|
1283
|
-
dataKey: "prev_orders",
|
|
1284
|
-
name: "Orders (prev)",
|
|
1285
|
-
stroke: "#64748b",
|
|
1286
|
-
strokeWidth: 1.5,
|
|
1287
|
-
strokeDasharray: "5 4",
|
|
1288
|
-
dot: false
|
|
1289
|
-
}
|
|
1290
|
-
),
|
|
1291
|
-
/* @__PURE__ */ jsx(
|
|
1292
|
-
Line,
|
|
1293
|
-
{
|
|
1294
|
-
yAxisId: "revenue",
|
|
1295
|
-
type: "natural",
|
|
1296
|
-
dataKey: "total_revenue",
|
|
1297
|
-
name: "Revenue",
|
|
1298
|
-
stroke: "#D946EF",
|
|
1299
|
-
strokeWidth: 2,
|
|
1300
|
-
dot: false
|
|
1301
|
-
}
|
|
1302
|
-
),
|
|
1303
|
-
/* @__PURE__ */ jsx(
|
|
1304
|
-
Line,
|
|
1305
|
-
{
|
|
1306
|
-
yAxisId: "revenue",
|
|
1307
|
-
type: "natural",
|
|
1308
|
-
dataKey: "prev_revenue",
|
|
1309
|
-
name: "Revenue (prev)",
|
|
1310
|
-
stroke: "#64748b",
|
|
1311
|
-
strokeWidth: 1.5,
|
|
1312
|
-
strokeDasharray: "5 4",
|
|
1313
|
-
dot: false
|
|
1314
|
-
}
|
|
1315
|
-
),
|
|
1316
|
-
/* @__PURE__ */ jsx(
|
|
1317
|
-
Line,
|
|
1318
|
-
{
|
|
1319
|
-
yAxisId: "aov",
|
|
1320
|
-
type: "natural",
|
|
1321
|
-
dataKey: "aov",
|
|
1322
|
-
name: "AOV",
|
|
1323
|
-
stroke: "#D97706",
|
|
1324
|
-
strokeWidth: 2,
|
|
1325
|
-
dot: false
|
|
1326
|
-
}
|
|
1327
|
-
),
|
|
1328
|
-
/* @__PURE__ */ jsx(
|
|
1329
|
-
Line,
|
|
1330
|
-
{
|
|
1331
|
-
yAxisId: "aov",
|
|
1332
|
-
type: "natural",
|
|
1333
|
-
dataKey: "prev_aov",
|
|
1334
|
-
name: "AOV (prev)",
|
|
1335
|
-
stroke: "#64748b",
|
|
1336
|
-
strokeWidth: 1.5,
|
|
1337
|
-
strokeDasharray: "5 4",
|
|
1338
|
-
dot: false
|
|
1339
|
-
}
|
|
1340
|
-
)
|
|
1341
|
-
]
|
|
1342
|
-
}
|
|
1343
|
-
) }) })
|
|
1344
|
-
] }),
|
|
1345
|
-
/* @__PURE__ */ jsxs(AnalyticsChartSurface, { variant: "atlas", className: "mt-1.5", children: [
|
|
1346
|
-
/* @__PURE__ */ jsx(Text, { className: "mb-0.5 text-[10px] font-medium uppercase tracking-[0.14em] text-ui-fg-muted", children: "Revenue breakdown (stacked — by order status)" }),
|
|
1347
|
-
/* @__PURE__ */ jsx("div", { className: "h-[min(168px,26vh)] min-h-[140px] w-full", children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
|
|
1348
|
-
ComposedChart,
|
|
1349
|
-
{
|
|
1350
|
-
data: dailyOrders,
|
|
1351
|
-
margin: { top: 4, right: 8, left: -4, bottom: 0 },
|
|
1352
|
-
children: [
|
|
1353
|
-
/* @__PURE__ */ jsx(
|
|
1354
|
-
CartesianGrid,
|
|
1355
|
-
{
|
|
1356
|
-
stroke: "rgba(148,163,184,0.14)",
|
|
1357
|
-
strokeDasharray: "3 3",
|
|
1358
|
-
vertical: false
|
|
1359
|
-
}
|
|
1360
|
-
),
|
|
1361
|
-
/* @__PURE__ */ jsx(
|
|
1362
|
-
XAxis,
|
|
1363
|
-
{
|
|
1364
|
-
dataKey: "date",
|
|
1365
|
-
tick: CHART_AXIS_TICK$2,
|
|
1366
|
-
tickLine: false,
|
|
1367
|
-
axisLine: false,
|
|
1368
|
-
tickFormatter: (value, index) => {
|
|
1369
|
-
const row = dailyOrders[index];
|
|
1370
|
-
return (row == null ? void 0 : row.label) ?? formatChartLabel$2(value);
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
),
|
|
1374
|
-
/* @__PURE__ */ jsx(
|
|
1375
|
-
YAxis,
|
|
1376
|
-
{
|
|
1377
|
-
tick: CHART_AXIS_TICK$2,
|
|
1378
|
-
tickFormatter: (v) => formatCompactCurrency$1(Number(v))
|
|
1379
|
-
}
|
|
1380
|
-
),
|
|
1381
|
-
/* @__PURE__ */ jsx(
|
|
1382
|
-
Tooltip,
|
|
1383
|
-
{
|
|
1384
|
-
content: ({ active, payload, label }) => active && (payload == null ? void 0 : payload.length) ? /* @__PURE__ */ jsx(AnalyticsTooltipCard, { variant: "compact", title: String(label), children: payload.map((p) => /* @__PURE__ */ jsxs("div", { children: [
|
|
1385
|
-
p.name,
|
|
1386
|
-
":",
|
|
1387
|
-
" ",
|
|
1388
|
-
/* @__PURE__ */ jsx("strong", { children: formatCurrency$1(Number(p.value) || 0) })
|
|
1389
|
-
] }, String(p.name))) }) : null
|
|
1390
|
-
}
|
|
1391
|
-
),
|
|
1392
|
-
/* @__PURE__ */ jsx(Legend, { wrapperStyle: { fontSize: 10 }, iconType: "circle" }),
|
|
1393
|
-
/* @__PURE__ */ jsx(
|
|
1394
|
-
Area,
|
|
1395
|
-
{
|
|
1396
|
-
type: "natural",
|
|
1397
|
-
dataKey: "revenue_delivered",
|
|
1398
|
-
name: "Delivered",
|
|
1399
|
-
stackId: "r",
|
|
1400
|
-
fill: "#10B981",
|
|
1401
|
-
stroke: "#059669",
|
|
1402
|
-
fillOpacity: 0.85
|
|
1403
|
-
}
|
|
1404
|
-
),
|
|
1405
|
-
/* @__PURE__ */ jsx(
|
|
1406
|
-
Area,
|
|
1407
|
-
{
|
|
1408
|
-
type: "natural",
|
|
1409
|
-
dataKey: "revenue_open",
|
|
1410
|
-
name: "Open / pending",
|
|
1411
|
-
stackId: "r",
|
|
1412
|
-
fill: "#3B82F6",
|
|
1413
|
-
stroke: "#2563eb",
|
|
1414
|
-
fillOpacity: 0.85
|
|
1415
|
-
}
|
|
1416
|
-
),
|
|
1417
|
-
/* @__PURE__ */ jsx(
|
|
1418
|
-
Area,
|
|
1419
|
-
{
|
|
1420
|
-
type: "natural",
|
|
1421
|
-
dataKey: "revenue_cancelled",
|
|
1422
|
-
name: "Cancelled",
|
|
1423
|
-
stackId: "r",
|
|
1424
|
-
fill: "#F87171",
|
|
1425
|
-
stroke: "#EF4444",
|
|
1426
|
-
fillOpacity: 0.75
|
|
1427
|
-
}
|
|
1428
|
-
)
|
|
1429
|
-
]
|
|
1430
|
-
}
|
|
1431
|
-
) }) })
|
|
1432
|
-
] })
|
|
1433
|
-
] }) : null
|
|
1434
|
-
] })
|
|
1435
|
-
}
|
|
1436
|
-
) }),
|
|
1437
|
-
/* @__PURE__ */ jsxs("div", { className: "col-span-12 flex flex-col gap-2 xl:col-span-6", children: [
|
|
237
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0 flex flex-col", style: { minWidth: "280px" }, children: [
|
|
238
|
+
/* @__PURE__ */ jsx(Heading, { level: "h3", className: "mb-3", children: "Returns & exchanges" }),
|
|
239
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 min-h-[280px] flex items-center justify-center", children: returnsExchangesData.length > 0 ? /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: 280, children: /* @__PURE__ */ jsxs(PieChart, { margin: { top: 8, right: 8, bottom: 8, left: 8 }, children: [
|
|
1438
240
|
/* @__PURE__ */ jsx(
|
|
1439
|
-
|
|
241
|
+
Pie,
|
|
1440
242
|
{
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted mt-0.5 text-[9px] leading-snug", children: metric.helper })
|
|
1452
|
-
]
|
|
1453
|
-
},
|
|
1454
|
-
metric.label
|
|
1455
|
-
)) })
|
|
243
|
+
data: returnsExchangesData,
|
|
244
|
+
cx: "50%",
|
|
245
|
+
cy: "50%",
|
|
246
|
+
innerRadius: 52,
|
|
247
|
+
outerRadius: 78,
|
|
248
|
+
paddingAngle: 2,
|
|
249
|
+
dataKey: "value",
|
|
250
|
+
nameKey: "name",
|
|
251
|
+
isAnimationActive: true,
|
|
252
|
+
children: returnsExchangesData.map((entry, index) => /* @__PURE__ */ jsx(Cell, { fill: entry.color }, `cell-re-${index}`))
|
|
1456
253
|
}
|
|
1457
254
|
),
|
|
255
|
+
/* @__PURE__ */ jsx(Tooltip, { formatter: (value) => [value ?? 0, "Count"] }),
|
|
256
|
+
/* @__PURE__ */ jsx(Legend, { verticalAlign: "bottom", height: 36 })
|
|
257
|
+
] }) }) : /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "No returns or exchanges in this period" }) })
|
|
258
|
+
] })
|
|
259
|
+
] }) }),
|
|
260
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-6", children: [
|
|
261
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-4 mb-4", children: [
|
|
262
|
+
/* @__PURE__ */ jsx(Heading, { level: "h3", children: "Orders over time" }),
|
|
263
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
264
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "over-time-period", className: "text-ui-fg-muted text-sm", children: "Range" }),
|
|
1458
265
|
/* @__PURE__ */ jsx(
|
|
1459
|
-
|
|
266
|
+
"select",
|
|
1460
267
|
{
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
/* @__PURE__ */ jsx(Text, { className: "mb-0.5 text-[10px] font-medium uppercase tracking-[0.14em] text-ui-fg-muted", children: "Stage counts (time series)" }),
|
|
1467
|
-
/* @__PURE__ */ jsx("div", { className: "h-[min(200px,30vh)] min-h-[168px] w-full", children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
|
|
1468
|
-
LineChart,
|
|
1469
|
-
{
|
|
1470
|
-
data: funnelTimeSeriesRows,
|
|
1471
|
-
margin: { top: 4, right: 8, left: 0, bottom: 4 },
|
|
1472
|
-
children: [
|
|
1473
|
-
/* @__PURE__ */ jsx(
|
|
1474
|
-
CartesianGrid,
|
|
1475
|
-
{
|
|
1476
|
-
strokeDasharray: "3 3",
|
|
1477
|
-
stroke: "rgba(148,163,184,0.2)"
|
|
1478
|
-
}
|
|
1479
|
-
),
|
|
1480
|
-
/* @__PURE__ */ jsx(
|
|
1481
|
-
XAxis,
|
|
1482
|
-
{
|
|
1483
|
-
dataKey: "date",
|
|
1484
|
-
tick: CHART_AXIS_TICK_SM$1,
|
|
1485
|
-
stroke: CHART_AXIS_LINE$2,
|
|
1486
|
-
tickLine: { stroke: CHART_AXIS_LINE$2 },
|
|
1487
|
-
tickFormatter: (value) => {
|
|
1488
|
-
const row = dailyOrders.find((r) => r.date === value);
|
|
1489
|
-
return (row == null ? void 0 : row.label) ?? formatChartLabel$2(String(value));
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
),
|
|
1493
|
-
/* @__PURE__ */ jsx(
|
|
1494
|
-
YAxis,
|
|
1495
|
-
{
|
|
1496
|
-
tick: CHART_AXIS_TICK_SM$1,
|
|
1497
|
-
stroke: CHART_AXIS_LINE$2,
|
|
1498
|
-
tickLine: { stroke: CHART_AXIS_LINE$2 },
|
|
1499
|
-
width: 28,
|
|
1500
|
-
allowDecimals: false,
|
|
1501
|
-
tickFormatter: (v) => Math.floor(Number(v) || 0).toLocaleString()
|
|
1502
|
-
}
|
|
1503
|
-
),
|
|
1504
|
-
/* @__PURE__ */ jsx(
|
|
1505
|
-
Tooltip,
|
|
1506
|
-
{
|
|
1507
|
-
content: ({ active, payload, label }) => {
|
|
1508
|
-
var _a2;
|
|
1509
|
-
return active && (payload == null ? void 0 : payload.length) ? /* @__PURE__ */ jsx(
|
|
1510
|
-
AnalyticsTooltipCard,
|
|
1511
|
-
{
|
|
1512
|
-
variant: "compact",
|
|
1513
|
-
title: typeof label === "string" ? ((_a2 = dailyOrders.find((r) => r.date === label)) == null ? void 0 : _a2.label) ?? formatChartLabel$2(label) : String(label),
|
|
1514
|
-
children: payload.map((p) => /* @__PURE__ */ jsxs("div", { children: [
|
|
1515
|
-
String(p.name),
|
|
1516
|
-
":",
|
|
1517
|
-
" ",
|
|
1518
|
-
/* @__PURE__ */ jsx("strong", { children: Math.floor(Number(p.value) || 0).toLocaleString() })
|
|
1519
|
-
] }, String(p.dataKey)))
|
|
1520
|
-
}
|
|
1521
|
-
) : null;
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
),
|
|
1525
|
-
/* @__PURE__ */ jsx(
|
|
1526
|
-
Legend,
|
|
1527
|
-
{
|
|
1528
|
-
wrapperStyle: { fontSize: 9, color: "#e5e7eb", paddingTop: 4 },
|
|
1529
|
-
iconType: "circle",
|
|
1530
|
-
iconSize: 6
|
|
1531
|
-
}
|
|
1532
|
-
),
|
|
1533
|
-
/* @__PURE__ */ jsx(
|
|
1534
|
-
Line,
|
|
1535
|
-
{
|
|
1536
|
-
type: "natural",
|
|
1537
|
-
dataKey: "placed",
|
|
1538
|
-
name: "Placed",
|
|
1539
|
-
stroke: "#6366F1",
|
|
1540
|
-
strokeWidth: 2,
|
|
1541
|
-
dot: false
|
|
1542
|
-
}
|
|
1543
|
-
),
|
|
1544
|
-
/* @__PURE__ */ jsx(
|
|
1545
|
-
Line,
|
|
1546
|
-
{
|
|
1547
|
-
type: "natural",
|
|
1548
|
-
dataKey: "not_cancelled",
|
|
1549
|
-
name: "Not cancelled",
|
|
1550
|
-
stroke: "#22d3ee",
|
|
1551
|
-
strokeWidth: 2,
|
|
1552
|
-
dot: false
|
|
1553
|
-
}
|
|
1554
|
-
),
|
|
1555
|
-
/* @__PURE__ */ jsx(
|
|
1556
|
-
Line,
|
|
1557
|
-
{
|
|
1558
|
-
type: "natural",
|
|
1559
|
-
dataKey: "shipped",
|
|
1560
|
-
name: "Shipped",
|
|
1561
|
-
stroke: "#F59E0B",
|
|
1562
|
-
strokeWidth: 2,
|
|
1563
|
-
dot: false
|
|
1564
|
-
}
|
|
1565
|
-
),
|
|
1566
|
-
/* @__PURE__ */ jsx(
|
|
1567
|
-
Line,
|
|
1568
|
-
{
|
|
1569
|
-
type: "natural",
|
|
1570
|
-
dataKey: "delivered",
|
|
1571
|
-
name: "Delivered",
|
|
1572
|
-
stroke: "#10B981",
|
|
1573
|
-
strokeWidth: 2,
|
|
1574
|
-
dot: false
|
|
1575
|
-
}
|
|
1576
|
-
)
|
|
1577
|
-
]
|
|
1578
|
-
}
|
|
1579
|
-
) }) })
|
|
1580
|
-
] }),
|
|
1581
|
-
/* @__PURE__ */ jsxs(AnalyticsChartSurface, { variant: "atlas", children: [
|
|
1582
|
-
/* @__PURE__ */ jsx(Text, { className: "mb-0.5 text-[10px] font-medium uppercase tracking-[0.14em] text-ui-fg-muted", children: "Stage conversion (% of prior stage, same buckets)" }),
|
|
1583
|
-
/* @__PURE__ */ jsx("div", { className: "h-[min(168px,26vh)] min-h-[140px] w-full", children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
|
|
1584
|
-
LineChart,
|
|
1585
|
-
{
|
|
1586
|
-
data: funnelTimeSeriesRows,
|
|
1587
|
-
margin: { top: 4, right: 8, left: 0, bottom: 4 },
|
|
1588
|
-
children: [
|
|
1589
|
-
/* @__PURE__ */ jsx(
|
|
1590
|
-
CartesianGrid,
|
|
1591
|
-
{
|
|
1592
|
-
strokeDasharray: "3 3",
|
|
1593
|
-
stroke: "rgba(148,163,184,0.2)"
|
|
1594
|
-
}
|
|
1595
|
-
),
|
|
1596
|
-
/* @__PURE__ */ jsx(
|
|
1597
|
-
XAxis,
|
|
1598
|
-
{
|
|
1599
|
-
dataKey: "date",
|
|
1600
|
-
tick: CHART_AXIS_TICK_SM$1,
|
|
1601
|
-
stroke: CHART_AXIS_LINE$2,
|
|
1602
|
-
tickLine: { stroke: CHART_AXIS_LINE$2 },
|
|
1603
|
-
tickFormatter: (value) => {
|
|
1604
|
-
const row = dailyOrders.find((r) => r.date === value);
|
|
1605
|
-
return (row == null ? void 0 : row.label) ?? formatChartLabel$2(String(value));
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
),
|
|
1609
|
-
/* @__PURE__ */ jsx(
|
|
1610
|
-
YAxis,
|
|
1611
|
-
{
|
|
1612
|
-
domain: [0, 100],
|
|
1613
|
-
tick: CHART_AXIS_TICK_SM$1,
|
|
1614
|
-
stroke: CHART_AXIS_LINE$2,
|
|
1615
|
-
tickLine: { stroke: CHART_AXIS_LINE$2 },
|
|
1616
|
-
width: 36,
|
|
1617
|
-
tickFormatter: (v) => `${Math.round(Number(v) || 0)}%`
|
|
1618
|
-
}
|
|
1619
|
-
),
|
|
1620
|
-
/* @__PURE__ */ jsx(
|
|
1621
|
-
Tooltip,
|
|
1622
|
-
{
|
|
1623
|
-
content: ({ active, payload, label }) => {
|
|
1624
|
-
var _a2;
|
|
1625
|
-
return active && (payload == null ? void 0 : payload.length) ? /* @__PURE__ */ jsx(
|
|
1626
|
-
AnalyticsTooltipCard,
|
|
1627
|
-
{
|
|
1628
|
-
variant: "compact",
|
|
1629
|
-
title: typeof label === "string" ? ((_a2 = dailyOrders.find((r) => r.date === label)) == null ? void 0 : _a2.label) ?? formatChartLabel$2(label) : String(label),
|
|
1630
|
-
children: payload.map((p) => /* @__PURE__ */ jsxs("div", { children: [
|
|
1631
|
-
String(p.name),
|
|
1632
|
-
":",
|
|
1633
|
-
" ",
|
|
1634
|
-
/* @__PURE__ */ jsx("strong", { children: formatPercent(Number(p.value) || 0) })
|
|
1635
|
-
] }, String(p.dataKey)))
|
|
1636
|
-
}
|
|
1637
|
-
) : null;
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
),
|
|
1641
|
-
/* @__PURE__ */ jsx(
|
|
1642
|
-
Legend,
|
|
1643
|
-
{
|
|
1644
|
-
wrapperStyle: { fontSize: 9, color: "#e5e7eb", paddingTop: 4 },
|
|
1645
|
-
iconType: "circle",
|
|
1646
|
-
iconSize: 6
|
|
1647
|
-
}
|
|
1648
|
-
),
|
|
1649
|
-
/* @__PURE__ */ jsx(
|
|
1650
|
-
Line,
|
|
1651
|
-
{
|
|
1652
|
-
type: "natural",
|
|
1653
|
-
dataKey: "pct_not_cancelled",
|
|
1654
|
-
name: "Not cancelled / placed",
|
|
1655
|
-
stroke: "#6366F1",
|
|
1656
|
-
strokeWidth: 2,
|
|
1657
|
-
dot: false
|
|
1658
|
-
}
|
|
1659
|
-
),
|
|
1660
|
-
/* @__PURE__ */ jsx(
|
|
1661
|
-
Line,
|
|
1662
|
-
{
|
|
1663
|
-
type: "natural",
|
|
1664
|
-
dataKey: "pct_shipped_of_active",
|
|
1665
|
-
name: "Shipped / not cancelled",
|
|
1666
|
-
stroke: "#F59E0B",
|
|
1667
|
-
strokeWidth: 2,
|
|
1668
|
-
dot: false
|
|
1669
|
-
}
|
|
1670
|
-
),
|
|
1671
|
-
/* @__PURE__ */ jsx(
|
|
1672
|
-
Line,
|
|
1673
|
-
{
|
|
1674
|
-
type: "natural",
|
|
1675
|
-
dataKey: "pct_delivered_of_shipped",
|
|
1676
|
-
name: "Delivered / shipped",
|
|
1677
|
-
stroke: "#10B981",
|
|
1678
|
-
strokeWidth: 2,
|
|
1679
|
-
dot: false
|
|
1680
|
-
}
|
|
1681
|
-
)
|
|
1682
|
-
]
|
|
1683
|
-
}
|
|
1684
|
-
) }) })
|
|
1685
|
-
] })
|
|
1686
|
-
] }) : /* @__PURE__ */ jsx(
|
|
1687
|
-
EmptyAnalyticsPanel$1,
|
|
1688
|
-
{
|
|
1689
|
-
title: "No funnel data",
|
|
1690
|
-
description: "No orders in this range to chart."
|
|
1691
|
-
}
|
|
1692
|
-
)
|
|
268
|
+
id: "over-time-period",
|
|
269
|
+
value: overTimePeriod,
|
|
270
|
+
onChange: (e) => setOverTimePeriod(e.target.value),
|
|
271
|
+
className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive",
|
|
272
|
+
children: OVER_TIME_PERIODS.map((p) => /* @__PURE__ */ jsx("option", { value: p.value, children: p.label }, p.value))
|
|
1693
273
|
}
|
|
1694
274
|
)
|
|
1695
275
|
] })
|
|
1696
276
|
] }),
|
|
1697
|
-
/* @__PURE__ */
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
variant: "atlas",
|
|
1715
|
-
className: "xl:col-span-7",
|
|
1716
|
-
title: "Order outcomes",
|
|
1717
|
-
description: "Delivered, cancelled, exchanges, and returns per bucket — same window as Revenue & orders.",
|
|
1718
|
-
children: /* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsx("div", { className: "h-[176px] sm:h-[196px]", children: overTimeLoading ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "Loading…" }) }) : overTimeError ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger text-xs", children: overTimeError }) }) : !outcomesTimeSeriesHasPoints ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "No outcome events in this range." }) }) : /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
|
|
1719
|
-
LineChart,
|
|
277
|
+
/* @__PURE__ */ jsx("div", { className: "h-72", children: overTimeLoading ? /* @__PURE__ */ jsx(
|
|
278
|
+
"div",
|
|
279
|
+
{
|
|
280
|
+
className: "flex items-center justify-center h-full",
|
|
281
|
+
role: "status",
|
|
282
|
+
"aria-label": "Loading orders over time",
|
|
283
|
+
children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted", children: "Loading chart…" })
|
|
284
|
+
}
|
|
285
|
+
) : overTimeError ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger", children: overTimeError }) }) : /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
|
|
286
|
+
LineChart,
|
|
287
|
+
{
|
|
288
|
+
data: dailyOrders,
|
|
289
|
+
margin: { top: 8, right: 8, left: 8, bottom: 8 },
|
|
290
|
+
children: [
|
|
291
|
+
/* @__PURE__ */ jsx(CartesianGrid, { strokeDasharray: "3 3", className: "stroke-ui-border-base" }),
|
|
292
|
+
/* @__PURE__ */ jsx(
|
|
293
|
+
XAxis,
|
|
1720
294
|
{
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
strokeDasharray: "3 3",
|
|
1729
|
-
vertical: false
|
|
1730
|
-
}
|
|
1731
|
-
),
|
|
1732
|
-
/* @__PURE__ */ jsx(
|
|
1733
|
-
XAxis,
|
|
1734
|
-
{
|
|
1735
|
-
dataKey: "date",
|
|
1736
|
-
tick: CHART_AXIS_TICK$2,
|
|
1737
|
-
tickLine: false,
|
|
1738
|
-
axisLine: false,
|
|
1739
|
-
tickFormatter: (value) => {
|
|
1740
|
-
const dateStr = typeof value === "string" ? value : String(value);
|
|
1741
|
-
const row = dailyOrders.find((d) => d.date === dateStr);
|
|
1742
|
-
return (row == null ? void 0 : row.label) ?? formatChartLabel$2(dateStr);
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
),
|
|
1746
|
-
/* @__PURE__ */ jsx(
|
|
1747
|
-
YAxis,
|
|
1748
|
-
{
|
|
1749
|
-
width: 28,
|
|
1750
|
-
tick: CHART_AXIS_TICK$2,
|
|
1751
|
-
tickLine: false,
|
|
1752
|
-
axisLine: false,
|
|
1753
|
-
allowDecimals: false,
|
|
1754
|
-
tickFormatter: (value) => Math.floor(Number(value) || 0).toLocaleString()
|
|
1755
|
-
}
|
|
1756
|
-
),
|
|
1757
|
-
/* @__PURE__ */ jsx(
|
|
1758
|
-
Tooltip,
|
|
1759
|
-
{
|
|
1760
|
-
content: /* @__PURE__ */ jsx(OutcomesTrendTooltip, {}),
|
|
1761
|
-
cursor: { stroke: "rgba(148,163,184,0.35)", strokeWidth: 1 }
|
|
1762
|
-
}
|
|
1763
|
-
),
|
|
1764
|
-
/* @__PURE__ */ jsx(
|
|
1765
|
-
Legend,
|
|
1766
|
-
{
|
|
1767
|
-
wrapperStyle: { fontSize: 9, paddingTop: 0 },
|
|
1768
|
-
iconType: "circle",
|
|
1769
|
-
iconSize: 6
|
|
1770
|
-
}
|
|
1771
|
-
),
|
|
1772
|
-
/* @__PURE__ */ jsx(
|
|
1773
|
-
Line,
|
|
1774
|
-
{
|
|
1775
|
-
type: "natural",
|
|
1776
|
-
dataKey: "delivered_count",
|
|
1777
|
-
name: "Delivered",
|
|
1778
|
-
stroke: STATUS_BAR_COLORS.delivered,
|
|
1779
|
-
strokeWidth: 2,
|
|
1780
|
-
dot: false
|
|
1781
|
-
}
|
|
1782
|
-
),
|
|
1783
|
-
/* @__PURE__ */ jsx(
|
|
1784
|
-
Line,
|
|
1785
|
-
{
|
|
1786
|
-
type: "natural",
|
|
1787
|
-
dataKey: "cancelled_count",
|
|
1788
|
-
name: "Cancelled",
|
|
1789
|
-
stroke: STATUS_BAR_COLORS.cancelled,
|
|
1790
|
-
strokeWidth: 2,
|
|
1791
|
-
dot: false
|
|
1792
|
-
}
|
|
1793
|
-
),
|
|
1794
|
-
/* @__PURE__ */ jsx(
|
|
1795
|
-
Line,
|
|
1796
|
-
{
|
|
1797
|
-
type: "natural",
|
|
1798
|
-
dataKey: "exchange_count",
|
|
1799
|
-
name: "Exchanges",
|
|
1800
|
-
stroke: STATUS_BAR_COLORS.exchange,
|
|
1801
|
-
strokeWidth: 2,
|
|
1802
|
-
dot: false
|
|
1803
|
-
}
|
|
1804
|
-
),
|
|
1805
|
-
/* @__PURE__ */ jsx(
|
|
1806
|
-
Line,
|
|
1807
|
-
{
|
|
1808
|
-
type: "natural",
|
|
1809
|
-
dataKey: "return_count",
|
|
1810
|
-
name: "Returns",
|
|
1811
|
-
stroke: STATUS_BAR_COLORS.return,
|
|
1812
|
-
strokeWidth: 2,
|
|
1813
|
-
dot: false
|
|
1814
|
-
}
|
|
1815
|
-
)
|
|
1816
|
-
]
|
|
1817
|
-
}
|
|
1818
|
-
) }) }) })
|
|
1819
|
-
}
|
|
1820
|
-
),
|
|
1821
|
-
/* @__PURE__ */ jsx(
|
|
1822
|
-
AnalyticsSection,
|
|
1823
|
-
{
|
|
1824
|
-
variant: "atlas",
|
|
1825
|
-
className: "xl:col-span-5",
|
|
1826
|
-
title: "Recent orders (7 days)",
|
|
1827
|
-
description: "Daily order count vs 7-day average — time series.",
|
|
1828
|
-
children: /* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
|
|
1829
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-1.5", children: [
|
|
1830
|
-
/* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle/50 px-2 py-2", children: [
|
|
1831
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "Today" }),
|
|
1832
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-base font-semibold tracking-tight", children: (todayPoint == null ? void 0 : todayPoint.orders_count.toLocaleString()) ?? "0" })
|
|
1833
|
-
] }),
|
|
1834
|
-
/* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle/50 px-2 py-2", children: [
|
|
1835
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "7-day avg" }),
|
|
1836
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-base font-semibold tracking-tight", children: todayOrdersAverage.toFixed(1) })
|
|
1837
|
-
] })
|
|
1838
|
-
] }),
|
|
1839
|
-
/* @__PURE__ */ jsx("div", { className: "h-[140px] sm:h-[156px]", children: todayContextLoading ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "Loading…" }) }) : todayContextError ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger text-xs", children: todayContextError }) }) : todayChartData.length === 0 ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "No recent activity." }) }) : /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
|
|
1840
|
-
ComposedChart,
|
|
1841
|
-
{
|
|
1842
|
-
data: todayChartData,
|
|
1843
|
-
margin: { top: 4, right: 4, left: -4, bottom: 0 },
|
|
1844
|
-
children: [
|
|
1845
|
-
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", { id: "todayOrdersFill", x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
1846
|
-
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: "#3b82f6", stopOpacity: 0.2 }),
|
|
1847
|
-
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: "#3b82f6", stopOpacity: 0 })
|
|
1848
|
-
] }) }),
|
|
1849
|
-
/* @__PURE__ */ jsx(
|
|
1850
|
-
CartesianGrid,
|
|
1851
|
-
{
|
|
1852
|
-
stroke: "rgba(148,163,184,0.14)",
|
|
1853
|
-
strokeDasharray: "3 3",
|
|
1854
|
-
vertical: false
|
|
1855
|
-
}
|
|
1856
|
-
),
|
|
1857
|
-
/* @__PURE__ */ jsx(
|
|
1858
|
-
XAxis,
|
|
1859
|
-
{
|
|
1860
|
-
dataKey: "date",
|
|
1861
|
-
tick: CHART_AXIS_TICK$2,
|
|
1862
|
-
tickLine: false,
|
|
1863
|
-
axisLine: false,
|
|
1864
|
-
tickFormatter: formatChartLabel$2
|
|
1865
|
-
}
|
|
1866
|
-
),
|
|
1867
|
-
/* @__PURE__ */ jsx(
|
|
1868
|
-
YAxis,
|
|
1869
|
-
{
|
|
1870
|
-
width: 28,
|
|
1871
|
-
tick: CHART_AXIS_TICK$2,
|
|
1872
|
-
tickLine: false,
|
|
1873
|
-
axisLine: false,
|
|
1874
|
-
allowDecimals: false,
|
|
1875
|
-
tickFormatter: (value) => Math.floor(Number(value) || 0).toLocaleString()
|
|
1876
|
-
}
|
|
1877
|
-
),
|
|
1878
|
-
/* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(OrdersTodayTooltip, {}), cursor: { stroke: "rgba(148,163,184,0.35)", strokeWidth: 1 } }),
|
|
1879
|
-
/* @__PURE__ */ jsx(
|
|
1880
|
-
ReferenceLine,
|
|
1881
|
-
{
|
|
1882
|
-
y: todayOrdersAverage,
|
|
1883
|
-
stroke: "rgba(148,163,184,0.65)",
|
|
1884
|
-
strokeDasharray: "4 4"
|
|
1885
|
-
}
|
|
1886
|
-
),
|
|
1887
|
-
/* @__PURE__ */ jsx(
|
|
1888
|
-
Area,
|
|
1889
|
-
{
|
|
1890
|
-
type: "natural",
|
|
1891
|
-
dataKey: "orders_count",
|
|
1892
|
-
stroke: "none",
|
|
1893
|
-
fill: "url(#todayOrdersFill)",
|
|
1894
|
-
isAnimationActive: false
|
|
1895
|
-
}
|
|
1896
|
-
),
|
|
1897
|
-
/* @__PURE__ */ jsx(
|
|
1898
|
-
Line,
|
|
1899
|
-
{
|
|
1900
|
-
type: "natural",
|
|
1901
|
-
dataKey: "orders_count",
|
|
1902
|
-
name: "Orders",
|
|
1903
|
-
stroke: "#3b82f6",
|
|
1904
|
-
strokeWidth: 2,
|
|
1905
|
-
dot: (props) => {
|
|
1906
|
-
const { cx, cy, payload } = props;
|
|
1907
|
-
if (payload && typeof payload === "object" && "isToday" in payload && payload.isToday) {
|
|
1908
|
-
return /* @__PURE__ */ jsx(
|
|
1909
|
-
"circle",
|
|
1910
|
-
{
|
|
1911
|
-
cx,
|
|
1912
|
-
cy,
|
|
1913
|
-
r: 4,
|
|
1914
|
-
fill: STATUS_BAR_COLORS.today,
|
|
1915
|
-
stroke: "var(--medusa-color-ui-bg-base)",
|
|
1916
|
-
strokeWidth: 1
|
|
1917
|
-
}
|
|
1918
|
-
);
|
|
1919
|
-
}
|
|
1920
|
-
return /* @__PURE__ */ jsx("circle", { cx, cy, r: 0, fill: "transparent" });
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
)
|
|
1924
|
-
]
|
|
1925
|
-
}
|
|
1926
|
-
) }) }),
|
|
1927
|
-
/* @__PURE__ */ jsxs(Container, { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle/40 px-2 py-1.5 shadow-sm", children: [
|
|
1928
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "Note" }),
|
|
1929
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-[11px] leading-snug", children: todayDelta === null ? "Compares the latest day to the 7-day mean." : todayDelta >= 0 ? `Latest day is ${todayDelta.toFixed(1)} above the 7-day average.` : `Latest day is ${Math.abs(todayDelta).toFixed(1)} below the 7-day average.` })
|
|
1930
|
-
] })
|
|
1931
|
-
] }) })
|
|
1932
|
-
}
|
|
1933
|
-
)
|
|
1934
|
-
] }),
|
|
1935
|
-
/* @__PURE__ */ jsxs("div", { className: "mt-3 grid grid-cols-1 items-start gap-3 xl:grid-cols-12", children: [
|
|
1936
|
-
/* @__PURE__ */ jsx(
|
|
1937
|
-
AnalyticsSection,
|
|
1938
|
-
{
|
|
1939
|
-
variant: "atlas",
|
|
1940
|
-
className: "xl:col-span-8",
|
|
1941
|
-
title: "Sales breakdown",
|
|
1942
|
-
description: salesBreakdownDescription,
|
|
1943
|
-
actionsBare: true,
|
|
1944
|
-
actions: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-stretch gap-1 sm:flex-row sm:items-center sm:gap-2", children: [
|
|
1945
|
-
/* @__PURE__ */ jsx(
|
|
1946
|
-
Label,
|
|
1947
|
-
{
|
|
1948
|
-
htmlFor: "sales-breakdown-granularity",
|
|
1949
|
-
className: "shrink-0 text-ui-fg-muted text-xs font-medium",
|
|
1950
|
-
children: "Breakdown"
|
|
1951
|
-
}
|
|
1952
|
-
),
|
|
1953
|
-
/* @__PURE__ */ jsx(
|
|
1954
|
-
"select",
|
|
1955
|
-
{
|
|
1956
|
-
id: "sales-breakdown-granularity",
|
|
1957
|
-
value: salesGranularity,
|
|
1958
|
-
onChange: (e) => {
|
|
1959
|
-
const v = e.target.value;
|
|
1960
|
-
if (v === "hour" || v === "day" || v === "week" || v === "month") {
|
|
1961
|
-
setSalesGranularity(v);
|
|
1962
|
-
}
|
|
1963
|
-
},
|
|
1964
|
-
className: SELECT_CLASS_NAME$2,
|
|
1965
|
-
"aria-label": "Sales breakdown time bucket",
|
|
1966
|
-
children: SALES_GRANULARITY_TABS.map((tab) => /* @__PURE__ */ jsx("option", { value: tab.value, children: tab.value === "hour" ? "Hour (last 24h)" : tab.value === "day" ? "Day (last 7 days)" : tab.value === "week" ? "Week (last 7 weeks)" : "Month (last 12 months)" }, tab.value))
|
|
295
|
+
dataKey: "date",
|
|
296
|
+
tick: { fontSize: 12 },
|
|
297
|
+
tickFormatter: (v, index) => {
|
|
298
|
+
const row = dailyOrders[index];
|
|
299
|
+
if (row == null ? void 0 : row.label) return row.label;
|
|
300
|
+
const d = new Date(v);
|
|
301
|
+
return `${d.getUTCMonth() + 1}/${d.getUTCDate()}`;
|
|
1967
302
|
}
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
),
|
|
1973
|
-
/* @__PURE__ */ jsx(
|
|
1974
|
-
AnalyticsSection,
|
|
1975
|
-
{
|
|
1976
|
-
variant: "atlas",
|
|
1977
|
-
className: "xl:col-span-4",
|
|
1978
|
-
title: "Placed orders vs drafts",
|
|
1979
|
-
description: "Window order count vs current open draft orders (admin). Not storefront cart abandonment.",
|
|
1980
|
-
children: insightsLoading ? /* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsx("div", { className: "flex min-h-[100px] items-center justify-center py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "Loading…" }) }) }) : insightsError ? /* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsx("div", { className: "flex min-h-[100px] items-center justify-center px-2 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger text-center text-xs", children: insightsError }) }) }) : ordersVsDraftsPie.some((s) => s.value > 0) ? /* @__PURE__ */ jsxs(AnalyticsChartSurface, { variant: "atlas", children: [
|
|
1981
|
-
/* @__PURE__ */ jsx("div", { className: "h-[min(176px,28vh)] min-h-[148px] w-full", children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(PieChart, { margin: { top: 2, bottom: 2, left: 2, right: 2 }, children: [
|
|
1982
|
-
/* @__PURE__ */ jsx(
|
|
1983
|
-
Pie,
|
|
1984
|
-
{
|
|
1985
|
-
data: ordersVsDraftsPie,
|
|
1986
|
-
dataKey: "value",
|
|
1987
|
-
nameKey: "name",
|
|
1988
|
-
cx: "50%",
|
|
1989
|
-
cy: "46%",
|
|
1990
|
-
innerRadius: 40,
|
|
1991
|
-
outerRadius: 58,
|
|
1992
|
-
paddingAngle: 2,
|
|
1993
|
-
children: ordersVsDraftsPie.map((slice, i) => /* @__PURE__ */ jsx(
|
|
1994
|
-
Cell,
|
|
1995
|
-
{
|
|
1996
|
-
fill: PIE_PALETTE[i % PIE_PALETTE.length]
|
|
1997
|
-
},
|
|
1998
|
-
slice.key
|
|
1999
|
-
))
|
|
2000
|
-
}
|
|
2001
|
-
),
|
|
2002
|
-
/* @__PURE__ */ jsx(
|
|
2003
|
-
Tooltip,
|
|
2004
|
-
{
|
|
2005
|
-
content: ({ active, payload }) => {
|
|
2006
|
-
var _a2, _b2;
|
|
2007
|
-
return active && (payload == null ? void 0 : payload.length) ? /* @__PURE__ */ jsx(AnalyticsTooltipCard, { variant: "compact", title: String(((_a2 = payload[0]) == null ? void 0 : _a2.name) ?? ""), children: /* @__PURE__ */ jsxs("div", { children: [
|
|
2008
|
-
"Count:",
|
|
2009
|
-
" ",
|
|
2010
|
-
/* @__PURE__ */ jsx("strong", { children: Math.floor(
|
|
2011
|
-
Number((_b2 = payload[0]) == null ? void 0 : _b2.value) || 0
|
|
2012
|
-
).toLocaleString() })
|
|
2013
|
-
] }) }) : null;
|
|
2014
|
-
}
|
|
2015
|
-
}
|
|
2016
|
-
),
|
|
2017
|
-
/* @__PURE__ */ jsx(
|
|
2018
|
-
Legend,
|
|
2019
|
-
{
|
|
2020
|
-
wrapperStyle: { fontSize: 9, paddingTop: 0 },
|
|
2021
|
-
verticalAlign: "bottom",
|
|
2022
|
-
height: 22,
|
|
2023
|
-
iconType: "circle"
|
|
2024
|
-
}
|
|
2025
|
-
)
|
|
2026
|
-
] }) }) }),
|
|
2027
|
-
(ordersInsights == null ? void 0 : ordersInsights.drafts.available) === false ? /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted mt-0.5 px-0.5 text-[10px] leading-snug", children: "Draft totals need draft_order remote query access." }) : null
|
|
2028
|
-
] }) : /* @__PURE__ */ jsx(
|
|
2029
|
-
EmptyAnalyticsPanel$1,
|
|
303
|
+
}
|
|
304
|
+
),
|
|
305
|
+
/* @__PURE__ */ jsx(
|
|
306
|
+
YAxis,
|
|
2030
307
|
{
|
|
2031
|
-
|
|
2032
|
-
|
|
308
|
+
tick: { fontSize: 12 },
|
|
309
|
+
allowDecimals: false,
|
|
310
|
+
domain: [0, "auto"],
|
|
311
|
+
ticks: (() => {
|
|
312
|
+
const max = Math.max(
|
|
313
|
+
1,
|
|
314
|
+
...dailyOrders.map((d) => d.orders_count ?? 0)
|
|
315
|
+
);
|
|
316
|
+
const step = max <= 10 ? 1 : Math.ceil(max / 6);
|
|
317
|
+
const arr = [];
|
|
318
|
+
for (let i = 0; i <= max; i += step) arr.push(i);
|
|
319
|
+
if (arr[arr.length - 1] !== max) arr.push(max);
|
|
320
|
+
return arr;
|
|
321
|
+
})(),
|
|
322
|
+
tickFormatter: (v) => String(Math.floor(Number(v) || 0))
|
|
323
|
+
}
|
|
324
|
+
),
|
|
325
|
+
/* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(OrdersOverTimeTooltip, {}) }),
|
|
326
|
+
/* @__PURE__ */ jsx(
|
|
327
|
+
Line,
|
|
328
|
+
{
|
|
329
|
+
type: "monotone",
|
|
330
|
+
dataKey: "orders_count",
|
|
331
|
+
name: "Orders",
|
|
332
|
+
stroke: "var(--medusa-color-ui-fg-interactive)",
|
|
333
|
+
strokeWidth: 2,
|
|
334
|
+
dot: { r: 3 }
|
|
2033
335
|
}
|
|
2034
336
|
)
|
|
2035
|
-
|
|
2036
|
-
)
|
|
2037
|
-
] })
|
|
2038
|
-
] })
|
|
2039
|
-
] }) });
|
|
2040
|
-
}
|
|
2041
|
-
const KPI_ICON_BG$1 = {
|
|
2042
|
-
green: "bg-emerald-500/20",
|
|
2043
|
-
blue: "bg-sky-500/20",
|
|
2044
|
-
purple: "bg-violet-500/20",
|
|
2045
|
-
amber: "bg-amber-500/20"
|
|
2046
|
-
};
|
|
2047
|
-
const KPI_ICONS$1 = {
|
|
2048
|
-
green: UsersSolid,
|
|
2049
|
-
blue: User,
|
|
2050
|
-
purple: UserGroup,
|
|
2051
|
-
amber: Trash
|
|
2052
|
-
};
|
|
2053
|
-
function AtlasKpiCard$1({
|
|
2054
|
-
label,
|
|
2055
|
-
value,
|
|
2056
|
-
helper,
|
|
2057
|
-
accent
|
|
2058
|
-
}) {
|
|
2059
|
-
const Icon = KPI_ICONS$1[accent];
|
|
2060
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex h-full min-h-[88px] min-w-0 flex-col rounded-xl border border-ui-border-base/80 bg-ui-bg-subtle/25 p-3 shadow-sm", children: [
|
|
2061
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-2", children: [
|
|
2062
|
-
/* @__PURE__ */ jsx(Text, { className: "min-w-0 flex-1 text-left text-xs font-medium leading-snug text-ui-fg-base", children: label }),
|
|
2063
|
-
/* @__PURE__ */ jsx(
|
|
2064
|
-
"div",
|
|
2065
|
-
{
|
|
2066
|
-
className: `flex h-7 w-7 shrink-0 items-center justify-center rounded-lg ${KPI_ICON_BG$1[accent]}`,
|
|
2067
|
-
"aria-hidden": true,
|
|
2068
|
-
children: /* @__PURE__ */ jsx(Icon, { className: "h-3.5 w-3.5 text-ui-fg-base" })
|
|
337
|
+
]
|
|
2069
338
|
}
|
|
2070
|
-
)
|
|
2071
|
-
] })
|
|
2072
|
-
/* @__PURE__ */ jsx("div", { className: "mt-2 text-lg font-semibold tabular-nums tracking-tight text-ui-fg-base sm:text-xl", children: value }),
|
|
2073
|
-
helper ? /* @__PURE__ */ jsx(Text, { className: "mt-2 text-[11px] leading-snug text-ui-fg-muted", children: helper }) : null
|
|
339
|
+
) }) })
|
|
340
|
+
] })
|
|
2074
341
|
] });
|
|
2075
342
|
}
|
|
2076
343
|
function CustomersOverTimeTooltip({
|
|
@@ -2084,27 +351,32 @@ function CustomersOverTimeTooltip({
|
|
|
2084
351
|
const displayLabel = (row == null ? void 0 : row.label) ?? (label ? new Date(label).toLocaleDateString() : label);
|
|
2085
352
|
const registered = Math.floor(((_b = payload.find((p) => p.name === "Registered")) == null ? void 0 : _b.value) ?? 0);
|
|
2086
353
|
const guest = Math.floor(((_c = payload.find((p) => p.name === "Guest")) == null ? void 0 : _c.value) ?? 0);
|
|
2087
|
-
return /* @__PURE__ */ jsxs(
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
})
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
354
|
+
return /* @__PURE__ */ jsxs(
|
|
355
|
+
"div",
|
|
356
|
+
{
|
|
357
|
+
style: {
|
|
358
|
+
backgroundColor: "rgb(254, 254, 254)",
|
|
359
|
+
color: "#111827",
|
|
360
|
+
border: "1px solid rgb(229, 231, 235)",
|
|
361
|
+
borderRadius: "8px",
|
|
362
|
+
padding: "12px 16px",
|
|
363
|
+
boxShadow: "0 4px 14px rgba(0, 0, 0, 0.08)",
|
|
364
|
+
fontSize: "14px",
|
|
365
|
+
lineHeight: 1.5
|
|
366
|
+
},
|
|
367
|
+
children: [
|
|
368
|
+
/* @__PURE__ */ jsx("div", { style: { fontWeight: 600, marginBottom: "6px", color: "#111827" }, children: displayLabel }),
|
|
369
|
+
/* @__PURE__ */ jsxs("div", { style: { color: "#374151" }, children: [
|
|
370
|
+
"Registered: ",
|
|
371
|
+
/* @__PURE__ */ jsx("strong", { style: { color: "#1f2937" }, children: registered })
|
|
372
|
+
] }),
|
|
373
|
+
/* @__PURE__ */ jsxs("div", { style: { color: "#374151" }, children: [
|
|
374
|
+
"Guest: ",
|
|
375
|
+
/* @__PURE__ */ jsx("strong", { style: { color: "#1f2937" }, children: guest })
|
|
376
|
+
] })
|
|
377
|
+
]
|
|
378
|
+
}
|
|
379
|
+
);
|
|
2108
380
|
}
|
|
2109
381
|
const COUNT_DAY_PRESETS = [
|
|
2110
382
|
{ value: "all", label: "All time" },
|
|
@@ -2113,24 +385,14 @@ const COUNT_DAY_PRESETS = [
|
|
|
2113
385
|
{ value: "30", label: "Last 30 days" },
|
|
2114
386
|
{ value: "90", label: "Last 90 days" }
|
|
2115
387
|
];
|
|
2116
|
-
const GRAPH_PERIODS
|
|
388
|
+
const GRAPH_PERIODS = [
|
|
2117
389
|
{ value: "one_week", label: "One week" },
|
|
2118
390
|
{ value: "one_month", label: "One month" },
|
|
2119
391
|
{ value: "one_year", label: "One year" }
|
|
2120
392
|
];
|
|
2121
393
|
const REGISTERED_COLOR = "var(--medusa-color-ui-fg-interactive)";
|
|
2122
394
|
const GUEST_COLOR = "#6B7280";
|
|
2123
|
-
const CHART_AXIS_TICK$1 = { fontSize: 10, fill: "#e5e7eb" };
|
|
2124
|
-
const CHART_AXIS_LINE$1 = "#94a3b8";
|
|
2125
|
-
const SELECT_CLASS_NAME$1 = "h-9 w-full min-w-[8rem] max-w-full cursor-pointer appearance-none rounded border border-ui-border-base bg-ui-bg-base py-1.5 pl-3 pr-8 text-xs text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive sm:w-auto sm:min-w-[132px] sm:max-w-[220px]";
|
|
2126
|
-
function formatChartLabel$1(value) {
|
|
2127
|
-
if (!value) return "";
|
|
2128
|
-
const parsed = new Date(value);
|
|
2129
|
-
if (Number.isNaN(parsed.getTime())) return value;
|
|
2130
|
-
return `${parsed.getUTCMonth() + 1}/${parsed.getUTCDate()}`;
|
|
2131
|
-
}
|
|
2132
395
|
function CustomersDashboard() {
|
|
2133
|
-
var _a, _b;
|
|
2134
396
|
const [data, setData] = useState(null);
|
|
2135
397
|
const [loading, setLoading] = useState(true);
|
|
2136
398
|
const [error, setError] = useState(null);
|
|
@@ -2139,15 +401,12 @@ function CustomersDashboard() {
|
|
|
2139
401
|
const [graphPeriod, setGraphPeriod] = useState("one_week");
|
|
2140
402
|
const [graphLoading, setGraphLoading] = useState(true);
|
|
2141
403
|
const [graphError, setGraphError] = useState(null);
|
|
2142
|
-
const [repeatStats, setRepeatStats] = useState(null);
|
|
2143
|
-
const [repeatLoading, setRepeatLoading] = useState(true);
|
|
2144
|
-
const [repeatError, setRepeatError] = useState(null);
|
|
2145
404
|
useEffect(() => {
|
|
2146
405
|
let cancelled = false;
|
|
2147
406
|
setLoading(true);
|
|
2148
407
|
setError(null);
|
|
2149
408
|
const url = `/admin/analytics/customers-summary?days=${countDays}`;
|
|
2150
|
-
fetch(url
|
|
409
|
+
fetch(url).then((res) => {
|
|
2151
410
|
if (!res.ok) throw new Error(res.statusText);
|
|
2152
411
|
return res.json();
|
|
2153
412
|
}).then((body) => {
|
|
@@ -2166,7 +425,7 @@ function CustomersDashboard() {
|
|
|
2166
425
|
setGraphLoading(true);
|
|
2167
426
|
setGraphError(null);
|
|
2168
427
|
const url = `/admin/analytics/customers-over-time?period=${graphPeriod}`;
|
|
2169
|
-
fetch(url
|
|
428
|
+
fetch(url).then((res) => {
|
|
2170
429
|
if (!res.ok) throw new Error(res.statusText);
|
|
2171
430
|
return res.json();
|
|
2172
431
|
}).then((body) => {
|
|
@@ -2180,79 +439,11 @@ function CustomersDashboard() {
|
|
|
2180
439
|
cancelled = true;
|
|
2181
440
|
};
|
|
2182
441
|
}, [graphPeriod]);
|
|
2183
|
-
useEffect(() => {
|
|
2184
|
-
let cancelled = false;
|
|
2185
|
-
setRepeatLoading(true);
|
|
2186
|
-
setRepeatError(null);
|
|
2187
|
-
fetch(`/admin/analytics/repeat-customers?days=${countDays}`, {
|
|
2188
|
-
credentials: "include"
|
|
2189
|
-
}).then((res) => {
|
|
2190
|
-
if (!res.ok) throw new Error(res.statusText);
|
|
2191
|
-
return res.json();
|
|
2192
|
-
}).then((body) => {
|
|
2193
|
-
if (!cancelled) setRepeatStats(body);
|
|
2194
|
-
}).catch((e) => {
|
|
2195
|
-
if (!cancelled) setRepeatError(e instanceof Error ? e.message : String(e));
|
|
2196
|
-
}).finally(() => {
|
|
2197
|
-
if (!cancelled) setRepeatLoading(false);
|
|
2198
|
-
});
|
|
2199
|
-
return () => {
|
|
2200
|
-
cancelled = true;
|
|
2201
|
-
};
|
|
2202
|
-
}, [countDays]);
|
|
2203
|
-
const selectedCountPeriodLabel = ((_a = COUNT_DAY_PRESETS.find((p) => p.value === countDays)) == null ? void 0 : _a.label) ?? "All time";
|
|
2204
|
-
const guestRegisteredPieData = useMemo(() => {
|
|
2205
|
-
const g = Math.max(0, Math.floor((data == null ? void 0 : data.guestCount) ?? 0));
|
|
2206
|
-
const r = Math.max(0, Math.floor((data == null ? void 0 : data.registeredCount) ?? 0));
|
|
2207
|
-
return [
|
|
2208
|
-
{ name: "Guest checkout", value: g, key: "guest" },
|
|
2209
|
-
{ name: "Registered", value: r, key: "registered" }
|
|
2210
|
-
].filter((s) => s.value > 0);
|
|
2211
|
-
}, [data]);
|
|
2212
|
-
const seriesWindowTotals = useMemo(() => {
|
|
2213
|
-
let registered = 0;
|
|
2214
|
-
let guest = 0;
|
|
2215
|
-
for (const row of series) {
|
|
2216
|
-
registered += Math.max(0, Math.floor(row.registered_count));
|
|
2217
|
-
guest += Math.max(0, Math.floor(row.guest_count));
|
|
2218
|
-
}
|
|
2219
|
-
return {
|
|
2220
|
-
registered,
|
|
2221
|
-
guest,
|
|
2222
|
-
points: series.length
|
|
2223
|
-
};
|
|
2224
|
-
}, [series]);
|
|
2225
|
-
const primaryStats = data ? [
|
|
2226
|
-
{
|
|
2227
|
-
label: "Guest customers",
|
|
2228
|
-
value: Math.floor(data.guestCount).toLocaleString(),
|
|
2229
|
-
helper: selectedCountPeriodLabel,
|
|
2230
|
-
accent: "blue"
|
|
2231
|
-
},
|
|
2232
|
-
{
|
|
2233
|
-
label: "Registered customers",
|
|
2234
|
-
value: Math.floor(data.registeredCount).toLocaleString(),
|
|
2235
|
-
helper: selectedCountPeriodLabel,
|
|
2236
|
-
accent: "purple"
|
|
2237
|
-
},
|
|
2238
|
-
{
|
|
2239
|
-
label: "Overall customers",
|
|
2240
|
-
value: Math.floor(data.totalCount).toLocaleString(),
|
|
2241
|
-
helper: "Guest + registered",
|
|
2242
|
-
accent: "green"
|
|
2243
|
-
},
|
|
2244
|
-
{
|
|
2245
|
-
label: "Deleted accounts",
|
|
2246
|
-
value: (data.deletedAccountsCount ?? 0).toLocaleString(),
|
|
2247
|
-
helper: "Removed profiles",
|
|
2248
|
-
accent: "amber"
|
|
2249
|
-
}
|
|
2250
|
-
] : [];
|
|
2251
442
|
if (loading) {
|
|
2252
443
|
return /* @__PURE__ */ jsx(
|
|
2253
444
|
"div",
|
|
2254
445
|
{
|
|
2255
|
-
className: "flex
|
|
446
|
+
className: "flex items-center justify-center min-h-[320px]",
|
|
2256
447
|
role: "status",
|
|
2257
448
|
"aria-label": "Loading analytics",
|
|
2258
449
|
children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted", children: "Loading…" })
|
|
@@ -2262,1753 +453,177 @@ function CustomersDashboard() {
|
|
|
2262
453
|
if (error || !data) {
|
|
2263
454
|
return /* @__PURE__ */ jsx(Container, { className: "p-6", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger", children: error ?? "Failed to load analytics" }) });
|
|
2264
455
|
}
|
|
2265
|
-
return /* @__PURE__ */
|
|
2266
|
-
/* @__PURE__ */
|
|
2267
|
-
|
|
2268
|
-
{
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
title: "Customers",
|
|
2273
|
-
description: "Acquisition mix, repeat behavior, and signups over time — aligned with Orders and Products analytics.",
|
|
2274
|
-
actions: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2275
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
2276
|
-
/* @__PURE__ */ jsx(
|
|
2277
|
-
Label,
|
|
2278
|
-
{
|
|
2279
|
-
htmlFor: "customers-count-period",
|
|
2280
|
-
className: "shrink-0 text-ui-fg-muted text-xs font-medium",
|
|
2281
|
-
children: "Period"
|
|
2282
|
-
}
|
|
2283
|
-
),
|
|
2284
|
-
/* @__PURE__ */ jsx(
|
|
2285
|
-
"select",
|
|
2286
|
-
{
|
|
2287
|
-
id: "customers-count-period",
|
|
2288
|
-
value: countDays,
|
|
2289
|
-
onChange: (e) => setCountDays(e.target.value),
|
|
2290
|
-
className: SELECT_CLASS_NAME$1,
|
|
2291
|
-
children: COUNT_DAY_PRESETS.map((p) => /* @__PURE__ */ jsx("option", { value: p.value, children: p.label }, p.value))
|
|
2292
|
-
}
|
|
2293
|
-
)
|
|
2294
|
-
] }),
|
|
2295
|
-
countDays !== "all" ? /* @__PURE__ */ jsx(
|
|
2296
|
-
"button",
|
|
456
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-8", children: [
|
|
457
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-4", children: [
|
|
458
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: "Customers" }),
|
|
459
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
460
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
461
|
+
/* @__PURE__ */ jsx(
|
|
462
|
+
Label,
|
|
2297
463
|
{
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
"aria-label": "Show all customers (clear filter)",
|
|
2302
|
-
children: "Clear period"
|
|
464
|
+
htmlFor: "customers-count-period",
|
|
465
|
+
className: "text-ui-fg-muted text-sm",
|
|
466
|
+
children: "Period (counts)"
|
|
2303
467
|
}
|
|
2304
|
-
)
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
},
|
|
2319
|
-
stat.label
|
|
2320
|
-
)) })
|
|
2321
|
-
] }),
|
|
2322
|
-
/* @__PURE__ */ jsxs("div", { className: "mt-2 grid grid-cols-12 gap-2 lg:items-stretch", children: [
|
|
2323
|
-
/* @__PURE__ */ jsx("div", { className: "col-span-12 flex min-h-0 min-w-0 lg:col-span-5", children: /* @__PURE__ */ jsx(
|
|
2324
|
-
AnalyticsSection,
|
|
2325
|
-
{
|
|
2326
|
-
variant: "atlas",
|
|
2327
|
-
className: "flex min-h-0 w-full flex-col",
|
|
2328
|
-
title: "Guest vs registered",
|
|
2329
|
-
description: "Mix for the selected period (same filter as overview).",
|
|
2330
|
-
children: /* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", className: "min-h-0 flex-1", children: /* @__PURE__ */ jsx("div", { className: "h-[min(168px,22vh)] min-h-[140px] w-full sm:h-[min(176px,24vh)]", children: guestRegisteredPieData.length === 0 ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center px-2", children: /* @__PURE__ */ jsx(Text, { className: "text-center text-ui-fg-muted text-[11px] leading-snug", children: "No guest or registered customers in this range." }) }) : /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(PieChart, { margin: { top: 2, right: 2, left: 2, bottom: 2 }, children: [
|
|
2331
|
-
/* @__PURE__ */ jsx(
|
|
2332
|
-
Pie,
|
|
2333
|
-
{
|
|
2334
|
-
data: guestRegisteredPieData,
|
|
2335
|
-
dataKey: "value",
|
|
2336
|
-
nameKey: "name",
|
|
2337
|
-
cx: "50%",
|
|
2338
|
-
cy: "48%",
|
|
2339
|
-
innerRadius: 34,
|
|
2340
|
-
outerRadius: 54,
|
|
2341
|
-
paddingAngle: 2,
|
|
2342
|
-
children: guestRegisteredPieData.map((entry) => /* @__PURE__ */ jsx(
|
|
2343
|
-
Cell,
|
|
2344
|
-
{
|
|
2345
|
-
fill: entry.key === "guest" ? GUEST_COLOR : REGISTERED_COLOR
|
|
2346
|
-
},
|
|
2347
|
-
entry.key
|
|
2348
|
-
))
|
|
2349
|
-
}
|
|
2350
|
-
),
|
|
2351
|
-
/* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(MixPieTooltip, {}) }),
|
|
2352
|
-
/* @__PURE__ */ jsx(
|
|
2353
|
-
Legend,
|
|
2354
|
-
{
|
|
2355
|
-
wrapperStyle: { fontSize: 9, paddingTop: 0 },
|
|
2356
|
-
verticalAlign: "bottom",
|
|
2357
|
-
height: 22,
|
|
2358
|
-
iconType: "circle"
|
|
2359
|
-
}
|
|
2360
|
-
)
|
|
2361
|
-
] }) }) }) })
|
|
2362
|
-
}
|
|
2363
|
-
) }),
|
|
2364
|
-
/* @__PURE__ */ jsx("div", { className: "col-span-12 flex min-h-0 min-w-0 lg:col-span-7", children: /* @__PURE__ */ jsx(
|
|
2365
|
-
AnalyticsSection,
|
|
468
|
+
),
|
|
469
|
+
/* @__PURE__ */ jsx(
|
|
470
|
+
"select",
|
|
471
|
+
{
|
|
472
|
+
id: "customers-count-period",
|
|
473
|
+
value: countDays,
|
|
474
|
+
onChange: (e) => setCountDays(e.target.value),
|
|
475
|
+
className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive",
|
|
476
|
+
children: COUNT_DAY_PRESETS.map((p) => /* @__PURE__ */ jsx("option", { value: p.value, children: p.label }, p.value))
|
|
477
|
+
}
|
|
478
|
+
)
|
|
479
|
+
] }),
|
|
480
|
+
countDays !== "all" && /* @__PURE__ */ jsx(
|
|
481
|
+
"button",
|
|
2366
482
|
{
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
children:
|
|
2372
|
-
/* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
2373
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "Repeat rate" }),
|
|
2374
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-lg font-semibold tracking-tight", children: `${repeatStats.repeat_rate_percent.toFixed(1)}%` }),
|
|
2375
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] leading-snug", children: repeatStats.window_days >= 365 ? "Approx. 12-month window" : `Last ${repeatStats.window_days} days` })
|
|
2376
|
-
] }) }),
|
|
2377
|
-
/* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
2378
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "With orders" }),
|
|
2379
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-lg font-semibold tracking-tight", children: repeatStats.customers_with_orders.toLocaleString() }),
|
|
2380
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] leading-snug", children: "Customers in window" })
|
|
2381
|
-
] }) }),
|
|
2382
|
-
/* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
2383
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "Repeat (2+ orders)" }),
|
|
2384
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-lg font-semibold tracking-tight", children: repeatStats.repeat_customers.toLocaleString() }),
|
|
2385
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] leading-snug", children: "Multi-order customers" })
|
|
2386
|
-
] }) })
|
|
2387
|
-
] }) : /* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", className: "flex flex-1 items-center justify-center py-6", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "No data." }) }) })
|
|
483
|
+
type: "button",
|
|
484
|
+
onClick: () => setCountDays("all"),
|
|
485
|
+
className: "text-xs text-ui-fg-muted hover:text-ui-fg-base transition-colors",
|
|
486
|
+
"aria-label": "Show all customers (clear filter)",
|
|
487
|
+
children: "Clear filter"
|
|
2388
488
|
}
|
|
2389
|
-
)
|
|
2390
|
-
] })
|
|
2391
|
-
/* @__PURE__ */ jsx(
|
|
2392
|
-
AnalyticsSection,
|
|
2393
|
-
{
|
|
2394
|
-
variant: "atlas",
|
|
2395
|
-
actionsBare: true,
|
|
2396
|
-
title: "Customers over time",
|
|
2397
|
-
description: "New registered vs guest activity for the chart range below.",
|
|
2398
|
-
actions: /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
2399
|
-
/* @__PURE__ */ jsx(
|
|
2400
|
-
Label,
|
|
2401
|
-
{
|
|
2402
|
-
htmlFor: "customers-graph-period",
|
|
2403
|
-
className: "shrink-0 text-ui-fg-muted text-xs font-medium",
|
|
2404
|
-
children: "Range"
|
|
2405
|
-
}
|
|
2406
|
-
),
|
|
2407
|
-
/* @__PURE__ */ jsx(
|
|
2408
|
-
"select",
|
|
2409
|
-
{
|
|
2410
|
-
id: "customers-graph-period",
|
|
2411
|
-
value: graphPeriod,
|
|
2412
|
-
onChange: (e) => setGraphPeriod(e.target.value),
|
|
2413
|
-
className: SELECT_CLASS_NAME$1,
|
|
2414
|
-
children: GRAPH_PERIODS$1.map((p) => /* @__PURE__ */ jsx("option", { value: p.value, children: p.label }, p.value))
|
|
2415
|
-
}
|
|
2416
|
-
)
|
|
2417
|
-
] }),
|
|
2418
|
-
children: /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
|
|
2419
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-1.5 sm:grid-cols-3", children: [
|
|
2420
|
-
/* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
2421
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "Window registered (sum)" }),
|
|
2422
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-lg font-semibold tracking-tight", children: seriesWindowTotals.registered.toLocaleString() }),
|
|
2423
|
-
/* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-muted text-[10px]", children: [
|
|
2424
|
-
"Across ",
|
|
2425
|
-
seriesWindowTotals.points,
|
|
2426
|
-
" buckets"
|
|
2427
|
-
] })
|
|
2428
|
-
] }) }),
|
|
2429
|
-
/* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
2430
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "Window guest (sum)" }),
|
|
2431
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-lg font-semibold tracking-tight", children: seriesWindowTotals.guest.toLocaleString() }),
|
|
2432
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px]", children: "Same range as chart" })
|
|
2433
|
-
] }) }),
|
|
2434
|
-
/* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
2435
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "Chart period" }),
|
|
2436
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-lg font-semibold tracking-tight", children: ((_b = GRAPH_PERIODS$1.find((p) => p.value === graphPeriod)) == null ? void 0 : _b.label) ?? graphPeriod }),
|
|
2437
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] leading-snug", children: "Independent of summary period filter" })
|
|
2438
|
-
] }) })
|
|
2439
|
-
] }),
|
|
2440
|
-
/* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsx("div", { className: "h-[212px] w-full sm:h-[228px]", children: graphLoading ? /* @__PURE__ */ jsx(
|
|
2441
|
-
"div",
|
|
2442
|
-
{
|
|
2443
|
-
className: "flex h-full items-center justify-center",
|
|
2444
|
-
role: "status",
|
|
2445
|
-
"aria-label": "Loading customers over time",
|
|
2446
|
-
children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "Loading chart…" })
|
|
2447
|
-
}
|
|
2448
|
-
) : graphError ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center px-2", children: /* @__PURE__ */ jsx(Text, { className: "text-center text-ui-fg-danger text-xs", children: graphError }) }) : /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
|
|
2449
|
-
LineChart,
|
|
2450
|
-
{
|
|
2451
|
-
data: series,
|
|
2452
|
-
margin: { top: 6, right: 8, left: 0, bottom: 4 },
|
|
2453
|
-
children: [
|
|
2454
|
-
/* @__PURE__ */ jsx(
|
|
2455
|
-
CartesianGrid,
|
|
2456
|
-
{
|
|
2457
|
-
strokeDasharray: "3 3",
|
|
2458
|
-
vertical: false,
|
|
2459
|
-
stroke: "rgba(148,163,184,0.12)"
|
|
2460
|
-
}
|
|
2461
|
-
),
|
|
2462
|
-
/* @__PURE__ */ jsx(
|
|
2463
|
-
XAxis,
|
|
2464
|
-
{
|
|
2465
|
-
dataKey: "date",
|
|
2466
|
-
tick: CHART_AXIS_TICK$1,
|
|
2467
|
-
stroke: CHART_AXIS_LINE$1,
|
|
2468
|
-
tickLine: false,
|
|
2469
|
-
axisLine: { stroke: CHART_AXIS_LINE$1 },
|
|
2470
|
-
tickFormatter: (_v, index) => {
|
|
2471
|
-
var _a2;
|
|
2472
|
-
const row = series[index];
|
|
2473
|
-
if (row == null ? void 0 : row.label) return row.label;
|
|
2474
|
-
const d = (_a2 = series[index]) == null ? void 0 : _a2.date;
|
|
2475
|
-
return formatChartLabel$1(d);
|
|
2476
|
-
}
|
|
2477
|
-
}
|
|
2478
|
-
),
|
|
2479
|
-
/* @__PURE__ */ jsx(
|
|
2480
|
-
YAxis,
|
|
2481
|
-
{
|
|
2482
|
-
width: 36,
|
|
2483
|
-
tick: CHART_AXIS_TICK$1,
|
|
2484
|
-
stroke: CHART_AXIS_LINE$1,
|
|
2485
|
-
tickLine: false,
|
|
2486
|
-
axisLine: { stroke: CHART_AXIS_LINE$1 },
|
|
2487
|
-
tickFormatter: (v) => String(Math.floor(Number(v))),
|
|
2488
|
-
allowDecimals: false
|
|
2489
|
-
}
|
|
2490
|
-
),
|
|
2491
|
-
/* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(CustomersOverTimeTooltip, {}) }),
|
|
2492
|
-
/* @__PURE__ */ jsx(
|
|
2493
|
-
Legend,
|
|
2494
|
-
{
|
|
2495
|
-
wrapperStyle: { fontSize: 10, paddingTop: 4 },
|
|
2496
|
-
iconType: "circle"
|
|
2497
|
-
}
|
|
2498
|
-
),
|
|
2499
|
-
/* @__PURE__ */ jsx(
|
|
2500
|
-
Line,
|
|
2501
|
-
{
|
|
2502
|
-
type: "monotone",
|
|
2503
|
-
dataKey: "registered_count",
|
|
2504
|
-
name: "Registered",
|
|
2505
|
-
stroke: REGISTERED_COLOR,
|
|
2506
|
-
strokeWidth: 2,
|
|
2507
|
-
dot: { r: 2 }
|
|
2508
|
-
}
|
|
2509
|
-
),
|
|
2510
|
-
/* @__PURE__ */ jsx(
|
|
2511
|
-
Line,
|
|
2512
|
-
{
|
|
2513
|
-
type: "monotone",
|
|
2514
|
-
dataKey: "guest_count",
|
|
2515
|
-
name: "Guest",
|
|
2516
|
-
stroke: GUEST_COLOR,
|
|
2517
|
-
strokeWidth: 2,
|
|
2518
|
-
dot: { r: 2 }
|
|
2519
|
-
}
|
|
2520
|
-
)
|
|
2521
|
-
]
|
|
2522
|
-
}
|
|
2523
|
-
) }) }) })
|
|
2524
|
-
] })
|
|
2525
|
-
}
|
|
2526
|
-
)
|
|
2527
|
-
] })
|
|
2528
|
-
] }) });
|
|
2529
|
-
}
|
|
2530
|
-
const SUMMARY_PERIODS = [
|
|
2531
|
-
{ value: "all", label: "All time" },
|
|
2532
|
-
{ value: "0", label: "Today" },
|
|
2533
|
-
{ value: "7", label: "Last 7 days" },
|
|
2534
|
-
{ value: "30", label: "Last 30 days" },
|
|
2535
|
-
{ value: "90", label: "Last 90 days" }
|
|
2536
|
-
];
|
|
2537
|
-
const GRAPH_PERIODS = [
|
|
2538
|
-
{ value: "one_week", label: "One week" },
|
|
2539
|
-
{ value: "one_month", label: "One month" },
|
|
2540
|
-
{ value: "one_year", label: "One year" }
|
|
2541
|
-
];
|
|
2542
|
-
const TOP_SELLER_PERIODS = [
|
|
2543
|
-
{ value: "week", label: "Week" },
|
|
2544
|
-
{ value: "month", label: "Month" },
|
|
2545
|
-
{ value: "year", label: "Year" },
|
|
2546
|
-
{ value: "all", label: "All time" }
|
|
2547
|
-
];
|
|
2548
|
-
const PRODUCT_CHART_COLORS = {
|
|
2549
|
-
units: "#38BDF8",
|
|
2550
|
-
views: "#C084FC",
|
|
2551
|
-
revenue: "#D946EF",
|
|
2552
|
-
revenueMuted: "#94A3B8",
|
|
2553
|
-
scatter: "#A855F7"
|
|
2554
|
-
};
|
|
2555
|
-
const KPI_ICON_BG = {
|
|
2556
|
-
green: "bg-emerald-500/20",
|
|
2557
|
-
blue: "bg-sky-500/20",
|
|
2558
|
-
purple: "bg-violet-500/20",
|
|
2559
|
-
amber: "bg-amber-500/20"
|
|
2560
|
-
};
|
|
2561
|
-
const KPI_ICONS = {
|
|
2562
|
-
green: CurrencyDollar,
|
|
2563
|
-
blue: ShoppingCart,
|
|
2564
|
-
purple: Tag,
|
|
2565
|
-
amber: CubeSolid
|
|
2566
|
-
};
|
|
2567
|
-
const CHART_AXIS_TICK = { fontSize: 10, fill: "#e5e7eb" };
|
|
2568
|
-
const CHART_AXIS_TICK_SM = { fontSize: 9, fill: "#e5e7eb" };
|
|
2569
|
-
const CHART_AXIS_LINE = "#94a3b8";
|
|
2570
|
-
const SELECT_CLASS_NAME = "h-9 w-full min-w-[8rem] max-w-full cursor-pointer appearance-none rounded border border-ui-border-base bg-ui-bg-base py-1.5 pl-3 pr-8 text-xs text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive sm:w-auto sm:min-w-[132px] sm:max-w-[220px]";
|
|
2571
|
-
const LEADERBOARD_TABLE_CLASS = "min-w-[32rem] sm:min-w-[36rem] max-w-none";
|
|
2572
|
-
const OPPORTUNITIES_TABLE_CLASS = "min-w-[30rem] sm:min-w-[34rem] max-w-none";
|
|
2573
|
-
const TABLE_HEAD_CELL_NOWRAP = "whitespace-nowrap";
|
|
2574
|
-
function formatCurrency(value) {
|
|
2575
|
-
return new Intl.NumberFormat("en-IN", {
|
|
2576
|
-
style: "currency",
|
|
2577
|
-
currency: "INR",
|
|
2578
|
-
minimumFractionDigits: 0,
|
|
2579
|
-
maximumFractionDigits: 0
|
|
2580
|
-
}).format(value);
|
|
2581
|
-
}
|
|
2582
|
-
function formatCompactCurrency(value) {
|
|
2583
|
-
return new Intl.NumberFormat("en-IN", {
|
|
2584
|
-
style: "currency",
|
|
2585
|
-
currency: "INR",
|
|
2586
|
-
notation: "compact",
|
|
2587
|
-
maximumFractionDigits: 1
|
|
2588
|
-
}).format(value);
|
|
2589
|
-
}
|
|
2590
|
-
function formatChartLabel(value) {
|
|
2591
|
-
if (!value) return "";
|
|
2592
|
-
const parsed = new Date(value);
|
|
2593
|
-
if (Number.isNaN(parsed.getTime())) return value;
|
|
2594
|
-
return `${parsed.getUTCMonth() + 1}/${parsed.getUTCDate()}`;
|
|
2595
|
-
}
|
|
2596
|
-
function formatRatio(value) {
|
|
2597
|
-
if (value === null || Number.isNaN(value)) return "N/A";
|
|
2598
|
-
return `${value.toFixed(2)}x`;
|
|
2599
|
-
}
|
|
2600
|
-
function formatShortNumber(value) {
|
|
2601
|
-
return new Intl.NumberFormat("en-IN", {
|
|
2602
|
-
notation: "compact",
|
|
2603
|
-
maximumFractionDigits: value < 10 ? 1 : 0
|
|
2604
|
-
}).format(value);
|
|
2605
|
-
}
|
|
2606
|
-
function topSellerPeriodToGraphPeriod(period) {
|
|
2607
|
-
if (period === "month") return "one_month";
|
|
2608
|
-
if (period === "year" || period === "all") return "one_year";
|
|
2609
|
-
return "one_week";
|
|
2610
|
-
}
|
|
2611
|
-
function summaryDaysToGraphPeriod(days) {
|
|
2612
|
-
if (days === "30") return "one_month";
|
|
2613
|
-
if (days === "all" || days === "90") return "one_year";
|
|
2614
|
-
return "one_week";
|
|
2615
|
-
}
|
|
2616
|
-
function buildAnalyticsUrl(path, params) {
|
|
2617
|
-
const search = new URLSearchParams();
|
|
2618
|
-
for (const [key, value] of Object.entries(params)) {
|
|
2619
|
-
if (value) {
|
|
2620
|
-
search.set(key, value);
|
|
2621
|
-
}
|
|
2622
|
-
}
|
|
2623
|
-
const query = search.toString();
|
|
2624
|
-
return query ? `${path}?${query}` : path;
|
|
2625
|
-
}
|
|
2626
|
-
function isProductOverTimePoint(value) {
|
|
2627
|
-
if (typeof value !== "object" || value === null) return false;
|
|
2628
|
-
const v = value;
|
|
2629
|
-
return typeof v.date === "string" && typeof v.units_sold === "number" && typeof v.revenue === "number" && typeof v.views === "number";
|
|
2630
|
-
}
|
|
2631
|
-
function TrendTooltip({
|
|
2632
|
-
active,
|
|
2633
|
-
payload,
|
|
2634
|
-
label
|
|
2635
|
-
}) {
|
|
2636
|
-
var _a, _b, _c, _d, _e;
|
|
2637
|
-
if (!active || !(payload == null ? void 0 : payload.length)) return null;
|
|
2638
|
-
const row = isProductOverTimePoint((_a = payload[0]) == null ? void 0 : _a.payload) ? (_b = payload[0]) == null ? void 0 : _b.payload : void 0;
|
|
2639
|
-
const displayLabel = (row == null ? void 0 : row.label) ?? (label ? new Date(label).toLocaleDateString() : "");
|
|
2640
|
-
const unitsSold = ((_c = payload.find((entry) => entry.name === "Units sold")) == null ? void 0 : _c.value) ?? 0;
|
|
2641
|
-
const views = ((_d = payload.find((entry) => entry.name === "Views")) == null ? void 0 : _d.value) ?? 0;
|
|
2642
|
-
const revenue = ((_e = payload.find((entry) => entry.name === "Revenue")) == null ? void 0 : _e.value) ?? 0;
|
|
2643
|
-
return /* @__PURE__ */ jsxs(AnalyticsTooltipCard, { title: displayLabel, children: [
|
|
2644
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
2645
|
-
"Units sold: ",
|
|
2646
|
-
/* @__PURE__ */ jsx("strong", { children: Math.floor(Number(unitsSold)).toLocaleString() })
|
|
2647
|
-
] }),
|
|
2648
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
2649
|
-
"Views: ",
|
|
2650
|
-
/* @__PURE__ */ jsx("strong", { children: Math.floor(Number(views)).toLocaleString() })
|
|
2651
|
-
] }),
|
|
2652
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
2653
|
-
"Revenue: ",
|
|
2654
|
-
/* @__PURE__ */ jsx("strong", { children: formatCurrency(Number(revenue)) })
|
|
2655
|
-
] })
|
|
2656
|
-
] });
|
|
2657
|
-
}
|
|
2658
|
-
function MiniTrendTooltip({
|
|
2659
|
-
active,
|
|
2660
|
-
payload,
|
|
2661
|
-
label,
|
|
2662
|
-
productHeadline,
|
|
2663
|
-
hideViewsRow,
|
|
2664
|
-
hideUnitsRow,
|
|
2665
|
-
hideRevenueRow
|
|
2666
|
-
}) {
|
|
2667
|
-
var _a, _b, _c, _d, _e;
|
|
2668
|
-
if (!active || !(payload == null ? void 0 : payload.length)) return null;
|
|
2669
|
-
const row = isProductOverTimePoint((_a = payload[0]) == null ? void 0 : _a.payload) ? (_b = payload[0]) == null ? void 0 : _b.payload : void 0;
|
|
2670
|
-
const labelKey = label !== void 0 && label !== null ? String(label) : "";
|
|
2671
|
-
const displayLabel = (row == null ? void 0 : row.label) ?? (labelKey ? new Date(labelKey).toLocaleDateString() : "");
|
|
2672
|
-
const unitsSold = ((_c = payload.find((entry) => entry.name === "Units sold")) == null ? void 0 : _c.value) ?? 0;
|
|
2673
|
-
const views = ((_d = payload.find((entry) => entry.name === "Views")) == null ? void 0 : _d.value) ?? 0;
|
|
2674
|
-
const revenue = ((_e = payload.find((entry) => entry.name === "Revenue")) == null ? void 0 : _e.value) ?? 0;
|
|
2675
|
-
const title = productHeadline ?? displayLabel;
|
|
2676
|
-
return /* @__PURE__ */ jsxs(AnalyticsTooltipCard, { variant: "compact", title, children: [
|
|
2677
|
-
productHeadline ? /* @__PURE__ */ jsx("div", { className: "mb-1 text-[10px] leading-tight opacity-80", children: displayLabel }) : null,
|
|
2678
|
-
!hideUnitsRow ? /* @__PURE__ */ jsxs("div", { children: [
|
|
2679
|
-
"Units sold: ",
|
|
2680
|
-
/* @__PURE__ */ jsx("strong", { children: Math.floor(Number(unitsSold)).toLocaleString() })
|
|
2681
|
-
] }) : null,
|
|
2682
|
-
!hideViewsRow ? /* @__PURE__ */ jsxs("div", { children: [
|
|
2683
|
-
"Views: ",
|
|
2684
|
-
/* @__PURE__ */ jsx("strong", { children: Math.floor(Number(views)).toLocaleString() })
|
|
2685
|
-
] }) : null,
|
|
2686
|
-
!hideRevenueRow ? /* @__PURE__ */ jsxs("div", { children: [
|
|
2687
|
-
"Revenue: ",
|
|
2688
|
-
/* @__PURE__ */ jsx("strong", { children: formatCurrency(Number(revenue)) })
|
|
2689
|
-
] }) : null
|
|
2690
|
-
] });
|
|
2691
|
-
}
|
|
2692
|
-
function ProductBarTooltip({
|
|
2693
|
-
active,
|
|
2694
|
-
payload,
|
|
2695
|
-
showViews = true
|
|
2696
|
-
}) {
|
|
2697
|
-
var _a;
|
|
2698
|
-
if (!active || !(payload == null ? void 0 : payload.length)) return null;
|
|
2699
|
-
const row = (_a = payload[0]) == null ? void 0 : _a.payload;
|
|
2700
|
-
if (!row) return null;
|
|
2701
|
-
const unitsSold = "units_sold" in row ? row.units_sold : 0;
|
|
2702
|
-
const totalViews = "total_views" in row ? row.total_views : 0;
|
|
2703
|
-
const revenue = "revenue" in row ? row.revenue : 0;
|
|
2704
|
-
return /* @__PURE__ */ jsxs(AnalyticsTooltipCard, { variant: "compact", title: row.product_title, children: [
|
|
2705
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
2706
|
-
"Units sold: ",
|
|
2707
|
-
/* @__PURE__ */ jsx("strong", { children: Math.floor(unitsSold).toLocaleString() })
|
|
2708
|
-
] }),
|
|
2709
|
-
showViews ? /* @__PURE__ */ jsxs("div", { children: [
|
|
2710
|
-
"Views: ",
|
|
2711
|
-
/* @__PURE__ */ jsx("strong", { children: Math.floor(totalViews).toLocaleString() })
|
|
2712
|
-
] }) : null,
|
|
2713
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
2714
|
-
"Revenue: ",
|
|
2715
|
-
/* @__PURE__ */ jsx("strong", { children: formatCurrency(Number(revenue)) })
|
|
2716
|
-
] })
|
|
2717
|
-
] });
|
|
2718
|
-
}
|
|
2719
|
-
function AtlasKpiCard({
|
|
2720
|
-
label,
|
|
2721
|
-
value,
|
|
2722
|
-
helper,
|
|
2723
|
-
accent
|
|
2724
|
-
}) {
|
|
2725
|
-
const Icon = KPI_ICONS[accent];
|
|
2726
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex h-full min-h-[88px] min-w-0 flex-col rounded-xl border border-ui-border-base/80 bg-ui-bg-subtle/25 p-3 shadow-sm", children: [
|
|
2727
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-2", children: [
|
|
2728
|
-
/* @__PURE__ */ jsx(Text, { className: "min-w-0 flex-1 text-left text-xs font-medium leading-snug text-ui-fg-base", children: label }),
|
|
2729
|
-
/* @__PURE__ */ jsx(
|
|
2730
|
-
"div",
|
|
2731
|
-
{
|
|
2732
|
-
className: `flex h-7 w-7 shrink-0 items-center justify-center rounded-lg ${KPI_ICON_BG[accent]}`,
|
|
2733
|
-
"aria-hidden": true,
|
|
2734
|
-
children: /* @__PURE__ */ jsx(Icon, { className: "h-3.5 w-3.5 text-ui-fg-base" })
|
|
2735
|
-
}
|
|
2736
|
-
)
|
|
489
|
+
)
|
|
490
|
+
] })
|
|
2737
491
|
] }),
|
|
2738
|
-
/* @__PURE__ */
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
}
|
|
2742
|
-
function EmptyAnalyticsPanel({ title, description }) {
|
|
2743
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex min-h-[88px] flex-col gap-1.5 rounded-lg border border-dashed border-ui-border-base px-3 py-3", children: [
|
|
2744
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-xs font-semibold", children: title }),
|
|
2745
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[11px] leading-snug", children: description })
|
|
2746
|
-
] });
|
|
2747
|
-
}
|
|
2748
|
-
function ProductsDashboard() {
|
|
2749
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2750
|
-
const [summaryDays, setSummaryDays] = useState("all");
|
|
2751
|
-
const [graphPeriod, setGraphPeriod] = useState("one_week");
|
|
2752
|
-
const [topSellerPeriod, setTopSellerPeriod] = useState("week");
|
|
2753
|
-
const [salesChannelId, setSalesChannelId] = useState("all");
|
|
2754
|
-
const [salesChannels, setSalesChannels] = useState([]);
|
|
2755
|
-
const [filtersLoading, setFiltersLoading] = useState(true);
|
|
2756
|
-
const [filtersError, setFiltersError] = useState(null);
|
|
2757
|
-
const [summary, setSummary] = useState(null);
|
|
2758
|
-
const [summaryLoading, setSummaryLoading] = useState(true);
|
|
2759
|
-
const [summaryError, setSummaryError] = useState(null);
|
|
2760
|
-
const [overTime, setOverTime] = useState(null);
|
|
2761
|
-
const [overTimeLoading, setOverTimeLoading] = useState(true);
|
|
2762
|
-
const [overTimeError, setOverTimeError] = useState(null);
|
|
2763
|
-
const [topSellers, setTopSellers] = useState(null);
|
|
2764
|
-
const [topSellersLoading, setTopSellersLoading] = useState(true);
|
|
2765
|
-
const [topSellersError, setTopSellersError] = useState(null);
|
|
2766
|
-
const [performance, setPerformance] = useState(null);
|
|
2767
|
-
const [performanceLoading, setPerformanceLoading] = useState(true);
|
|
2768
|
-
const [performanceError, setPerformanceError] = useState(null);
|
|
2769
|
-
const [bestSellersTrend, setBestSellersTrend] = useState(null);
|
|
2770
|
-
const [bestSellersTrendLoading, setBestSellersTrendLoading] = useState(true);
|
|
2771
|
-
const [bestSellersTrendError, setBestSellersTrendError] = useState(null);
|
|
2772
|
-
const [mostViewedTrend, setMostViewedTrend] = useState(null);
|
|
2773
|
-
const [mostViewedTrendLoading, setMostViewedTrendLoading] = useState(true);
|
|
2774
|
-
const [mostViewedTrendError, setMostViewedTrendError] = useState(null);
|
|
2775
|
-
useEffect(() => {
|
|
2776
|
-
let cancelled = false;
|
|
2777
|
-
setFiltersLoading(true);
|
|
2778
|
-
setFiltersError(null);
|
|
2779
|
-
fetch("/admin/analytics/products-filters", { credentials: "include" }).then((res) => {
|
|
2780
|
-
if (!res.ok) throw new Error(res.statusText);
|
|
2781
|
-
return res.json();
|
|
2782
|
-
}).then((body) => {
|
|
2783
|
-
if (!cancelled) {
|
|
2784
|
-
setSalesChannels(body.salesChannels ?? []);
|
|
2785
|
-
}
|
|
2786
|
-
}).catch((error) => {
|
|
2787
|
-
if (!cancelled) {
|
|
2788
|
-
setFiltersError(error instanceof Error ? error.message : String(error));
|
|
2789
|
-
}
|
|
2790
|
-
}).finally(() => {
|
|
2791
|
-
if (!cancelled) setFiltersLoading(false);
|
|
2792
|
-
});
|
|
2793
|
-
return () => {
|
|
2794
|
-
cancelled = true;
|
|
2795
|
-
};
|
|
2796
|
-
}, []);
|
|
2797
|
-
useEffect(() => {
|
|
2798
|
-
let cancelled = false;
|
|
2799
|
-
setSummaryLoading(true);
|
|
2800
|
-
setSummaryError(null);
|
|
2801
|
-
fetch(
|
|
2802
|
-
buildAnalyticsUrl("/admin/analytics/products-summary", {
|
|
2803
|
-
days: summaryDays,
|
|
2804
|
-
sales_channel_id: salesChannelId !== "all" ? salesChannelId : null
|
|
2805
|
-
}),
|
|
2806
|
-
{ credentials: "include" }
|
|
2807
|
-
).then((res) => {
|
|
2808
|
-
if (!res.ok) throw new Error(res.statusText);
|
|
2809
|
-
return res.json();
|
|
2810
|
-
}).then((body) => {
|
|
2811
|
-
if (!cancelled) setSummary(body);
|
|
2812
|
-
}).catch((error) => {
|
|
2813
|
-
if (!cancelled) {
|
|
2814
|
-
setSummaryError(error instanceof Error ? error.message : String(error));
|
|
2815
|
-
}
|
|
2816
|
-
}).finally(() => {
|
|
2817
|
-
if (!cancelled) setSummaryLoading(false);
|
|
2818
|
-
});
|
|
2819
|
-
return () => {
|
|
2820
|
-
cancelled = true;
|
|
2821
|
-
};
|
|
2822
|
-
}, [salesChannelId, summaryDays]);
|
|
2823
|
-
useEffect(() => {
|
|
2824
|
-
let cancelled = false;
|
|
2825
|
-
setOverTimeLoading(true);
|
|
2826
|
-
setOverTimeError(null);
|
|
2827
|
-
fetch(
|
|
2828
|
-
buildAnalyticsUrl("/admin/analytics/products-over-time", {
|
|
2829
|
-
period: graphPeriod,
|
|
2830
|
-
sales_channel_id: salesChannelId !== "all" ? salesChannelId : null
|
|
2831
|
-
}),
|
|
2832
|
-
{ credentials: "include" }
|
|
2833
|
-
).then((res) => {
|
|
2834
|
-
if (!res.ok) throw new Error(res.statusText);
|
|
2835
|
-
return res.json();
|
|
2836
|
-
}).then((body) => {
|
|
2837
|
-
if (!cancelled) setOverTime(body);
|
|
2838
|
-
}).catch((error) => {
|
|
2839
|
-
if (!cancelled) {
|
|
2840
|
-
setOverTimeError(error instanceof Error ? error.message : String(error));
|
|
2841
|
-
}
|
|
2842
|
-
}).finally(() => {
|
|
2843
|
-
if (!cancelled) setOverTimeLoading(false);
|
|
2844
|
-
});
|
|
2845
|
-
return () => {
|
|
2846
|
-
cancelled = true;
|
|
2847
|
-
};
|
|
2848
|
-
}, [graphPeriod, salesChannelId]);
|
|
2849
|
-
useEffect(() => {
|
|
2850
|
-
let cancelled = false;
|
|
2851
|
-
setTopSellersLoading(true);
|
|
2852
|
-
setTopSellersError(null);
|
|
2853
|
-
fetch(
|
|
2854
|
-
buildAnalyticsUrl("/admin/analytics/products-top-sellers", {
|
|
2855
|
-
period: topSellerPeriod,
|
|
2856
|
-
sales_channel_id: salesChannelId !== "all" ? salesChannelId : null
|
|
2857
|
-
}),
|
|
2858
|
-
{ credentials: "include" }
|
|
2859
|
-
).then((res) => {
|
|
2860
|
-
if (!res.ok) throw new Error(res.statusText);
|
|
2861
|
-
return res.json();
|
|
2862
|
-
}).then((body) => {
|
|
2863
|
-
if (!cancelled) setTopSellers(body);
|
|
2864
|
-
}).catch((error) => {
|
|
2865
|
-
if (!cancelled) {
|
|
2866
|
-
setTopSellersError(error instanceof Error ? error.message : String(error));
|
|
2867
|
-
}
|
|
2868
|
-
}).finally(() => {
|
|
2869
|
-
if (!cancelled) setTopSellersLoading(false);
|
|
2870
|
-
});
|
|
2871
|
-
return () => {
|
|
2872
|
-
cancelled = true;
|
|
2873
|
-
};
|
|
2874
|
-
}, [salesChannelId, topSellerPeriod]);
|
|
2875
|
-
useEffect(() => {
|
|
2876
|
-
var _a2;
|
|
2877
|
-
let cancelled = false;
|
|
2878
|
-
if (topSellersLoading) {
|
|
2879
|
-
setBestSellersTrendLoading(true);
|
|
2880
|
-
return () => {
|
|
2881
|
-
cancelled = true;
|
|
2882
|
-
};
|
|
2883
|
-
}
|
|
2884
|
-
if (topSellersError) {
|
|
2885
|
-
setBestSellersTrendLoading(false);
|
|
2886
|
-
setBestSellersTrendError(topSellersError);
|
|
2887
|
-
setBestSellersTrend(null);
|
|
2888
|
-
return () => {
|
|
2889
|
-
cancelled = true;
|
|
2890
|
-
};
|
|
2891
|
-
}
|
|
2892
|
-
const topSellersByUnits2 = [...(topSellers == null ? void 0 : topSellers.products) ?? []].sort((a, b) => {
|
|
2893
|
-
if (b.units_sold !== a.units_sold) return b.units_sold - a.units_sold;
|
|
2894
|
-
if (b.order_count !== a.order_count) return b.order_count - a.order_count;
|
|
2895
|
-
return b.revenue - a.revenue;
|
|
2896
|
-
});
|
|
2897
|
-
const topProductId = (_a2 = topSellersByUnits2[0]) == null ? void 0 : _a2.product_id;
|
|
2898
|
-
if (!topProductId) {
|
|
2899
|
-
setBestSellersTrendLoading(false);
|
|
2900
|
-
setBestSellersTrendError(null);
|
|
2901
|
-
setBestSellersTrend({
|
|
2902
|
-
series: [],
|
|
2903
|
-
productViewsConnected: (topSellers == null ? void 0 : topSellers.productViewsConnected) ?? false,
|
|
2904
|
-
product: null
|
|
2905
|
-
});
|
|
2906
|
-
return () => {
|
|
2907
|
-
cancelled = true;
|
|
2908
|
-
};
|
|
2909
|
-
}
|
|
2910
|
-
setBestSellersTrendLoading(true);
|
|
2911
|
-
setBestSellersTrendError(null);
|
|
2912
|
-
const period = topSellerPeriodToGraphPeriod(topSellerPeriod);
|
|
2913
|
-
fetch(
|
|
2914
|
-
buildAnalyticsUrl("/admin/analytics/products-over-time", {
|
|
2915
|
-
period,
|
|
2916
|
-
sales_channel_id: salesChannelId !== "all" ? salesChannelId : null,
|
|
2917
|
-
product_id: topProductId
|
|
2918
|
-
}),
|
|
2919
|
-
{ credentials: "include" }
|
|
2920
|
-
).then((res) => {
|
|
2921
|
-
if (!res.ok) throw new Error(res.statusText);
|
|
2922
|
-
return res.json();
|
|
2923
|
-
}).then((body) => {
|
|
2924
|
-
if (!cancelled) setBestSellersTrend(body);
|
|
2925
|
-
}).catch((error) => {
|
|
2926
|
-
if (!cancelled) {
|
|
2927
|
-
setBestSellersTrendError(error instanceof Error ? error.message : String(error));
|
|
2928
|
-
}
|
|
2929
|
-
}).finally(() => {
|
|
2930
|
-
if (!cancelled) setBestSellersTrendLoading(false);
|
|
2931
|
-
});
|
|
2932
|
-
return () => {
|
|
2933
|
-
cancelled = true;
|
|
2934
|
-
};
|
|
2935
|
-
}, [salesChannelId, topSellerPeriod, topSellersLoading, topSellersError, topSellers]);
|
|
2936
|
-
useEffect(() => {
|
|
2937
|
-
var _a2, _b2;
|
|
2938
|
-
let cancelled = false;
|
|
2939
|
-
if (performanceLoading) {
|
|
2940
|
-
setMostViewedTrendLoading(true);
|
|
2941
|
-
return () => {
|
|
2942
|
-
cancelled = true;
|
|
2943
|
-
};
|
|
2944
|
-
}
|
|
2945
|
-
if (performanceError) {
|
|
2946
|
-
setMostViewedTrendLoading(false);
|
|
2947
|
-
setMostViewedTrendError(performanceError);
|
|
2948
|
-
setMostViewedTrend(null);
|
|
2949
|
-
return () => {
|
|
2950
|
-
cancelled = true;
|
|
2951
|
-
};
|
|
2952
|
-
}
|
|
2953
|
-
if (!(performance == null ? void 0 : performance.productViewsConnected)) {
|
|
2954
|
-
setMostViewedTrendLoading(false);
|
|
2955
|
-
setMostViewedTrendError(null);
|
|
2956
|
-
setMostViewedTrend(null);
|
|
2957
|
-
return () => {
|
|
2958
|
-
cancelled = true;
|
|
2959
|
-
};
|
|
2960
|
-
}
|
|
2961
|
-
const topViewedId = (_b2 = (_a2 = performance.topViewedProducts) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.product_id;
|
|
2962
|
-
if (!topViewedId) {
|
|
2963
|
-
setMostViewedTrendLoading(false);
|
|
2964
|
-
setMostViewedTrendError(null);
|
|
2965
|
-
setMostViewedTrend({
|
|
2966
|
-
series: [],
|
|
2967
|
-
productViewsConnected: true,
|
|
2968
|
-
product: null
|
|
2969
|
-
});
|
|
2970
|
-
return () => {
|
|
2971
|
-
cancelled = true;
|
|
2972
|
-
};
|
|
2973
|
-
}
|
|
2974
|
-
setMostViewedTrendLoading(true);
|
|
2975
|
-
setMostViewedTrendError(null);
|
|
2976
|
-
const period = summaryDaysToGraphPeriod(summaryDays);
|
|
2977
|
-
fetch(
|
|
2978
|
-
buildAnalyticsUrl("/admin/analytics/products-over-time", {
|
|
2979
|
-
period,
|
|
2980
|
-
sales_channel_id: salesChannelId !== "all" ? salesChannelId : null,
|
|
2981
|
-
product_id: topViewedId
|
|
2982
|
-
}),
|
|
2983
|
-
{ credentials: "include" }
|
|
2984
|
-
).then((res) => {
|
|
2985
|
-
if (!res.ok) throw new Error(res.statusText);
|
|
2986
|
-
return res.json();
|
|
2987
|
-
}).then((body) => {
|
|
2988
|
-
if (!cancelled) setMostViewedTrend(body);
|
|
2989
|
-
}).catch((error) => {
|
|
2990
|
-
if (!cancelled) {
|
|
2991
|
-
setMostViewedTrendError(error instanceof Error ? error.message : String(error));
|
|
2992
|
-
}
|
|
2993
|
-
}).finally(() => {
|
|
2994
|
-
if (!cancelled) setMostViewedTrendLoading(false);
|
|
2995
|
-
});
|
|
2996
|
-
return () => {
|
|
2997
|
-
cancelled = true;
|
|
2998
|
-
};
|
|
2999
|
-
}, [salesChannelId, summaryDays, performanceLoading, performanceError, performance]);
|
|
3000
|
-
useEffect(() => {
|
|
3001
|
-
let cancelled = false;
|
|
3002
|
-
setPerformanceLoading(true);
|
|
3003
|
-
setPerformanceError(null);
|
|
3004
|
-
fetch(
|
|
3005
|
-
buildAnalyticsUrl("/admin/analytics/products-performance", {
|
|
3006
|
-
days: summaryDays,
|
|
3007
|
-
sales_channel_id: salesChannelId !== "all" ? salesChannelId : null
|
|
3008
|
-
}),
|
|
3009
|
-
{ credentials: "include" }
|
|
3010
|
-
).then((res) => {
|
|
3011
|
-
if (!res.ok) throw new Error(res.statusText);
|
|
3012
|
-
return res.json();
|
|
3013
|
-
}).then((body) => {
|
|
3014
|
-
if (!cancelled) setPerformance(body);
|
|
3015
|
-
}).catch((error) => {
|
|
3016
|
-
if (!cancelled) {
|
|
3017
|
-
setPerformanceError(error instanceof Error ? error.message : String(error));
|
|
3018
|
-
}
|
|
3019
|
-
}).finally(() => {
|
|
3020
|
-
if (!cancelled) setPerformanceLoading(false);
|
|
3021
|
-
});
|
|
3022
|
-
return () => {
|
|
3023
|
-
cancelled = true;
|
|
3024
|
-
};
|
|
3025
|
-
}, [salesChannelId, summaryDays]);
|
|
3026
|
-
const series = (overTime == null ? void 0 : overTime.series) ?? [];
|
|
3027
|
-
const trendTotals = useMemo(() => {
|
|
3028
|
-
const totalUnits = series.reduce((s, p) => s + p.units_sold, 0);
|
|
3029
|
-
const totalRevenue = series.reduce((s, p) => s + p.revenue, 0);
|
|
3030
|
-
const totalViews = series.reduce((s, p) => s + p.views, 0);
|
|
3031
|
-
const n = series.length || 1;
|
|
3032
|
-
return {
|
|
3033
|
-
totalUnits,
|
|
3034
|
-
totalRevenue,
|
|
3035
|
-
totalViews,
|
|
3036
|
-
avgUnitsPerDay: totalUnits / n,
|
|
3037
|
-
avgRevenuePerDay: totalRevenue / n,
|
|
3038
|
-
avgViewsPerDay: totalViews / n
|
|
3039
|
-
};
|
|
3040
|
-
}, [series]);
|
|
3041
|
-
const peakRevenuePoint = series.length > 0 ? series.reduce((peak, point) => point.revenue > peak.revenue ? point : peak) : null;
|
|
3042
|
-
const viewsConnectedForPulse = ((summary == null ? void 0 : summary.productViewsConnected) ?? false) || (overTime == null ? void 0 : overTime.productViewsConnected) === true || (topSellers == null ? void 0 : topSellers.productViewsConnected) === true || (performance == null ? void 0 : performance.productViewsConnected) === true;
|
|
3043
|
-
const topSellersByUnits = useMemo(
|
|
3044
|
-
() => [...(topSellers == null ? void 0 : topSellers.products) ?? []].sort((a, b) => {
|
|
3045
|
-
if (b.units_sold !== a.units_sold) return b.units_sold - a.units_sold;
|
|
3046
|
-
if (b.order_count !== a.order_count) return b.order_count - a.order_count;
|
|
3047
|
-
return b.revenue - a.revenue;
|
|
3048
|
-
}),
|
|
3049
|
-
[topSellers]
|
|
3050
|
-
);
|
|
3051
|
-
const bestSellersTrendSeries = (bestSellersTrend == null ? void 0 : bestSellersTrend.series) ?? [];
|
|
3052
|
-
const mostViewedTrendSeries = (mostViewedTrend == null ? void 0 : mostViewedTrend.series) ?? [];
|
|
3053
|
-
const bestSellerTrendProductTitle = ((_a = bestSellersTrend == null ? void 0 : bestSellersTrend.product) == null ? void 0 : _a.product_title) ?? ((_b = topSellersByUnits[0]) == null ? void 0 : _b.product_title) ?? null;
|
|
3054
|
-
const mostViewedTrendProductTitle = ((_c = mostViewedTrend == null ? void 0 : mostViewedTrend.product) == null ? void 0 : _c.product_title) ?? ((_e = (_d = performance == null ? void 0 : performance.topViewedProducts) == null ? void 0 : _d[0]) == null ? void 0 : _e.product_title) ?? null;
|
|
3055
|
-
const viewsVsUnitsScatterData = useMemo(
|
|
3056
|
-
() => ((performance == null ? void 0 : performance.topViewedProducts) ?? []).slice(0, 48).filter((row) => row.total_views > 0 || row.units_sold > 0),
|
|
3057
|
-
[performance]
|
|
3058
|
-
);
|
|
3059
|
-
const selectedSummaryPeriod = ((_f = SUMMARY_PERIODS.find((p) => p.value === summaryDays)) == null ? void 0 : _f.label) ?? "All time";
|
|
3060
|
-
const selectedGraphPeriodLabel = ((_g = GRAPH_PERIODS.find((p) => p.value === graphPeriod)) == null ? void 0 : _g.label) ?? "One week";
|
|
3061
|
-
const quickPulseMetrics = [
|
|
3062
|
-
{
|
|
3063
|
-
label: "Range units",
|
|
3064
|
-
value: formatShortNumber(trendTotals.totalUnits),
|
|
3065
|
-
helper: selectedGraphPeriodLabel,
|
|
3066
|
-
accentClassName: "border-sky-400/25 bg-sky-500/5"
|
|
3067
|
-
},
|
|
3068
|
-
{
|
|
3069
|
-
label: "Range revenue",
|
|
3070
|
-
value: formatCompactCurrency(trendTotals.totalRevenue),
|
|
3071
|
-
helper: "Current chart window",
|
|
3072
|
-
accentClassName: "border-fuchsia-400/25 bg-fuchsia-500/5"
|
|
3073
|
-
},
|
|
3074
|
-
{
|
|
3075
|
-
label: "Avg/day views",
|
|
3076
|
-
value: trendTotals.avgViewsPerDay.toFixed(0),
|
|
3077
|
-
helper: viewsConnectedForPulse ? "Across chart range" : "Views need tracking",
|
|
3078
|
-
accentClassName: "border-violet-400/25 bg-violet-500/5"
|
|
3079
|
-
},
|
|
3080
|
-
{
|
|
3081
|
-
label: "Peak revenue day",
|
|
3082
|
-
value: peakRevenuePoint ? formatCompactCurrency(peakRevenuePoint.revenue) : "—",
|
|
3083
|
-
helper: (peakRevenuePoint == null ? void 0 : peakRevenuePoint.label) ?? formatChartLabel(peakRevenuePoint == null ? void 0 : peakRevenuePoint.date),
|
|
3084
|
-
accentClassName: "border-amber-400/25 bg-amber-500/5"
|
|
3085
|
-
}
|
|
3086
|
-
];
|
|
3087
|
-
if (summaryLoading) {
|
|
3088
|
-
return /* @__PURE__ */ jsx(
|
|
3089
|
-
"div",
|
|
3090
|
-
{
|
|
3091
|
-
className: "flex min-h-[200px] items-center justify-center",
|
|
3092
|
-
role: "status",
|
|
3093
|
-
"aria-label": "Loading product analytics",
|
|
3094
|
-
children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted", children: "Loading…" })
|
|
3095
|
-
}
|
|
3096
|
-
);
|
|
3097
|
-
}
|
|
3098
|
-
if (summaryError || !summary) {
|
|
3099
|
-
return /* @__PURE__ */ jsx(Container, { className: "p-6", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger", children: summaryError ?? "Failed to load product analytics" }) });
|
|
3100
|
-
}
|
|
3101
|
-
const viewsConnected = summary.productViewsConnected || (overTime == null ? void 0 : overTime.productViewsConnected) === true || (topSellers == null ? void 0 : topSellers.productViewsConnected) === true || (performance == null ? void 0 : performance.productViewsConnected) === true;
|
|
3102
|
-
const selectedChannelLabel = salesChannelId === "all" ? "All channels" : ((_h = salesChannels.find((channel) => channel.id === salesChannelId)) == null ? void 0 : _h.name) ?? "Selected channel";
|
|
3103
|
-
const primaryStats = [
|
|
3104
|
-
{
|
|
3105
|
-
label: "Units sold",
|
|
3106
|
-
value: summary.unitsSold.toLocaleString(),
|
|
3107
|
-
helper: selectedSummaryPeriod,
|
|
3108
|
-
accent: "amber"
|
|
3109
|
-
},
|
|
3110
|
-
{
|
|
3111
|
-
label: "Product revenue",
|
|
3112
|
-
value: formatCurrency(summary.productRevenue),
|
|
3113
|
-
helper: selectedSummaryPeriod,
|
|
3114
|
-
accent: "green"
|
|
3115
|
-
},
|
|
3116
|
-
{
|
|
3117
|
-
label: "Orders with products",
|
|
3118
|
-
value: summary.ordersWithProducts.toLocaleString(),
|
|
3119
|
-
helper: "Distinct orders",
|
|
3120
|
-
accent: "blue"
|
|
3121
|
-
},
|
|
3122
|
-
{
|
|
3123
|
-
label: "Active products sold",
|
|
3124
|
-
value: summary.activeProductsSold.toLocaleString(),
|
|
3125
|
-
helper: "Unique SKUs with sales",
|
|
3126
|
-
accent: "purple"
|
|
3127
|
-
},
|
|
3128
|
-
{
|
|
3129
|
-
label: "Product views",
|
|
3130
|
-
value: summary.totalProductViews.toLocaleString(),
|
|
3131
|
-
helper: viewsConnected ? "Tracked views" : "Tracking unavailable",
|
|
3132
|
-
accent: "green"
|
|
3133
|
-
},
|
|
3134
|
-
{
|
|
3135
|
-
label: "View / order ratio",
|
|
3136
|
-
value: formatRatio(summary.viewToOrderRatio),
|
|
3137
|
-
helper: viewsConnected ? "Views per product order" : "N/A without views",
|
|
3138
|
-
accent: "blue"
|
|
3139
|
-
}
|
|
3140
|
-
];
|
|
3141
|
-
return /* @__PURE__ */ jsx(AnalyticsDashboardShell, { className: "w-full min-w-0 max-w-full", children: /* @__PURE__ */ jsxs("div", { className: "w-full min-w-0 max-w-full overflow-hidden rounded-2xl border border-ui-border-base/80 bg-ui-bg-base shadow-sm", children: [
|
|
3142
|
-
/* @__PURE__ */ jsx(
|
|
3143
|
-
AnalyticsDashboardHeader,
|
|
3144
|
-
{
|
|
3145
|
-
variant: "premium",
|
|
3146
|
-
appearance: "inset",
|
|
3147
|
-
actionsBare: true,
|
|
3148
|
-
actionsClassName: "w-full justify-start lg:w-auto lg:justify-end",
|
|
3149
|
-
title: "Products",
|
|
3150
|
-
description: "Units, revenue, best sellers, and visit behavior in a compact layout aligned with Orders analytics.",
|
|
3151
|
-
actions: /* @__PURE__ */ jsxs("div", { className: "flex w-full min-w-0 flex-wrap items-center gap-x-3 gap-y-2 sm:flex-nowrap lg:gap-x-4", children: [
|
|
3152
|
-
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-2 sm:flex-initial sm:flex-none", children: [
|
|
3153
|
-
/* @__PURE__ */ jsx(
|
|
3154
|
-
Label,
|
|
3155
|
-
{
|
|
3156
|
-
htmlFor: "products-channel-filter",
|
|
3157
|
-
className: "shrink-0 whitespace-nowrap text-ui-fg-muted text-xs font-medium",
|
|
3158
|
-
children: "Channel"
|
|
3159
|
-
}
|
|
3160
|
-
),
|
|
3161
|
-
/* @__PURE__ */ jsxs(
|
|
3162
|
-
"select",
|
|
3163
|
-
{
|
|
3164
|
-
id: "products-channel-filter",
|
|
3165
|
-
value: salesChannelId,
|
|
3166
|
-
onChange: (event) => setSalesChannelId(event.target.value),
|
|
3167
|
-
disabled: filtersLoading,
|
|
3168
|
-
className: SELECT_CLASS_NAME,
|
|
3169
|
-
"aria-busy": filtersLoading,
|
|
3170
|
-
children: [
|
|
3171
|
-
/* @__PURE__ */ jsx("option", { value: "all", children: "All channels" }),
|
|
3172
|
-
salesChannels.map((channel) => /* @__PURE__ */ jsx("option", { value: channel.id, children: channel.name }, channel.id))
|
|
3173
|
-
]
|
|
3174
|
-
}
|
|
3175
|
-
)
|
|
3176
|
-
] }),
|
|
3177
|
-
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-2 sm:flex-initial sm:flex-none", children: [
|
|
3178
|
-
/* @__PURE__ */ jsx(
|
|
3179
|
-
Label,
|
|
3180
|
-
{
|
|
3181
|
-
htmlFor: "products-summary-period",
|
|
3182
|
-
className: "shrink-0 whitespace-nowrap text-ui-fg-muted text-xs font-medium",
|
|
3183
|
-
children: "Period"
|
|
3184
|
-
}
|
|
3185
|
-
),
|
|
3186
|
-
/* @__PURE__ */ jsx(
|
|
3187
|
-
"select",
|
|
3188
|
-
{
|
|
3189
|
-
id: "products-summary-period",
|
|
3190
|
-
value: summaryDays,
|
|
3191
|
-
onChange: (event) => setSummaryDays(event.target.value),
|
|
3192
|
-
className: SELECT_CLASS_NAME,
|
|
3193
|
-
children: SUMMARY_PERIODS.map((period) => /* @__PURE__ */ jsx("option", { value: period.value, children: period.label }, period.value))
|
|
3194
|
-
}
|
|
3195
|
-
)
|
|
3196
|
-
] }),
|
|
3197
|
-
/* @__PURE__ */ jsxs("div", { className: "flex w-full shrink-0 flex-wrap items-center gap-x-3 gap-y-1 sm:w-auto sm:pl-1", children: [
|
|
3198
|
-
summaryDays !== "all" ? /* @__PURE__ */ jsx(
|
|
3199
|
-
"button",
|
|
3200
|
-
{
|
|
3201
|
-
type: "button",
|
|
3202
|
-
onClick: () => setSummaryDays("all"),
|
|
3203
|
-
className: "text-xs text-ui-fg-muted transition-colors hover:text-ui-fg-base",
|
|
3204
|
-
"aria-label": "Clear summary period filter",
|
|
3205
|
-
children: "Clear period"
|
|
3206
|
-
}
|
|
3207
|
-
) : null,
|
|
3208
|
-
salesChannelId !== "all" ? /* @__PURE__ */ jsx(
|
|
3209
|
-
"button",
|
|
3210
|
-
{
|
|
3211
|
-
type: "button",
|
|
3212
|
-
onClick: () => setSalesChannelId("all"),
|
|
3213
|
-
className: "text-xs text-ui-fg-muted transition-colors hover:text-ui-fg-base",
|
|
3214
|
-
"aria-label": "Clear sales channel filter",
|
|
3215
|
-
children: "Clear channel"
|
|
3216
|
-
}
|
|
3217
|
-
) : null
|
|
3218
|
-
] })
|
|
3219
|
-
] })
|
|
3220
|
-
}
|
|
3221
|
-
),
|
|
3222
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-2 p-2 pt-0 sm:p-3 sm:pt-0 md:p-4 md:pt-0", children: [
|
|
3223
|
-
filtersError ? /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-dashed border-ui-border-base bg-ui-bg-subtle/30 px-3 py-2", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger text-xs", children: filtersError }) }) : null,
|
|
3224
|
-
!viewsConnected ? /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-dashed border-ui-border-base bg-ui-bg-subtle/30 px-3 py-2", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[11px] leading-snug", children: "Product views are unavailable until the `medusa-product-helper` tracking module is registered and storefront page views are being recorded." }) }) : null,
|
|
3225
|
-
salesChannelId !== "all" && viewsConnected ? /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-ui-border-base/80 bg-ui-bg-subtle/25 px-3 py-2 shadow-sm", children: /* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-muted text-[11px] leading-snug", children: [
|
|
3226
|
-
"Showing analytics for ",
|
|
3227
|
-
/* @__PURE__ */ jsx("span", { className: "font-medium text-ui-fg-base", children: selectedChannelLabel }),
|
|
3228
|
-
". Views are scoped to products assigned to this sales channel."
|
|
3229
|
-
] }) }) : null,
|
|
3230
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
|
|
3231
|
-
/* @__PURE__ */ jsx("div", { className: "px-0.5", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.16em]", children: "Product overview" }) }),
|
|
3232
|
-
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-6", children: primaryStats.map((stat) => /* @__PURE__ */ jsx(
|
|
3233
|
-
AtlasKpiCard,
|
|
3234
|
-
{
|
|
3235
|
-
label: stat.label,
|
|
3236
|
-
value: stat.value,
|
|
3237
|
-
helper: stat.helper,
|
|
3238
|
-
accent: stat.accent
|
|
3239
|
-
},
|
|
3240
|
-
stat.label
|
|
3241
|
-
)) })
|
|
492
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4", children: [
|
|
493
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
494
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Guest customers" }),
|
|
495
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: Math.floor(data.guestCount).toLocaleString() })
|
|
3242
496
|
] }),
|
|
3243
|
-
/* @__PURE__ */ jsxs(
|
|
3244
|
-
/* @__PURE__ */ jsx(
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
/* @__PURE__ */ jsx(
|
|
3261
|
-
"select",
|
|
3262
|
-
{
|
|
3263
|
-
id: "products-graph-period",
|
|
3264
|
-
value: graphPeriod,
|
|
3265
|
-
onChange: (event) => setGraphPeriod(event.target.value),
|
|
3266
|
-
className: SELECT_CLASS_NAME,
|
|
3267
|
-
children: GRAPH_PERIODS.map((period) => /* @__PURE__ */ jsx("option", { value: period.value, children: period.label }, period.value))
|
|
3268
|
-
}
|
|
3269
|
-
)
|
|
3270
|
-
] }),
|
|
3271
|
-
children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
3272
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-2 sm:grid-cols-3 sm:gap-1.5", children: [
|
|
3273
|
-
/* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", className: "min-h-0", children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
3274
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "Window units" }),
|
|
3275
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-lg font-semibold tracking-tight", children: formatShortNumber(trendTotals.totalUnits) }),
|
|
3276
|
-
/* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-muted text-[10px]", children: [
|
|
3277
|
-
"Avg/day ",
|
|
3278
|
-
trendTotals.avgUnitsPerDay.toFixed(1)
|
|
3279
|
-
] })
|
|
3280
|
-
] }) }),
|
|
3281
|
-
/* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", className: "min-h-0", children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
3282
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "Window revenue" }),
|
|
3283
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-lg font-semibold tracking-tight", children: formatCompactCurrency(trendTotals.totalRevenue) }),
|
|
3284
|
-
/* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-muted text-[10px]", children: [
|
|
3285
|
-
"Avg/day ",
|
|
3286
|
-
formatCompactCurrency(trendTotals.avgRevenuePerDay)
|
|
3287
|
-
] })
|
|
3288
|
-
] }) }),
|
|
3289
|
-
/* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", className: "min-h-0", children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
3290
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: "Window views" }),
|
|
3291
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-lg font-semibold tracking-tight", children: formatShortNumber(trendTotals.totalViews) }),
|
|
3292
|
-
/* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-muted text-[10px]", children: [
|
|
3293
|
-
"Avg/day ",
|
|
3294
|
-
trendTotals.avgViewsPerDay.toFixed(0)
|
|
3295
|
-
] })
|
|
3296
|
-
] }) })
|
|
3297
|
-
] }),
|
|
3298
|
-
/* @__PURE__ */ jsxs(AnalyticsChartSurface, { variant: "atlas", className: "relative overflow-hidden", children: [
|
|
3299
|
-
/* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-x-6 top-0 h-12 rounded-b-full bg-gradient-to-r from-sky-400/10 via-fuchsia-400/10 to-transparent blur-xl" }),
|
|
3300
|
-
/* @__PURE__ */ jsxs("div", { className: "relative space-y-1", children: [
|
|
3301
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-1.5", children: [
|
|
3302
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-0", children: [
|
|
3303
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.16em]", children: "Trend overview" }),
|
|
3304
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base text-sm font-semibold", children: selectedGraphPeriodLabel })
|
|
3305
|
-
] }),
|
|
3306
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap justify-end gap-2 text-[10px] text-ui-fg-muted", children: [
|
|
3307
|
-
/* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1", children: [
|
|
3308
|
-
/* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 rounded-full bg-sky-400" }),
|
|
3309
|
-
"Units"
|
|
3310
|
-
] }),
|
|
3311
|
-
/* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1", children: [
|
|
3312
|
-
/* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 rounded-full bg-violet-400" }),
|
|
3313
|
-
"Views"
|
|
3314
|
-
] }),
|
|
3315
|
-
/* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1", children: [
|
|
3316
|
-
/* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 rounded-full bg-fuchsia-400" }),
|
|
3317
|
-
"Revenue"
|
|
3318
|
-
] })
|
|
3319
|
-
] })
|
|
3320
|
-
] }),
|
|
3321
|
-
/* @__PURE__ */ jsx("div", { className: "h-[min(168px,24vh)] min-h-[140px] sm:h-[min(184px,26vh)]", children: overTimeLoading ? /* @__PURE__ */ jsx(
|
|
3322
|
-
"div",
|
|
3323
|
-
{
|
|
3324
|
-
className: "flex h-full items-center justify-center",
|
|
3325
|
-
role: "status",
|
|
3326
|
-
"aria-label": "Loading product trend chart",
|
|
3327
|
-
children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "Loading chart…" })
|
|
3328
|
-
}
|
|
3329
|
-
) : overTimeError ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center px-2", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger text-center text-xs", children: overTimeError }) }) : series.length === 0 ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "No data in this range." }) }) : /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
|
|
3330
|
-
ComposedChart,
|
|
3331
|
-
{
|
|
3332
|
-
data: series,
|
|
3333
|
-
margin: { top: 4, right: 6, left: -6, bottom: 0 },
|
|
3334
|
-
children: [
|
|
3335
|
-
/* @__PURE__ */ jsxs("defs", { children: [
|
|
3336
|
-
/* @__PURE__ */ jsxs("linearGradient", { id: "productUnitsGradient", x1: "0", y1: "0", x2: "1", y2: "0", children: [
|
|
3337
|
-
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: "#67E8F9" }),
|
|
3338
|
-
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: "#3B82F6" })
|
|
3339
|
-
] }),
|
|
3340
|
-
/* @__PURE__ */ jsxs("linearGradient", { id: "productRevenueGradient", x1: "0", y1: "0", x2: "1", y2: "0", children: [
|
|
3341
|
-
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: "#F472B6" }),
|
|
3342
|
-
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: "#C084FC" })
|
|
3343
|
-
] }),
|
|
3344
|
-
/* @__PURE__ */ jsxs("linearGradient", { id: "productUnitsAreaFill", x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
3345
|
-
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: "#38BDF8", stopOpacity: 0.22 }),
|
|
3346
|
-
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: "#38BDF8", stopOpacity: 0 })
|
|
3347
|
-
] }),
|
|
3348
|
-
/* @__PURE__ */ jsxs("linearGradient", { id: "productRevenueAreaFill", x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
3349
|
-
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: "#E879F9", stopOpacity: 0.2 }),
|
|
3350
|
-
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: "#E879F9", stopOpacity: 0 })
|
|
3351
|
-
] }),
|
|
3352
|
-
/* @__PURE__ */ jsxs("linearGradient", { id: "productViewsAreaFill", x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
3353
|
-
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: "#C084FC", stopOpacity: 0.18 }),
|
|
3354
|
-
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: "#C084FC", stopOpacity: 0 })
|
|
3355
|
-
] })
|
|
3356
|
-
] }),
|
|
3357
|
-
/* @__PURE__ */ jsx(
|
|
3358
|
-
CartesianGrid,
|
|
3359
|
-
{
|
|
3360
|
-
stroke: "rgba(148,163,184,0.14)",
|
|
3361
|
-
strokeDasharray: "3 3",
|
|
3362
|
-
vertical: false
|
|
3363
|
-
}
|
|
3364
|
-
),
|
|
3365
|
-
/* @__PURE__ */ jsx(
|
|
3366
|
-
XAxis,
|
|
3367
|
-
{
|
|
3368
|
-
dataKey: "date",
|
|
3369
|
-
tick: CHART_AXIS_TICK,
|
|
3370
|
-
tickLine: false,
|
|
3371
|
-
axisLine: false,
|
|
3372
|
-
tickFormatter: (value, index) => {
|
|
3373
|
-
const row = series[index];
|
|
3374
|
-
return (row == null ? void 0 : row.label) ?? formatChartLabel(String(value));
|
|
3375
|
-
}
|
|
3376
|
-
}
|
|
3377
|
-
),
|
|
3378
|
-
/* @__PURE__ */ jsx(
|
|
3379
|
-
YAxis,
|
|
3380
|
-
{
|
|
3381
|
-
yAxisId: "counts",
|
|
3382
|
-
width: 32,
|
|
3383
|
-
tick: CHART_AXIS_TICK,
|
|
3384
|
-
tickLine: false,
|
|
3385
|
-
axisLine: false,
|
|
3386
|
-
allowDecimals: false,
|
|
3387
|
-
tickFormatter: (value) => Math.floor(Number(value) || 0).toLocaleString()
|
|
3388
|
-
}
|
|
3389
|
-
),
|
|
3390
|
-
/* @__PURE__ */ jsx(
|
|
3391
|
-
YAxis,
|
|
3392
|
-
{
|
|
3393
|
-
yAxisId: "revenue",
|
|
3394
|
-
orientation: "right",
|
|
3395
|
-
width: 40,
|
|
3396
|
-
tick: CHART_AXIS_TICK,
|
|
3397
|
-
tickLine: false,
|
|
3398
|
-
axisLine: false,
|
|
3399
|
-
tickFormatter: (value) => formatCompactCurrency(Number(value) || 0)
|
|
3400
|
-
}
|
|
3401
|
-
),
|
|
3402
|
-
/* @__PURE__ */ jsx(
|
|
3403
|
-
Tooltip,
|
|
3404
|
-
{
|
|
3405
|
-
content: /* @__PURE__ */ jsx(TrendTooltip, {}),
|
|
3406
|
-
cursor: {
|
|
3407
|
-
stroke: "rgba(248, 250, 252, 0.35)",
|
|
3408
|
-
strokeWidth: 1
|
|
3409
|
-
}
|
|
3410
|
-
}
|
|
3411
|
-
),
|
|
3412
|
-
/* @__PURE__ */ jsx(
|
|
3413
|
-
Area,
|
|
3414
|
-
{
|
|
3415
|
-
yAxisId: "counts",
|
|
3416
|
-
type: "natural",
|
|
3417
|
-
dataKey: "units_sold",
|
|
3418
|
-
stroke: "none",
|
|
3419
|
-
fill: "url(#productUnitsAreaFill)",
|
|
3420
|
-
isAnimationActive: false,
|
|
3421
|
-
legendType: "none"
|
|
3422
|
-
}
|
|
3423
|
-
),
|
|
3424
|
-
/* @__PURE__ */ jsx(
|
|
3425
|
-
Area,
|
|
3426
|
-
{
|
|
3427
|
-
yAxisId: "counts",
|
|
3428
|
-
type: "natural",
|
|
3429
|
-
dataKey: "views",
|
|
3430
|
-
stroke: "none",
|
|
3431
|
-
fill: "url(#productViewsAreaFill)",
|
|
3432
|
-
isAnimationActive: false,
|
|
3433
|
-
legendType: "none"
|
|
3434
|
-
}
|
|
3435
|
-
),
|
|
3436
|
-
/* @__PURE__ */ jsx(
|
|
3437
|
-
Area,
|
|
3438
|
-
{
|
|
3439
|
-
yAxisId: "revenue",
|
|
3440
|
-
type: "natural",
|
|
3441
|
-
dataKey: "revenue",
|
|
3442
|
-
stroke: "none",
|
|
3443
|
-
fill: "url(#productRevenueAreaFill)",
|
|
3444
|
-
isAnimationActive: false,
|
|
3445
|
-
legendType: "none"
|
|
3446
|
-
}
|
|
3447
|
-
),
|
|
3448
|
-
/* @__PURE__ */ jsx(
|
|
3449
|
-
Line,
|
|
3450
|
-
{
|
|
3451
|
-
yAxisId: "counts",
|
|
3452
|
-
type: "natural",
|
|
3453
|
-
dataKey: "units_sold",
|
|
3454
|
-
name: "Units sold",
|
|
3455
|
-
stroke: "url(#productUnitsGradient)",
|
|
3456
|
-
strokeWidth: 2,
|
|
3457
|
-
dot: false,
|
|
3458
|
-
activeDot: { r: 4, fill: PRODUCT_CHART_COLORS.units }
|
|
3459
|
-
}
|
|
3460
|
-
),
|
|
3461
|
-
/* @__PURE__ */ jsx(
|
|
3462
|
-
Line,
|
|
3463
|
-
{
|
|
3464
|
-
yAxisId: "counts",
|
|
3465
|
-
type: "natural",
|
|
3466
|
-
dataKey: "views",
|
|
3467
|
-
name: "Views",
|
|
3468
|
-
stroke: PRODUCT_CHART_COLORS.views,
|
|
3469
|
-
strokeWidth: 1.5,
|
|
3470
|
-
strokeDasharray: "4 3",
|
|
3471
|
-
dot: false,
|
|
3472
|
-
activeDot: { r: 4, fill: PRODUCT_CHART_COLORS.views }
|
|
3473
|
-
}
|
|
3474
|
-
),
|
|
3475
|
-
/* @__PURE__ */ jsx(
|
|
3476
|
-
Line,
|
|
3477
|
-
{
|
|
3478
|
-
yAxisId: "revenue",
|
|
3479
|
-
type: "natural",
|
|
3480
|
-
dataKey: "revenue",
|
|
3481
|
-
name: "Revenue",
|
|
3482
|
-
stroke: "url(#productRevenueGradient)",
|
|
3483
|
-
strokeWidth: 2,
|
|
3484
|
-
dot: false,
|
|
3485
|
-
activeDot: { r: 4, fill: PRODUCT_CHART_COLORS.revenue }
|
|
3486
|
-
}
|
|
3487
|
-
)
|
|
3488
|
-
]
|
|
3489
|
-
}
|
|
3490
|
-
) }) })
|
|
3491
|
-
] })
|
|
3492
|
-
] })
|
|
3493
|
-
] })
|
|
3494
|
-
}
|
|
3495
|
-
) }),
|
|
3496
|
-
/* @__PURE__ */ jsxs("div", { className: "col-span-12 flex flex-col gap-2 lg:col-span-6", children: [
|
|
497
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
498
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Registered customers" }),
|
|
499
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: Math.floor(data.registeredCount).toLocaleString() })
|
|
500
|
+
] }),
|
|
501
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
502
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Overall customers" }),
|
|
503
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: Math.floor(data.totalCount).toLocaleString() })
|
|
504
|
+
] }),
|
|
505
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-4", children: [
|
|
506
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Deleted accounts" }),
|
|
507
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: (data.deletedAccountsCount ?? 0).toLocaleString() })
|
|
508
|
+
] })
|
|
509
|
+
] }),
|
|
510
|
+
/* @__PURE__ */ jsxs(Container, { className: "p-6", children: [
|
|
511
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-4 mb-4", children: [
|
|
512
|
+
/* @__PURE__ */ jsx(Heading, { level: "h3", children: "Customers over time" }),
|
|
513
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
3497
514
|
/* @__PURE__ */ jsx(
|
|
3498
|
-
|
|
515
|
+
Label,
|
|
3499
516
|
{
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
children: /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 gap-2", children: quickPulseMetrics.map((metric) => /* @__PURE__ */ jsxs(
|
|
3504
|
-
"div",
|
|
3505
|
-
{
|
|
3506
|
-
className: `rounded-lg border border-ui-border-base bg-ui-bg-base px-2 py-2 shadow-sm ${metric.accentClassName}`.trim(),
|
|
3507
|
-
children: [
|
|
3508
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-[10px] font-medium uppercase tracking-[0.14em]", children: metric.label }),
|
|
3509
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-base mt-0.5 text-sm font-semibold tracking-tight", children: metric.value }),
|
|
3510
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted mt-0.5 text-[9px] leading-snug", children: metric.helper })
|
|
3511
|
-
]
|
|
3512
|
-
},
|
|
3513
|
-
metric.label
|
|
3514
|
-
)) })
|
|
517
|
+
htmlFor: "customers-graph-period",
|
|
518
|
+
className: "text-ui-fg-muted text-sm",
|
|
519
|
+
children: "Range"
|
|
3515
520
|
}
|
|
3516
521
|
),
|
|
3517
522
|
/* @__PURE__ */ jsx(
|
|
3518
|
-
|
|
523
|
+
"select",
|
|
3519
524
|
{
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
/* @__PURE__ */ jsx(
|
|
3526
|
-
Label,
|
|
3527
|
-
{
|
|
3528
|
-
htmlFor: "products-top-seller-period",
|
|
3529
|
-
className: "shrink-0 text-ui-fg-muted text-xs font-medium",
|
|
3530
|
-
children: "Window"
|
|
3531
|
-
}
|
|
3532
|
-
),
|
|
3533
|
-
/* @__PURE__ */ jsx(
|
|
3534
|
-
"select",
|
|
3535
|
-
{
|
|
3536
|
-
id: "products-top-seller-period",
|
|
3537
|
-
value: topSellerPeriod,
|
|
3538
|
-
onChange: (event) => setTopSellerPeriod(event.target.value),
|
|
3539
|
-
className: SELECT_CLASS_NAME,
|
|
3540
|
-
children: TOP_SELLER_PERIODS.map((period) => /* @__PURE__ */ jsx("option", { value: period.value, children: period.label }, period.value))
|
|
3541
|
-
}
|
|
3542
|
-
)
|
|
3543
|
-
] }),
|
|
3544
|
-
children: /* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", className: "min-w-0 overflow-x-auto", children: /* @__PURE__ */ jsx("div", { className: "h-[212px] min-w-[280px] w-full sm:h-[228px]", children: bestSellersTrendLoading ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "Loading…" }) }) : bestSellersTrendError ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center px-2", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger text-center text-xs", children: bestSellersTrendError }) }) : bestSellersTrendSeries.length === 0 ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "No product sales for this range." }) }) : /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", minWidth: 0, children: /* @__PURE__ */ jsxs(
|
|
3545
|
-
ComposedChart,
|
|
3546
|
-
{
|
|
3547
|
-
data: bestSellersTrendSeries,
|
|
3548
|
-
margin: { left: 0, right: 8, top: 6, bottom: 2 },
|
|
3549
|
-
children: [
|
|
3550
|
-
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs(
|
|
3551
|
-
"linearGradient",
|
|
3552
|
-
{
|
|
3553
|
-
id: "bestSellersRevenueArea",
|
|
3554
|
-
x1: "0",
|
|
3555
|
-
y1: "0",
|
|
3556
|
-
x2: "0",
|
|
3557
|
-
y2: "1",
|
|
3558
|
-
children: [
|
|
3559
|
-
/* @__PURE__ */ jsx(
|
|
3560
|
-
"stop",
|
|
3561
|
-
{
|
|
3562
|
-
offset: "0%",
|
|
3563
|
-
stopColor: PRODUCT_CHART_COLORS.revenue,
|
|
3564
|
-
stopOpacity: 0.22
|
|
3565
|
-
}
|
|
3566
|
-
),
|
|
3567
|
-
/* @__PURE__ */ jsx(
|
|
3568
|
-
"stop",
|
|
3569
|
-
{
|
|
3570
|
-
offset: "100%",
|
|
3571
|
-
stopColor: PRODUCT_CHART_COLORS.revenue,
|
|
3572
|
-
stopOpacity: 0
|
|
3573
|
-
}
|
|
3574
|
-
)
|
|
3575
|
-
]
|
|
3576
|
-
}
|
|
3577
|
-
) }),
|
|
3578
|
-
/* @__PURE__ */ jsx(
|
|
3579
|
-
CartesianGrid,
|
|
3580
|
-
{
|
|
3581
|
-
strokeDasharray: "3 3",
|
|
3582
|
-
vertical: false,
|
|
3583
|
-
stroke: "rgba(148,163,184,0.12)"
|
|
3584
|
-
}
|
|
3585
|
-
),
|
|
3586
|
-
/* @__PURE__ */ jsx(
|
|
3587
|
-
XAxis,
|
|
3588
|
-
{
|
|
3589
|
-
dataKey: "date",
|
|
3590
|
-
tick: CHART_AXIS_TICK_SM,
|
|
3591
|
-
tickFormatter: (value) => formatChartLabel(String(value)),
|
|
3592
|
-
tickLine: false,
|
|
3593
|
-
axisLine: { stroke: CHART_AXIS_LINE }
|
|
3594
|
-
}
|
|
3595
|
-
),
|
|
3596
|
-
/* @__PURE__ */ jsx(
|
|
3597
|
-
YAxis,
|
|
3598
|
-
{
|
|
3599
|
-
yAxisId: "units",
|
|
3600
|
-
tick: CHART_AXIS_TICK_SM,
|
|
3601
|
-
tickFormatter: (value) => formatShortNumber(Number(value)),
|
|
3602
|
-
width: 36,
|
|
3603
|
-
tickLine: false,
|
|
3604
|
-
axisLine: { stroke: CHART_AXIS_LINE },
|
|
3605
|
-
allowDecimals: false
|
|
3606
|
-
}
|
|
3607
|
-
),
|
|
3608
|
-
/* @__PURE__ */ jsx(
|
|
3609
|
-
YAxis,
|
|
3610
|
-
{
|
|
3611
|
-
yAxisId: "revenue",
|
|
3612
|
-
orientation: "right",
|
|
3613
|
-
tick: CHART_AXIS_TICK_SM,
|
|
3614
|
-
tickFormatter: (value) => formatCompactCurrency(Number(value)),
|
|
3615
|
-
width: 44,
|
|
3616
|
-
tickLine: false,
|
|
3617
|
-
axisLine: { stroke: CHART_AXIS_LINE }
|
|
3618
|
-
}
|
|
3619
|
-
),
|
|
3620
|
-
/* @__PURE__ */ jsx(
|
|
3621
|
-
Tooltip,
|
|
3622
|
-
{
|
|
3623
|
-
content: (tooltipProps) => /* @__PURE__ */ jsx(
|
|
3624
|
-
MiniTrendTooltip,
|
|
3625
|
-
{
|
|
3626
|
-
...tooltipProps,
|
|
3627
|
-
productHeadline: bestSellerTrendProductTitle,
|
|
3628
|
-
hideViewsRow: true
|
|
3629
|
-
}
|
|
3630
|
-
)
|
|
3631
|
-
}
|
|
3632
|
-
),
|
|
3633
|
-
/* @__PURE__ */ jsx(
|
|
3634
|
-
Area,
|
|
3635
|
-
{
|
|
3636
|
-
yAxisId: "revenue",
|
|
3637
|
-
type: "natural",
|
|
3638
|
-
dataKey: "revenue",
|
|
3639
|
-
name: "Revenue",
|
|
3640
|
-
stroke: "transparent",
|
|
3641
|
-
fill: "url(#bestSellersRevenueArea)",
|
|
3642
|
-
isAnimationActive: false
|
|
3643
|
-
}
|
|
3644
|
-
),
|
|
3645
|
-
/* @__PURE__ */ jsx(
|
|
3646
|
-
Line,
|
|
3647
|
-
{
|
|
3648
|
-
yAxisId: "revenue",
|
|
3649
|
-
type: "natural",
|
|
3650
|
-
dataKey: "revenue",
|
|
3651
|
-
name: "Revenue",
|
|
3652
|
-
stroke: PRODUCT_CHART_COLORS.revenue,
|
|
3653
|
-
strokeWidth: 2,
|
|
3654
|
-
dot: false,
|
|
3655
|
-
activeDot: { r: 4, fill: PRODUCT_CHART_COLORS.revenue },
|
|
3656
|
-
isAnimationActive: false
|
|
3657
|
-
}
|
|
3658
|
-
),
|
|
3659
|
-
/* @__PURE__ */ jsx(
|
|
3660
|
-
Line,
|
|
3661
|
-
{
|
|
3662
|
-
yAxisId: "units",
|
|
3663
|
-
type: "natural",
|
|
3664
|
-
dataKey: "units_sold",
|
|
3665
|
-
name: "Units sold",
|
|
3666
|
-
stroke: PRODUCT_CHART_COLORS.units,
|
|
3667
|
-
strokeWidth: 2,
|
|
3668
|
-
dot: false,
|
|
3669
|
-
activeDot: { r: 4, fill: PRODUCT_CHART_COLORS.units },
|
|
3670
|
-
isAnimationActive: false
|
|
3671
|
-
}
|
|
3672
|
-
)
|
|
3673
|
-
]
|
|
3674
|
-
}
|
|
3675
|
-
) }) }) })
|
|
525
|
+
id: "customers-graph-period",
|
|
526
|
+
value: graphPeriod,
|
|
527
|
+
onChange: (e) => setGraphPeriod(e.target.value),
|
|
528
|
+
className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive",
|
|
529
|
+
children: GRAPH_PERIODS.map((p) => /* @__PURE__ */ jsx("option", { value: p.value, children: p.label }, p.value))
|
|
3676
530
|
}
|
|
3677
531
|
)
|
|
3678
532
|
] })
|
|
3679
533
|
] }),
|
|
3680
|
-
/* @__PURE__ */
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { className: TABLE_HEAD_CELL_NOWRAP, children: "Product" }),
|
|
3691
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { className: TABLE_HEAD_CELL_NOWRAP, children: "Units" }),
|
|
3692
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { className: TABLE_HEAD_CELL_NOWRAP, children: "Orders" }),
|
|
3693
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { className: TABLE_HEAD_CELL_NOWRAP, children: "Revenue" })
|
|
3694
|
-
] }) }),
|
|
3695
|
-
/* @__PURE__ */ jsxs(Table.Body, { children: [
|
|
3696
|
-
topSellersError ? /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
3697
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger text-xs", children: topSellersError }) }),
|
|
3698
|
-
/* @__PURE__ */ jsx(Table.Cell, {}),
|
|
3699
|
-
/* @__PURE__ */ jsx(Table.Cell, {}),
|
|
3700
|
-
/* @__PURE__ */ jsx(Table.Cell, {})
|
|
3701
|
-
] }) : null,
|
|
3702
|
-
!topSellersError ? topSellersByUnits.slice(0, 8).map((product) => {
|
|
3703
|
-
var _a2;
|
|
3704
|
-
return /* @__PURE__ */ jsxs(
|
|
3705
|
-
Table.Row,
|
|
3706
|
-
{
|
|
3707
|
-
className: product.product_id === ((_a2 = topSellersByUnits[0]) == null ? void 0 : _a2.product_id) ? "bg-emerald-500/5" : void 0,
|
|
3708
|
-
children: [
|
|
3709
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: product.product_title }),
|
|
3710
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: product.units_sold.toLocaleString() }),
|
|
3711
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: product.order_count.toLocaleString() }),
|
|
3712
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: formatCurrency(product.revenue) })
|
|
3713
|
-
]
|
|
3714
|
-
},
|
|
3715
|
-
product.product_id
|
|
3716
|
-
);
|
|
3717
|
-
}) : null,
|
|
3718
|
-
!topSellersLoading && !topSellersError && (((_i = topSellers == null ? void 0 : topSellers.products) == null ? void 0 : _i.length) ?? 0) === 0 ? /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
3719
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "No best seller data yet." }) }),
|
|
3720
|
-
/* @__PURE__ */ jsx(Table.Cell, {}),
|
|
3721
|
-
/* @__PURE__ */ jsx(Table.Cell, {}),
|
|
3722
|
-
/* @__PURE__ */ jsx(Table.Cell, {})
|
|
3723
|
-
] }) : null
|
|
3724
|
-
] })
|
|
3725
|
-
] }) }) })
|
|
3726
|
-
}
|
|
3727
|
-
),
|
|
3728
|
-
/* @__PURE__ */ jsx(
|
|
3729
|
-
AnalyticsSection,
|
|
3730
|
-
{
|
|
3731
|
-
variant: "atlas",
|
|
3732
|
-
className: "min-w-0 md:col-span-1 xl:col-span-1",
|
|
3733
|
-
title: "Most viewed products",
|
|
3734
|
-
description: mostViewedTrendProductTitle ? `Views over time for “${mostViewedTrendProductTitle}” (top of the list for your summary period; buckets follow period: today / 7d → week, 30d → month, 90d / all → year).` : "Views over time for the most-viewed product in your summary period (buckets: today / 7d → week, 30d → month, 90d / all → year).",
|
|
3735
|
-
children: performanceLoading ? /* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsx("div", { className: "flex h-[212px] items-center justify-center sm:h-[228px]", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "Loading…" }) }) }) : performanceError ? /* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsx("div", { className: "flex h-[212px] items-center justify-center px-2 sm:h-[228px]", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger text-center text-xs", children: performanceError }) }) }) : !(performance == null ? void 0 : performance.productViewsConnected) ? /* @__PURE__ */ jsx("div", { className: "min-h-[212px] sm:min-h-[228px]", children: /* @__PURE__ */ jsx(
|
|
3736
|
-
EmptyAnalyticsPanel,
|
|
3737
|
-
{
|
|
3738
|
-
title: "Views unavailable",
|
|
3739
|
-
description: "Product view tracking is not available in this environment."
|
|
3740
|
-
}
|
|
3741
|
-
) }) : ((performance == null ? void 0 : performance.topViewedProducts) ?? []).length === 0 ? /* @__PURE__ */ jsx("div", { className: "min-h-[212px] sm:min-h-[228px]", children: /* @__PURE__ */ jsx(
|
|
3742
|
-
EmptyAnalyticsPanel,
|
|
3743
|
-
{
|
|
3744
|
-
title: "No views",
|
|
3745
|
-
description: "No product views found for this summary period."
|
|
3746
|
-
}
|
|
3747
|
-
) }) : /* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", className: "min-w-0 overflow-x-auto", children: /* @__PURE__ */ jsx("div", { className: "h-[212px] min-w-[280px] w-full sm:h-[228px]", children: mostViewedTrendLoading ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "Loading chart…" }) }) : mostViewedTrendError ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center px-2", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger text-center text-xs", children: mostViewedTrendError }) }) : mostViewedTrendSeries.length === 0 ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "No view data in this range." }) }) : /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", minWidth: 0, children: /* @__PURE__ */ jsxs(
|
|
3748
|
-
ComposedChart,
|
|
3749
|
-
{
|
|
3750
|
-
data: mostViewedTrendSeries,
|
|
3751
|
-
margin: { left: 0, right: 8, top: 6, bottom: 2 },
|
|
3752
|
-
children: [
|
|
3753
|
-
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs(
|
|
3754
|
-
"linearGradient",
|
|
3755
|
-
{
|
|
3756
|
-
id: "mostViewedViewsArea",
|
|
3757
|
-
x1: "0",
|
|
3758
|
-
y1: "0",
|
|
3759
|
-
x2: "0",
|
|
3760
|
-
y2: "1",
|
|
3761
|
-
children: [
|
|
3762
|
-
/* @__PURE__ */ jsx(
|
|
3763
|
-
"stop",
|
|
3764
|
-
{
|
|
3765
|
-
offset: "0%",
|
|
3766
|
-
stopColor: PRODUCT_CHART_COLORS.views,
|
|
3767
|
-
stopOpacity: 0.22
|
|
3768
|
-
}
|
|
3769
|
-
),
|
|
3770
|
-
/* @__PURE__ */ jsx(
|
|
3771
|
-
"stop",
|
|
3772
|
-
{
|
|
3773
|
-
offset: "100%",
|
|
3774
|
-
stopColor: PRODUCT_CHART_COLORS.views,
|
|
3775
|
-
stopOpacity: 0
|
|
3776
|
-
}
|
|
3777
|
-
)
|
|
3778
|
-
]
|
|
3779
|
-
}
|
|
3780
|
-
) }),
|
|
3781
|
-
/* @__PURE__ */ jsx(
|
|
3782
|
-
CartesianGrid,
|
|
3783
|
-
{
|
|
3784
|
-
strokeDasharray: "3 3",
|
|
3785
|
-
vertical: false,
|
|
3786
|
-
stroke: "rgba(148,163,184,0.12)"
|
|
3787
|
-
}
|
|
3788
|
-
),
|
|
3789
|
-
/* @__PURE__ */ jsx(
|
|
3790
|
-
XAxis,
|
|
3791
|
-
{
|
|
3792
|
-
dataKey: "date",
|
|
3793
|
-
tick: CHART_AXIS_TICK_SM,
|
|
3794
|
-
tickFormatter: (value) => formatChartLabel(String(value)),
|
|
3795
|
-
tickLine: false,
|
|
3796
|
-
axisLine: { stroke: CHART_AXIS_LINE }
|
|
3797
|
-
}
|
|
3798
|
-
),
|
|
3799
|
-
/* @__PURE__ */ jsx(
|
|
3800
|
-
YAxis,
|
|
3801
|
-
{
|
|
3802
|
-
tick: CHART_AXIS_TICK_SM,
|
|
3803
|
-
tickFormatter: (value) => formatShortNumber(Number(value)),
|
|
3804
|
-
width: 36,
|
|
3805
|
-
tickLine: false,
|
|
3806
|
-
axisLine: { stroke: CHART_AXIS_LINE },
|
|
3807
|
-
allowDecimals: false
|
|
3808
|
-
}
|
|
3809
|
-
),
|
|
3810
|
-
/* @__PURE__ */ jsx(
|
|
3811
|
-
Tooltip,
|
|
3812
|
-
{
|
|
3813
|
-
content: (tooltipProps) => /* @__PURE__ */ jsx(
|
|
3814
|
-
MiniTrendTooltip,
|
|
3815
|
-
{
|
|
3816
|
-
...tooltipProps,
|
|
3817
|
-
productHeadline: mostViewedTrendProductTitle,
|
|
3818
|
-
hideUnitsRow: true,
|
|
3819
|
-
hideRevenueRow: true
|
|
3820
|
-
}
|
|
3821
|
-
)
|
|
3822
|
-
}
|
|
3823
|
-
),
|
|
3824
|
-
/* @__PURE__ */ jsx(
|
|
3825
|
-
Area,
|
|
3826
|
-
{
|
|
3827
|
-
type: "natural",
|
|
3828
|
-
dataKey: "views",
|
|
3829
|
-
name: "Views",
|
|
3830
|
-
stroke: "transparent",
|
|
3831
|
-
fill: "url(#mostViewedViewsArea)",
|
|
3832
|
-
isAnimationActive: false
|
|
3833
|
-
}
|
|
3834
|
-
),
|
|
3835
|
-
/* @__PURE__ */ jsx(
|
|
3836
|
-
Line,
|
|
3837
|
-
{
|
|
3838
|
-
type: "natural",
|
|
3839
|
-
dataKey: "views",
|
|
3840
|
-
name: "Views",
|
|
3841
|
-
stroke: PRODUCT_CHART_COLORS.views,
|
|
3842
|
-
strokeWidth: 2,
|
|
3843
|
-
dot: false,
|
|
3844
|
-
activeDot: { r: 4, fill: PRODUCT_CHART_COLORS.views },
|
|
3845
|
-
isAnimationActive: false
|
|
3846
|
-
}
|
|
3847
|
-
)
|
|
3848
|
-
]
|
|
3849
|
-
}
|
|
3850
|
-
) }) }) })
|
|
3851
|
-
}
|
|
3852
|
-
),
|
|
3853
|
-
/* @__PURE__ */ jsx(
|
|
3854
|
-
AnalyticsSection,
|
|
3855
|
-
{
|
|
3856
|
-
variant: "atlas",
|
|
3857
|
-
className: "min-w-0 md:col-span-2 xl:col-span-1",
|
|
3858
|
-
title: "View-to-sales opportunities",
|
|
3859
|
-
description: "Products with attention but weaker unit conversion.",
|
|
3860
|
-
children: /* @__PURE__ */ jsx("div", { className: "min-h-[212px] min-w-0 sm:min-h-[228px]", children: /* @__PURE__ */ jsx(AnalyticsTableSurface, { className: "shadow-sm", children: /* @__PURE__ */ jsxs(Table, { className: OPPORTUNITIES_TABLE_CLASS, children: [
|
|
3861
|
-
/* @__PURE__ */ jsx(Table.Header, { children: /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
3862
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { className: TABLE_HEAD_CELL_NOWRAP, children: "Product" }),
|
|
3863
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { className: TABLE_HEAD_CELL_NOWRAP, children: "Views" }),
|
|
3864
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { className: TABLE_HEAD_CELL_NOWRAP, children: "Units" }),
|
|
3865
|
-
/* @__PURE__ */ jsx(Table.HeaderCell, { className: TABLE_HEAD_CELL_NOWRAP, children: "Views / unit" })
|
|
3866
|
-
] }) }),
|
|
3867
|
-
/* @__PURE__ */ jsxs(Table.Body, { children: [
|
|
3868
|
-
((performance == null ? void 0 : performance.viewOpportunities) ?? []).slice(0, 8).map((product) => /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
3869
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: product.product_title }),
|
|
3870
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: product.total_views.toLocaleString() }),
|
|
3871
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: product.units_sold.toLocaleString() }),
|
|
3872
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: formatRatio(product.views_per_unit) })
|
|
3873
|
-
] }, product.product_id)),
|
|
3874
|
-
!performanceLoading && !performanceError && (((_j = performance == null ? void 0 : performance.viewOpportunities) == null ? void 0 : _j.length) ?? 0) === 0 ? /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
3875
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "No product view opportunities yet." }) }),
|
|
3876
|
-
/* @__PURE__ */ jsx(Table.Cell, {}),
|
|
3877
|
-
/* @__PURE__ */ jsx(Table.Cell, {}),
|
|
3878
|
-
/* @__PURE__ */ jsx(Table.Cell, {})
|
|
3879
|
-
] }) : null
|
|
3880
|
-
] })
|
|
3881
|
-
] }) }) })
|
|
3882
|
-
}
|
|
3883
|
-
)
|
|
3884
|
-
] }),
|
|
3885
|
-
/* @__PURE__ */ jsx(
|
|
3886
|
-
AnalyticsSection,
|
|
534
|
+
/* @__PURE__ */ jsx("div", { className: "h-72", children: graphLoading ? /* @__PURE__ */ jsx(
|
|
535
|
+
"div",
|
|
536
|
+
{
|
|
537
|
+
className: "flex items-center justify-center h-full",
|
|
538
|
+
role: "status",
|
|
539
|
+
"aria-label": "Loading customers over time",
|
|
540
|
+
children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted", children: "Loading chart…" })
|
|
541
|
+
}
|
|
542
|
+
) : graphError ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger", children: graphError }) }) : /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
|
|
543
|
+
LineChart,
|
|
3887
544
|
{
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
description: "Each point is a product (top viewed in this period). Requires product view tracking.",
|
|
3892
|
-
children: /* @__PURE__ */ jsx(AnalyticsChartSurface, { variant: "atlas", children: /* @__PURE__ */ jsx("div", { className: "h-[220px] w-full sm:h-[248px]", children: performanceLoading ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "Loading scatter…" }) }) : performanceError || !performance ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center px-2", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-danger text-center text-xs", children: performanceError ?? "Failed to load product performance" }) }) : !performance.productViewsConnected ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "Product view tracking is not available in this environment." }) }) : viewsVsUnitsScatterData.length === 0 ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-xs", children: "No products with views or sales in this range." }) }) : /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(ScatterChart, { margin: { top: 12, right: 16, bottom: 8, left: 8 }, children: [
|
|
3893
|
-
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("radialGradient", { id: "productScatterGlow", cx: "50%", cy: "50%", r: "50%", children: [
|
|
3894
|
-
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: "#E879F9", stopOpacity: 0.95 }),
|
|
3895
|
-
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: "#6366F1", stopOpacity: 0.65 })
|
|
3896
|
-
] }) }),
|
|
545
|
+
data: series,
|
|
546
|
+
margin: { top: 8, right: 8, left: 8, bottom: 8 },
|
|
547
|
+
children: [
|
|
3897
548
|
/* @__PURE__ */ jsx(
|
|
3898
549
|
CartesianGrid,
|
|
3899
550
|
{
|
|
3900
551
|
strokeDasharray: "3 3",
|
|
3901
|
-
|
|
552
|
+
className: "stroke-ui-border-base"
|
|
3902
553
|
}
|
|
3903
554
|
),
|
|
3904
555
|
/* @__PURE__ */ jsx(
|
|
3905
556
|
XAxis,
|
|
3906
557
|
{
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
label: {
|
|
3915
|
-
value: "Views",
|
|
3916
|
-
position: "insideBottom",
|
|
3917
|
-
offset: -4,
|
|
3918
|
-
fontSize: 10,
|
|
3919
|
-
fill: "#9ca3af"
|
|
558
|
+
dataKey: "date",
|
|
559
|
+
tick: { fontSize: 12 },
|
|
560
|
+
tickFormatter: (v, index) => {
|
|
561
|
+
const row = series[index];
|
|
562
|
+
if (row == null ? void 0 : row.label) return row.label;
|
|
563
|
+
const d = new Date(v);
|
|
564
|
+
return `${d.getUTCMonth() + 1}/${d.getUTCDate()}`;
|
|
3920
565
|
}
|
|
3921
566
|
}
|
|
3922
567
|
),
|
|
3923
568
|
/* @__PURE__ */ jsx(
|
|
3924
569
|
YAxis,
|
|
3925
570
|
{
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
tick: CHART_AXIS_TICK_SM,
|
|
3930
|
-
stroke: CHART_AXIS_LINE,
|
|
3931
|
-
tickLine: { stroke: CHART_AXIS_LINE },
|
|
3932
|
-
allowDecimals: false,
|
|
3933
|
-
label: {
|
|
3934
|
-
value: "Units sold",
|
|
3935
|
-
angle: -90,
|
|
3936
|
-
position: "insideLeft",
|
|
3937
|
-
fontSize: 10,
|
|
3938
|
-
fill: "#9ca3af"
|
|
3939
|
-
}
|
|
571
|
+
tick: { fontSize: 12 },
|
|
572
|
+
tickFormatter: (v) => String(Math.floor(Number(v))),
|
|
573
|
+
allowDecimals: false
|
|
3940
574
|
}
|
|
3941
575
|
),
|
|
576
|
+
/* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(CustomersOverTimeTooltip, {}) }),
|
|
577
|
+
/* @__PURE__ */ jsx(Legend, {}),
|
|
3942
578
|
/* @__PURE__ */ jsx(
|
|
3943
|
-
|
|
579
|
+
Line,
|
|
3944
580
|
{
|
|
3945
|
-
|
|
3946
|
-
|
|
581
|
+
type: "monotone",
|
|
582
|
+
dataKey: "registered_count",
|
|
583
|
+
name: "Registered",
|
|
584
|
+
stroke: REGISTERED_COLOR,
|
|
585
|
+
strokeWidth: 2,
|
|
586
|
+
dot: { r: 3 }
|
|
3947
587
|
}
|
|
3948
588
|
),
|
|
3949
589
|
/* @__PURE__ */ jsx(
|
|
3950
|
-
|
|
590
|
+
Line,
|
|
3951
591
|
{
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
592
|
+
type: "monotone",
|
|
593
|
+
dataKey: "guest_count",
|
|
594
|
+
name: "Guest",
|
|
595
|
+
stroke: GUEST_COLOR,
|
|
596
|
+
strokeWidth: 2,
|
|
597
|
+
dot: { r: 3 }
|
|
3955
598
|
}
|
|
3956
599
|
)
|
|
3957
|
-
]
|
|
600
|
+
]
|
|
3958
601
|
}
|
|
3959
|
-
)
|
|
602
|
+
) }) })
|
|
3960
603
|
] })
|
|
3961
|
-
] })
|
|
604
|
+
] });
|
|
3962
605
|
}
|
|
3963
606
|
const ANALYTICS_MODULES = [
|
|
3964
607
|
{ id: "orders", label: "Orders" },
|
|
3965
|
-
{ id: "customers", label: "Customers" }
|
|
3966
|
-
{ id: "products", label: "Products" }
|
|
608
|
+
{ id: "customers", label: "Customers" }
|
|
3967
609
|
];
|
|
3968
610
|
const AnalyticsPage = () => {
|
|
3969
611
|
const [activeModule, setActiveModule] = useState("orders");
|
|
3970
|
-
return /* @__PURE__ */ jsx("div", { className: "flex h-full bg-ui-bg-
|
|
3971
|
-
"
|
|
3972
|
-
{
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
"aria-label": "Analytics modules",
|
|
3986
|
-
children: ANALYTICS_MODULES.map((m) => {
|
|
3987
|
-
const active = activeModule === m.id;
|
|
3988
|
-
return /* @__PURE__ */ jsx(
|
|
3989
|
-
"button",
|
|
3990
|
-
{
|
|
3991
|
-
type: "button",
|
|
3992
|
-
role: "tab",
|
|
3993
|
-
"aria-selected": active,
|
|
3994
|
-
onClick: () => setActiveModule(m.id),
|
|
3995
|
-
className: `rounded-md px-3 py-1.5 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ui-fg-interactive focus-visible:ring-offset-2 focus-visible:ring-offset-ui-bg-base ${active ? "bg-ui-bg-base text-ui-fg-base shadow-sm" : "text-ui-fg-muted hover:bg-ui-bg-base/60 hover:text-ui-fg-base"}`.trim(),
|
|
3996
|
-
children: m.label
|
|
3997
|
-
},
|
|
3998
|
-
m.id
|
|
3999
|
-
);
|
|
4000
|
-
})
|
|
4001
|
-
}
|
|
4002
|
-
)
|
|
4003
|
-
] }) }),
|
|
4004
|
-
/* @__PURE__ */ jsxs("div", { className: "min-w-0 w-full", children: [
|
|
4005
|
-
activeModule === "orders" && /* @__PURE__ */ jsx(OrdersDashboard, {}),
|
|
4006
|
-
activeModule === "customers" && /* @__PURE__ */ jsx(CustomersDashboard, {}),
|
|
4007
|
-
activeModule === "products" && /* @__PURE__ */ jsx(ProductsDashboard, {})
|
|
4008
|
-
] })
|
|
4009
|
-
]
|
|
4010
|
-
}
|
|
4011
|
-
) }) });
|
|
612
|
+
return /* @__PURE__ */ jsx("div", { className: "flex h-full bg-ui-bg-base", children: /* @__PURE__ */ jsx("main", { className: "flex-1 overflow-auto", children: /* @__PURE__ */ jsx(Container, { className: "divide-y p-0", children: /* @__PURE__ */ jsxs("div", { className: "py-6 px-6", children: [
|
|
613
|
+
/* @__PURE__ */ jsx(Heading, { level: "h1", className: "mb-4", children: "Analytics" }),
|
|
614
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-2 mb-6", children: ANALYTICS_MODULES.map((m) => /* @__PURE__ */ jsx(
|
|
615
|
+
Button,
|
|
616
|
+
{
|
|
617
|
+
variant: activeModule === m.id ? "secondary" : "transparent",
|
|
618
|
+
size: "small",
|
|
619
|
+
onClick: () => setActiveModule(m.id),
|
|
620
|
+
children: m.label
|
|
621
|
+
},
|
|
622
|
+
m.id
|
|
623
|
+
)) }),
|
|
624
|
+
activeModule === "orders" && /* @__PURE__ */ jsx(OrdersDashboard, {}),
|
|
625
|
+
activeModule === "customers" && /* @__PURE__ */ jsx(CustomersDashboard, {})
|
|
626
|
+
] }) }) }) });
|
|
4012
627
|
};
|
|
4013
628
|
const config = defineRouteConfig({
|
|
4014
629
|
label: "Analytics",
|