From 095d1f2070eeb1fe1ea5c10c301af4febab0ce4d Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Wed, 11 Jun 2025 23:12:10 -0700 Subject: [PATCH] Updates to Revenue report. --- src/app/(main)/console/TestConsole.module.css | 33 --- src/app/(main)/console/TestConsole.tsx | 219 ------------------ .../console/[websiteId]/TestConsolePage.tsx | 202 ++++++++++++++++ .../page.tsx | 4 +- .../realtime/RealtimeCountries.tsx | 2 +- .../reports/retention/Retention.tsx | 4 +- .../[websiteId]/reports/revenue/Revenue.tsx | 120 +++------- .../[websiteId]/sessions/SessionsWeekly.tsx | 76 +++--- src/app/api/reports/revenue/route.ts | 2 +- src/components/common/Panel.tsx | 1 + src/components/common/TypeIcon.tsx | 2 +- src/components/hooks/useFormat.ts | 2 +- src/components/input/CurrencySelect.tsx | 34 +++ src/components/metrics/CountriesTable.tsx | 2 +- src/components/metrics/EventsChart.tsx | 4 +- src/lib/date.ts | 3 +- src/lib/format.ts | 2 +- src/lib/schema.ts | 3 + src/queries/sql/reports/getRevenue.ts | 66 +++--- 19 files changed, 365 insertions(+), 416 deletions(-) delete mode 100644 src/app/(main)/console/TestConsole.module.css delete mode 100644 src/app/(main)/console/TestConsole.tsx create mode 100644 src/app/(main)/console/[websiteId]/TestConsolePage.tsx rename src/app/(main)/console/{[[...websiteId]] => [websiteId]}/page.tsx (78%) create mode 100644 src/components/input/CurrencySelect.tsx diff --git a/src/app/(main)/console/TestConsole.module.css b/src/app/(main)/console/TestConsole.module.css deleted file mode 100644 index 88b70ab3..00000000 --- a/src/app/(main)/console/TestConsole.module.css +++ /dev/null @@ -1,33 +0,0 @@ -.container { - display: grid; - gap: 30px; - padding-bottom: 40px; -} - -.actions { - border: 1px solid var(--base400); - border-radius: 5px; - padding: 0 20px 20px 20px; - display: grid; - gap: 40px; - grid-template-columns: repeat(3, minmax(300px, 1fr)); - box-shadow: 0 0 0 10px var(--base100); -} - -.header { - font-size: 16px; - font-weight: 700; - margin: 20px 0; -} - -.group { - display: flex; - flex-direction: column; - gap: 10px; -} - -.wrapped { - border: 1px solid var(--blue900); - border-radius: 4px; - padding: 8px 16px; -} diff --git a/src/app/(main)/console/TestConsole.tsx b/src/app/(main)/console/TestConsole.tsx deleted file mode 100644 index 6126b150..00000000 --- a/src/app/(main)/console/TestConsole.tsx +++ /dev/null @@ -1,219 +0,0 @@ -'use client'; -import { Button } from '@umami/react-zen'; -import Link from 'next/link'; -import Script from 'next/script'; -import { WebsiteSelect } from '@/components/input/WebsiteSelect'; -import { PageBody } from '@/components/common/PageBody'; -import { SectionHeader } from '@/components/common/SectionHeader'; -import { EventsChart } from '@/components/metrics/EventsChart'; -import { WebsiteChart } from '../websites/[websiteId]/WebsiteChart'; -import { useApi, useNavigation } from '@/components/hooks'; -import styles from './TestConsole.module.css'; - -export function TestConsole({ websiteId }: { websiteId: string }) { - const { get, useQuery } = useApi(); - const { data, isLoading, error } = useQuery({ - queryKey: ['websites:me'], - queryFn: () => get('/me/websites'), - }); - const { router } = useNavigation(); - - function handleChange(value: string) { - router.push(`/console/${value}`); - } - - function handleRunScript() { - window['umami'].track(props => ({ - ...props, - url: '/page-view', - referrer: 'https://www.google.com', - })); - window['umami'].track('track-event-no-data'); - window['umami'].track('track-event-with-data', { - test: 'test-data', - boolean: true, - booleanError: 'true', - time: new Date(), - user: `user${Math.round(Math.random() * 10)}`, - number: 1, - number2: Math.random() * 100, - time2: new Date().toISOString(), - nested: { - test: 'test-data', - number: 1, - object: { - test: 'test-data', - }, - }, - array: [1, 2, 3], - }); - } - - function handleRunRevenue() { - window['umami'].track(props => ({ - ...props, - url: '/checkout-cart', - referrer: 'https://www.google.com', - })); - window['umami'].track('checkout-cart', { - revenue: parseFloat((Math.random() * 1000).toFixed(2)), - currency: 'USD', - }); - window['umami'].track('affiliate-link', { - revenue: parseFloat((Math.random() * 1000).toFixed(2)), - currency: 'USD', - }); - window['umami'].track('promotion-link', { - revenue: parseFloat((Math.random() * 1000).toFixed(2)), - currency: 'USD', - }); - window['umami'].track('checkout-cart', { - revenue: parseFloat((Math.random() * 1000).toFixed(2)), - currency: 'EUR', - }); - window['umami'].track('promotion-link', { - revenue: parseFloat((Math.random() * 1000).toFixed(2)), - currency: 'EUR', - }); - window['umami'].track('affiliate-link', { - item1: { - productIdentity: 'ABC424', - revenue: parseFloat((Math.random() * 10000).toFixed(2)), - currency: 'JPY', - }, - item2: { - productIdentity: 'ZYW684', - revenue: parseFloat((Math.random() * 10000).toFixed(2)), - currency: 'JPY', - }, - }); - } - - function handleRunIdentify() { - window['umami'].identify({ - userId: 123, - name: 'brian', - number: Math.random() * 100, - test: 'test-data', - boolean: true, - booleanError: 'true', - time: new Date(), - time2: new Date().toISOString(), - nested: { - test: 'test-data', - number: 1, - object: { - test: 'test-data', - }, - }, - array: [1, 2, 3], - }); - } - - if (!data) { - return null; - } - - const website = data?.data.find(({ id }) => websiteId === id); - - return ( - - - - - {website && ( -
-