@open-mercato/core 0.6.4-develop.4121.1.0d7f20d229 → 0.6.4-develop.4133.1.48fc6c8f7b

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.
Files changed (44) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/modules/dashboards/api/widgets/data/batch/route.js +137 -0
  3. package/dist/modules/dashboards/api/widgets/data/batch/route.js.map +7 -0
  4. package/dist/modules/dashboards/api/widgets/data/route.js +1 -75
  5. package/dist/modules/dashboards/api/widgets/data/route.js.map +2 -2
  6. package/dist/modules/dashboards/api/widgets/data/schema.js +85 -0
  7. package/dist/modules/dashboards/api/widgets/data/schema.js.map +7 -0
  8. package/dist/modules/dashboards/lib/widgetDataBatch.js +49 -0
  9. package/dist/modules/dashboards/lib/widgetDataBatch.js.map +7 -0
  10. package/dist/modules/dashboards/widgets/dashboard/aov-kpi/widget.client.js +6 -14
  11. package/dist/modules/dashboards/widgets/dashboard/aov-kpi/widget.client.js.map +2 -2
  12. package/dist/modules/dashboards/widgets/dashboard/new-customers-kpi/widget.client.js +6 -14
  13. package/dist/modules/dashboards/widgets/dashboard/new-customers-kpi/widget.client.js.map +2 -2
  14. package/dist/modules/dashboards/widgets/dashboard/orders-by-status/widget.client.js +6 -14
  15. package/dist/modules/dashboards/widgets/dashboard/orders-by-status/widget.client.js.map +2 -2
  16. package/dist/modules/dashboards/widgets/dashboard/orders-kpi/widget.client.js +6 -14
  17. package/dist/modules/dashboards/widgets/dashboard/orders-kpi/widget.client.js.map +2 -2
  18. package/dist/modules/dashboards/widgets/dashboard/pipeline-summary/widget.client.js +6 -14
  19. package/dist/modules/dashboards/widgets/dashboard/pipeline-summary/widget.client.js.map +2 -2
  20. package/dist/modules/dashboards/widgets/dashboard/revenue-kpi/widget.client.js +6 -14
  21. package/dist/modules/dashboards/widgets/dashboard/revenue-kpi/widget.client.js.map +2 -2
  22. package/dist/modules/dashboards/widgets/dashboard/revenue-trend/widget.client.js +6 -14
  23. package/dist/modules/dashboards/widgets/dashboard/revenue-trend/widget.client.js.map +2 -2
  24. package/dist/modules/dashboards/widgets/dashboard/sales-by-region/widget.client.js +6 -14
  25. package/dist/modules/dashboards/widgets/dashboard/sales-by-region/widget.client.js.map +2 -2
  26. package/dist/modules/dashboards/widgets/dashboard/top-customers/widget.client.js +6 -14
  27. package/dist/modules/dashboards/widgets/dashboard/top-customers/widget.client.js.map +2 -2
  28. package/dist/modules/dashboards/widgets/dashboard/top-products/widget.client.js +6 -14
  29. package/dist/modules/dashboards/widgets/dashboard/top-products/widget.client.js.map +2 -2
  30. package/package.json +7 -7
  31. package/src/modules/dashboards/api/widgets/data/batch/route.ts +168 -0
  32. package/src/modules/dashboards/api/widgets/data/route.ts +1 -90
  33. package/src/modules/dashboards/api/widgets/data/schema.ts +90 -0
  34. package/src/modules/dashboards/lib/widgetDataBatch.ts +89 -0
  35. package/src/modules/dashboards/widgets/dashboard/aov-kpi/widget.client.tsx +6 -16
  36. package/src/modules/dashboards/widgets/dashboard/new-customers-kpi/widget.client.tsx +6 -16
  37. package/src/modules/dashboards/widgets/dashboard/orders-by-status/widget.client.tsx +6 -16
  38. package/src/modules/dashboards/widgets/dashboard/orders-kpi/widget.client.tsx +6 -16
  39. package/src/modules/dashboards/widgets/dashboard/pipeline-summary/widget.client.tsx +6 -16
  40. package/src/modules/dashboards/widgets/dashboard/revenue-kpi/widget.client.tsx +6 -16
  41. package/src/modules/dashboards/widgets/dashboard/revenue-trend/widget.client.tsx +6 -16
  42. package/src/modules/dashboards/widgets/dashboard/sales-by-region/widget.client.tsx +6 -16
  43. package/src/modules/dashboards/widgets/dashboard/top-customers/widget.client.tsx +6 -16
  44. package/src/modules/dashboards/widgets/dashboard/top-products/widget.client.tsx +6 -16
@@ -2,7 +2,7 @@
2
2
 
3
3
  import * as React from 'react'
4
4
  import type { DashboardWidgetComponentProps } from '@open-mercato/shared/modules/dashboard/widgets'
5
- import { apiCall } from '@open-mercato/ui/backend/utils/apiCall'
5
+ import { useWidgetData, type WidgetDataFetcher } from '@open-mercato/ui/backend/dashboard/widgetData'
6
6
  import { useT } from '@open-mercato/shared/lib/i18n/context'
7
7
  import { TopNTable, type TopNTableColumn } from '@open-mercato/ui/backend/charts'
8
8
  import { DateRangeSelect, type DateRangePreset } from '@open-mercato/ui/backend/date-range'
@@ -17,7 +17,7 @@ type CustomerRow = {
17
17
  revenue: number
18
18
  }
19
19
 
20
- async function fetchTopCustomersData(settings: TopCustomersSettings): Promise<WidgetDataResponse> {
20
+ async function fetchTopCustomersData(settings: TopCustomersSettings, fetchWidgetData: WidgetDataFetcher): Promise<WidgetDataResponse> {
21
21
  const body = {
22
22
  entityType: 'sales:orders',
23
23
  metric: {
@@ -35,18 +35,7 @@ async function fetchTopCustomersData(settings: TopCustomersSettings): Promise<Wi
35
35
  },
36
36
  }
37
37
 
38
- const call = await apiCall<WidgetDataResponse>('/api/dashboards/widgets/data', {
39
- method: 'POST',
40
- headers: { 'Content-Type': 'application/json' },
41
- body: JSON.stringify(body),
42
- })
43
-
44
- if (!call.ok) {
45
- const errorMsg = (call.result as Record<string, unknown>)?.error
46
- throw new Error(typeof errorMsg === 'string' ? errorMsg : 'Failed to fetch top customers data')
47
- }
48
-
49
- return call.result as WidgetDataResponse
38
+ return fetchWidgetData<WidgetDataResponse>(body)
50
39
  }
51
40
 
52
41
  function formatCustomerName(name: string | null, unknownLabel: string): string {
@@ -90,12 +79,13 @@ const TopCustomersWidget: React.FC<DashboardWidgetComponentProps<TopCustomersSet
90
79
  [t, unknownLabel],
91
80
  )
92
81
 
82
+ const fetchWidgetData = useWidgetData()
93
83
  const refresh = React.useCallback(async () => {
94
84
  onRefreshStateChange?.(true)
95
85
  setLoading(true)
96
86
  setError(null)
97
87
  try {
98
- const result = await fetchTopCustomersData(hydrated)
88
+ const result = await fetchTopCustomersData(hydrated, fetchWidgetData)
99
89
  const tableData: CustomerRow[] = result.data.map((item, index) => ({
100
90
  rank: index + 1,
101
91
  customerId: item.groupLabel || String(item.groupKey || t('dashboards.analytics.labels.unknown', 'Unknown')),
@@ -109,7 +99,7 @@ const TopCustomersWidget: React.FC<DashboardWidgetComponentProps<TopCustomersSet
109
99
  setLoading(false)
110
100
  onRefreshStateChange?.(false)
111
101
  }
112
- }, [hydrated, onRefreshStateChange, t])
102
+ }, [hydrated, fetchWidgetData, onRefreshStateChange, t])
113
103
 
114
104
  React.useEffect(() => {
115
105
  refresh().catch(() => {})
@@ -2,7 +2,7 @@
2
2
 
3
3
  import * as React from 'react'
4
4
  import type { DashboardWidgetComponentProps } from '@open-mercato/shared/modules/dashboard/widgets'
5
- import { apiCall } from '@open-mercato/ui/backend/utils/apiCall'
5
+ import { useWidgetData, type WidgetDataFetcher } from '@open-mercato/ui/backend/dashboard/widgetData'
6
6
  import { useT } from '@open-mercato/shared/lib/i18n/context'
7
7
  import { BarChart, type BarChartDataItem } from '@open-mercato/ui/backend/charts'
8
8
  import { DateRangeSelect, InlineDateRangeSelect, type DateRangePreset } from '@open-mercato/ui/backend/date-range'
@@ -18,7 +18,7 @@ import { DEFAULT_SETTINGS, hydrateSettings, type TopProductsSettings } from './c
18
18
  import type { WidgetDataResponse } from '../../../services/widgetDataService'
19
19
  import { formatCurrencyCompact } from '../../../lib/formatters'
20
20
 
21
- async function fetchTopProductsData(settings: TopProductsSettings): Promise<WidgetDataResponse> {
21
+ async function fetchTopProductsData(settings: TopProductsSettings, fetchWidgetData: WidgetDataFetcher): Promise<WidgetDataResponse> {
22
22
  const body = {
23
23
  entityType: 'sales:order_lines',
24
24
  metric: {
@@ -36,18 +36,7 @@ async function fetchTopProductsData(settings: TopProductsSettings): Promise<Widg
36
36
  },
37
37
  }
38
38
 
39
- const call = await apiCall<WidgetDataResponse>('/api/dashboards/widgets/data', {
40
- method: 'POST',
41
- headers: { 'Content-Type': 'application/json' },
42
- body: JSON.stringify(body),
43
- })
44
-
45
- if (!call.ok) {
46
- const errorMsg = (call.result as Record<string, unknown>)?.error
47
- throw new Error(typeof errorMsg === 'string' ? errorMsg : 'Failed to fetch top products data')
48
- }
49
-
50
- return call.result as WidgetDataResponse
39
+ return fetchWidgetData<WidgetDataResponse>(body)
51
40
  }
52
41
 
53
42
  function truncateLabel(
@@ -82,6 +71,7 @@ const TopProductsWidget: React.FC<DashboardWidgetComponentProps<TopProductsSetti
82
71
  const [error, setError] = React.useState<string | null>(null)
83
72
  const fetchingRef = React.useRef(false)
84
73
 
74
+ const fetchWidgetData = useWidgetData()
85
75
  const refresh = React.useCallback(async () => {
86
76
  if (fetchingRef.current) return
87
77
  fetchingRef.current = true
@@ -89,7 +79,7 @@ const TopProductsWidget: React.FC<DashboardWidgetComponentProps<TopProductsSetti
89
79
  setLoading(true)
90
80
  setError(null)
91
81
  try {
92
- const result = await fetchTopProductsData(hydrated)
82
+ const result = await fetchTopProductsData(hydrated, fetchWidgetData)
93
83
  const chartData = result.data.map((item, index) => ({
94
84
  name: truncateLabel(item.groupLabel ?? item.groupKey ?? `Product ${index + 1}`, t),
95
85
  Revenue: item.value ?? 0,
@@ -103,7 +93,7 @@ const TopProductsWidget: React.FC<DashboardWidgetComponentProps<TopProductsSetti
103
93
  onRefreshStateChange?.(false)
104
94
  fetchingRef.current = false
105
95
  }
106
- }, [hydrated, onRefreshStateChange, t])
96
+ }, [hydrated, fetchWidgetData, onRefreshStateChange, t])
107
97
 
108
98
  React.useEffect(() => {
109
99
  refresh().catch(() => {})