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}

-
- ))}

Business Dashboard

- + - Overview - Analytics + {projects.map((project) => ( + {project.project_name} + ))} - +
diff --git a/src/lib/data/businessQuery.ts b/src/lib/data/businessQuery.ts index 6d6d138..382a2ea 100644 --- a/src/lib/data/businessQuery.ts +++ b/src/lib/data/businessQuery.ts @@ -18,6 +18,17 @@ export const getAllBusinesses = (client: SupabaseClient) => { `); }; +export async function getBusinessByUserId(client: SupabaseClient, userId: string) { + const { data, error } = await client.from("business").select("*").eq("user_id", userId); + + if (error) { + console.error("Error fetching business ID:", error); + return null; + } + + return data; +} + export const getBusinessAndProject = ( client: SupabaseClient, params: { businessName?: String | null; businessId?: number | null; single?: boolean } = { single: false }