diff --git a/src/app/api/dealApi.ts b/src/app/api/dealApi.ts index cd56925..0752168 100644 --- a/src/app/api/dealApi.ts +++ b/src/app/api/dealApi.ts @@ -35,7 +35,7 @@ export async function getDealList(userId: string | undefined) { } if (!dealData || !dealData.project.length) { - alert("No project available"); + // alert("No project available"); return []; // Exit if there's no data } diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index d506482..9026d07 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -4,9 +4,13 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Overview } from "@/components/ui/overview"; import { RecentFunds } from "@/components/recent-funds"; -import { useState } from "react"; - +import { useEffect, useState } from "react"; +import { getBusinessByUserId } from "@/lib/data/businessQuery"; import { useDealList } from "./hook"; +import { createSupabaseClient } from "@/lib/supabase/clientComponentClient"; +import { useQuery } from "@supabase-cache-helpers/postgrest-react-query"; +import useSession from "@/lib/supabase/useSession"; +import { getProjectByUserId } from "@/lib/data/projectQuery"; const data = [ { @@ -60,19 +64,35 @@ const data = [ ]; export default function Dashboard() { + let supabase = createSupabaseClient(); + const userId = useSession().session?.user.id; + const [projects, setProjects] = useState< + { id: number; project_name: string; business_id: { user_id: number }[]; dataroom_id: number }[] + >([]); const [graphType, setGraphType] = useState("line"); const dealList = useDealList(); const totalDealAmount = dealList?.reduce((sum, deal) => sum + deal.deal_amount, 0) || 0; + useEffect(() => { + const fetchProjects = async () => { + if (userId) { + const { data, error } = await getProjectByUserId(supabase, userId); + // alert(JSON.stringify(data)); + if (error) { + console.error("Error while fetching projects"); + } + if (data) { + setProjects(data); + console.table(data); + } + } else { + console.error("Error with UserId while fetching projects"); + } + }; + fetchProjects(); + }, [supabase, userId]); return ( <> - {dealList?.map((deal, index) => ( -
Deal Amount: {deal.deal_amount}
-Created Time: {new Date(deal.created_time).toUTCString()}
-Investor ID: {deal.investor_id}
-