From 17004465b4c94a4211d506159f6bbdb518585630 Mon Sep 17 00:00:00 2001 From: deji2ghost Date: Sat, 17 Aug 2024 16:49:46 +0200 Subject: [PATCH] feat: dashboard data. --- src/actions/dashboard.ts | 28 +++++++++ .../_components/overview-revenue/index.tsx | 61 +++++++++++++++++-- 2 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 src/actions/dashboard.ts diff --git a/src/actions/dashboard.ts b/src/actions/dashboard.ts new file mode 100644 index 000000000..1da3e21d4 --- /dev/null +++ b/src/actions/dashboard.ts @@ -0,0 +1,28 @@ +"use server"; + +import axios from "axios"; + +import { auth } from "~/lib/auth"; +import { getApiUrl } from "./getApiUrl"; + +export const dashboard = async () => { + const session = await auth(); + const apiUrl = await getApiUrl(); + try { + const response = await axios.get(`${apiUrl}/api/v1/Dashboards`, { + headers: { + Authorization: `Bearer ${session?.access_token}`, + }, + }); + return response.data; + } catch (error) { + return axios.isAxiosError(error) && error.response + ? { + error: error.response.data.message || "Product creation failed.", + status: error.response.status, + } + : { + error: "An unexpected error occurred.", + }; + } +}; diff --git a/src/app/dashboard/(user-dashboard)/_components/overview-revenue/index.tsx b/src/app/dashboard/(user-dashboard)/_components/overview-revenue/index.tsx index c035a171e..10642e0eb 100644 --- a/src/app/dashboard/(user-dashboard)/_components/overview-revenue/index.tsx +++ b/src/app/dashboard/(user-dashboard)/_components/overview-revenue/index.tsx @@ -1,40 +1,93 @@ "use client"; +import { useEffect, useState } from "react"; + +import { dashboard } from "~/actions/dashboard"; import { revenueData } from "~/app/dashboard/(user-dashboard)/_components/overview-revenue/revenueData"; import CardComponent from "~/components/common/DashboardCard/CardComponent"; import { useOrgContext } from "~/contexts/orgContext"; +interface dashboard { + revenue: number; + subscriptions: number; + sales: number; + activeSubscription: number; + monthSales: [ + { + id: string; + user_id: string; + product_id: string; + subscription_id: string; + type: string; + status: string; + partners: string; + amount: number; + reference: string; + created_at: string; + paid_at: string; + modified_at: string; + }, + ]; +} export function OverviewRevenue() { + const [dashboardObjectData, setDashboardObjectData] = useState(); + useEffect(() => { + getDashboardData(); + }, []); + const getDashboardData = async () => { + const data = await dashboard(); + setDashboardObjectData(data); + }; const { isLoading, dashboardData } = useOrgContext(); return (