diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index c6e41a3..f3b4df1 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -14,9 +14,16 @@ import { useEffect, useState } from "react"; import { createSupabaseClient } from "@/lib/supabase/clientComponentClient"; export default function Dashboard() { + type Deal = { + deal_amount: number; + created_time: Date; + investor_id: string; + }; + let supabase = createSupabaseClient(); const [graphType, setGraphType] = useState("line"); - const [totalFundsRaised, setTotalFundsRaised] = useState(); + const [dealList, setDealList] = useState(); + const totalDealAmount = dealList?.reduce((sum, deal) => sum + deal.deal_amount, 0) || 0; // get current user id // #TODO extract function to lib/util @@ -31,9 +38,8 @@ export default function Dashboard() { return user.id; } - const fetchTotalFundsRaised = async () => { + const getDealList = async () => { const userId = await getUserID(); - const { data: dealData, error } = await supabase .from('business') .select(` @@ -54,17 +60,36 @@ export default function Dashboard() { alert(JSON.stringify(error)); console.error('Error fetching deal amount:', error); } else { - alert(JSON.stringify(dealData)); - // setTotalFundsRaised(deal); #TODO + const dealList = dealData.project[0].investment_deal; + + if (!dealList.length) { + alert("No data available"); + return; // Exit early if there's no data + } + + // Sort the dealList by created_time in descending order + const byCreatedTimeDesc = (a: Deal, b: Deal) => + new Date(b.created_time).getTime() - new Date(a.created_time).getTime(); + return dealList.sort(byCreatedTimeDesc); } } + const fetchDealList = async () => { + setDealList(await getDealList()); + } + useEffect(() => { - fetchTotalFundsRaised(); + fetchDealList(); }, []); return ( <> - {totalFundsRaised} + {dealList?.map((deal, index) => ( +
+

Deal Amount: {deal.deal_amount}

+

Created Time: {new Date(deal.created_time).toUTCString()}

+

Investor ID: {deal.investor_id}

+
+ ))}
-

Dashboard

+

Business Dashboard

@@ -112,10 +137,10 @@ export default function Dashboard() { -
$45,231.89
-

+

${totalDealAmount}
+ {/*

+20.1% from last month -

+

*/}
@@ -139,9 +164,9 @@ export default function Dashboard() {
+2350
-

+ {/*

+180.1% from last month -

+

*/}
@@ -166,9 +191,9 @@ export default function Dashboard() {
+12,234
-

+ {/*

+19% from last month -

+

*/}
{/* @@ -230,11 +255,12 @@ export default function Dashboard() { Recent Funds - You made 265 sales this month. + You made {dealList?.length || 0} sales this month. - + +