From a0de7e9112c17ef6304f24e98983d8dc43004caa Mon Sep 17 00:00:00 2001 From: vincanger <70215737+vincanger@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:02:38 +0100 Subject: [PATCH] add notification to admin dash if no stats generated yet (#346) * add notification if no stats generated yet * Update main.wasp * fix app_diff * Update AnalyticsDashboardPage.tsx --- opensaas-sh/app_diff/package-lock.json.diff | 4 +- .../analytics/AnalyticsDashboardPage.tsx.diff | 43 +++++---------- .../client/components/NavBar/NavBar.tsx.diff | 8 ++- .../analytics/AnalyticsDashboardPage.tsx | 54 +++++++++++++------ template/app/src/analytics/operations.ts | 5 +- 5 files changed, 64 insertions(+), 50 deletions(-) diff --git a/opensaas-sh/app_diff/package-lock.json.diff b/opensaas-sh/app_diff/package-lock.json.diff index 186a12a6..88565e56 100644 --- a/opensaas-sh/app_diff/package-lock.json.diff +++ b/opensaas-sh/app_diff/package-lock.json.diff @@ -25,8 +25,10 @@ + "prettier-plugin-tailwindcss": "0.5.11", + "react": "^18.2.0", + "react-apexcharts": "1.4.1", ++ "react-dom": "^18.2.0", + "react-hot-toast": "^2.4.1", + "react-icons": "4.11.0", ++ "react-router-dom": "^6.26.2", + "stripe": "11.15.0", + "tailwind-merge": "^2.2.1", + "vanilla-cookieconsent": "^3.0.1", @@ -9013,7 +9015,6 @@ + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", + "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", -+ "peer": true, + "dependencies": { + "loose-envify": "^1.1.0", + "scheduler": "^0.23.2" @@ -9327,7 +9328,6 @@ + "version": "0.23.2", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", + "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", -+ "peer": true, + "dependencies": { + "loose-envify": "^1.1.0" + } diff --git a/opensaas-sh/app_diff/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx.diff b/opensaas-sh/app_diff/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx.diff index 96ae364d..8d78b92f 100644 --- a/opensaas-sh/app_diff/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx.diff +++ b/opensaas-sh/app_diff/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx.diff @@ -7,17 +7,12 @@ import { useQuery, getDailyStats } from 'wasp/client/operations'; import TotalSignupsCard from './TotalSignupsCard'; import TotalPageViewsCard from './TotalPageViewsCard'; -@@ -7,21 +9,68 @@ - import RevenueAndProfitChart from './RevenueAndProfitChart'; - import SourcesTable from './SourcesTable'; - import DefaultLayout from '../../layout/DefaultLayout'; --import { useRedirectHomeUnlessUserIsAdmin } from '../../useRedirectHomeUnlessUserIsAdmin' -+import { useRedirectHomeUnlessUserIsAdmin } from '../../useRedirectHomeUnlessUserIsAdmin'; +@@ -10,12 +12,54 @@ + import { useRedirectHomeUnlessUserIsAdmin } from '../../useRedirectHomeUnlessUserIsAdmin'; const Dashboard = ({ user }: { user: AuthUser }) => { -- useRedirectHomeUnlessUserIsAdmin({ user }) + const [isDemoInfoVisible, setIsDemoInfoVisible] = useState(false); -+ useRedirectHomeUnlessUserIsAdmin({ user }); + useRedirectHomeUnlessUserIsAdmin({ user }); const { data: stats, isLoading, error } = useQuery(getDailyStats); @@ -48,7 +43,6 @@ + return ( -+ {/* Floating Demo Announcement */} + {isDemoInfoVisible && ( +
+
@@ -65,26 +59,15 @@ +
+
+ )} -
- -- -+ - - -
-@@ -30,7 +79,7 @@ - +
+
+
+@@ -36,7 +80,7 @@ + -
-- -+ +
+- ++ +
+
-
- diff --git a/opensaas-sh/app_diff/src/client/components/NavBar/NavBar.tsx.diff b/opensaas-sh/app_diff/src/client/components/NavBar/NavBar.tsx.diff index c55dcb88..1b4a1c6c 100644 --- a/opensaas-sh/app_diff/src/client/components/NavBar/NavBar.tsx.diff +++ b/opensaas-sh/app_diff/src/client/components/NavBar/NavBar.tsx.diff @@ -19,7 +19,13 @@
-@@ -61,8 +60,8 @@ +@@ -56,13 +55,13 @@ +
+
{renderNavigationItems(navigationItems)}
+
+-
    ++
      +
    {isUserLoading ? null : !user ? ( diff --git a/template/app/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx b/template/app/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx index dcd2f1ed..70382a45 100644 --- a/template/app/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx +++ b/template/app/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx @@ -7,31 +7,55 @@ import TotalRevenueCard from './TotalRevenueCard'; import RevenueAndProfitChart from './RevenueAndProfitChart'; import SourcesTable from './SourcesTable'; import DefaultLayout from '../../layout/DefaultLayout'; -import { useRedirectHomeUnlessUserIsAdmin } from '../../useRedirectHomeUnlessUserIsAdmin' +import { useRedirectHomeUnlessUserIsAdmin } from '../../useRedirectHomeUnlessUserIsAdmin'; +import { cn } from '../../../client/cn'; const Dashboard = ({ user }: { user: AuthUser }) => { - useRedirectHomeUnlessUserIsAdmin({ user }) + useRedirectHomeUnlessUserIsAdmin({ user }); const { data: stats, isLoading, error } = useQuery(getDailyStats); return ( -
    - - - - -
    +
    +
    +
    + + + + +
    -
    - +
    + -
    - +
    + +
    +
    + + {!stats && ( +
    +
    +

    + No daily stats generated yet +

    +

    + Stats will appear here once the daily stats job has run +

    +
    +
    + )}
    ); diff --git a/template/app/src/analytics/operations.ts b/template/app/src/analytics/operations.ts index e9ed8669..bfe5041c 100644 --- a/template/app/src/analytics/operations.ts +++ b/template/app/src/analytics/operations.ts @@ -11,7 +11,7 @@ type DailyStatsValues = { weeklyStats: DailyStatsWithSources[]; }; -export const getDailyStats: GetDailyStats = async (_args, context) => { +export const getDailyStats: GetDailyStats = async (_args, context) => { if (!context.user?.isAdmin) { throw new HttpError(401); } @@ -24,7 +24,8 @@ export const getDailyStats: GetDailyStats = async (_args }, }); if (!dailyStats) { - throw new HttpError(204, 'No daily stats generated yet.'); + console.log('\x1b[34mNote: No daily stats have been generated by the dailyStatsJob yet. \x1b[0m'); + return undefined; } const weeklyStats = await context.entities.DailyStats.findMany({