('revenue', {
- websiteId,
- startDate,
- endDate,
- currency,
- compare,
- });
-
- const metrics = useMemo(() => {
- if (!data) return [];
-
- const { sum, count, average, unique_count, arpu, comparison } = data.total;
-
- return [
- {
- value: sum,
- label: t(labels.total),
- change: comparison ? sum - comparison.sum : 0,
- formatValue: (n: number) => formatLongCurrency(n, currency),
- },
- {
- value: average,
- label: t(labels.aov),
- tooltip: (
- <>
- Average Order Value
- (Total Revenue / Orders)
- >
- ),
- change: comparison ? average - comparison.average : 0,
- formatValue: (n: number) => formatLongCurrency(n, currency),
- },
- {
- value: arpu,
- label: t(labels.arpu),
- tooltip: (
- <>
- Average Revenue Per User
- (Total Revenue / All Sessions)
- >
- ),
- change: comparison ? arpu - (comparison.arpu ?? 0) : 0,
- formatValue: (n: number) => formatLongCurrency(n, currency),
- },
- {
- value: count,
- label: t(labels.orders),
- change: comparison ? count - comparison.count : 0,
- formatValue: formatLongNumber,
- },
- {
- value: unique_count,
- label: t(labels.uniqueCustomers),
- change: comparison ? unique_count - comparison.unique_count : 0,
- formatValue: formatLongNumber,
- },
- ] as any;
- }, [
- data,
- currency,
- t,
- labels.total,
- labels.aov,
- labels.arpu,
- labels.orders,
- labels.uniqueCustomers,
- ]);
-
- const renderLabel = (type: string) => (data: any) => ;
+ const { compare } = useDateRange();
+ const chartQuery = useRevenueChartQuery(websiteId, currency);
+ const statsQuery = useRevenueStatsQuery({ websiteId, currency, compare });
+ const data = useMemo(
+ () =>
+ chartQuery.data && statsQuery.data
+ ? { chart: chartQuery.data.chart, total: statsQuery.data }
+ : null,
+ [chartQuery.data, statsQuery.data],
+ );
+ const error = chartQuery.error || statsQuery.error;
+ const isFetching = chartQuery.isFetching || statsQuery.isFetching;
+ const isLoading = chartQuery.isLoading || statsQuery.isLoading;
return (
-
+
{data && (
-
- {metrics?.map(({ label, value, change, formatValue, tooltip }) => {
- return (
-
- );
- })}
-
+