mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-20 14:34:05 +01:00
feat: implement project fetching and update dashboard to display projects dynamically
This commit is contained in:
parent
54db6905da
commit
71b8ad314f
@ -35,7 +35,7 @@ export async function getDealList(userId: string | undefined) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!dealData || !dealData.project.length) {
|
if (!dealData || !dealData.project.length) {
|
||||||
alert("No project available");
|
// alert("No project available");
|
||||||
return []; // Exit if there's no data
|
return []; // Exit if there's no data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,9 +4,13 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com
|
|||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
import { Overview } from "@/components/ui/overview";
|
import { Overview } from "@/components/ui/overview";
|
||||||
import { RecentFunds } from "@/components/recent-funds";
|
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 { 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 = [
|
const data = [
|
||||||
{
|
{
|
||||||
@ -60,19 +64,35 @@ const data = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export default function Dashboard() {
|
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 [graphType, setGraphType] = useState("line");
|
||||||
const dealList = useDealList();
|
const dealList = useDealList();
|
||||||
const totalDealAmount = dealList?.reduce((sum, deal) => sum + deal.deal_amount, 0) || 0;
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
{dealList?.map((deal, index) => (
|
|
||||||
<div key={index} className="deal-item">
|
|
||||||
<p>Deal Amount: {deal.deal_amount}</p>
|
|
||||||
<p>Created Time: {new Date(deal.created_time).toUTCString()}</p>
|
|
||||||
<p>Investor ID: {deal.investor_id}</p>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
<div className="md:hidden">
|
<div className="md:hidden">
|
||||||
<Image
|
<Image
|
||||||
src="/examples/dashboard-light.png"
|
src="/examples/dashboard-light.png"
|
||||||
@ -94,12 +114,13 @@ export default function Dashboard() {
|
|||||||
<div className="flex items-center justify-between space-y-2">
|
<div className="flex items-center justify-between space-y-2">
|
||||||
<h2 className="text-3xl font-bold tracking-tight">Business Dashboard</h2>
|
<h2 className="text-3xl font-bold tracking-tight">Business Dashboard</h2>
|
||||||
</div>
|
</div>
|
||||||
<Tabs defaultValue="overview" className="space-y-4">
|
<Tabs defaultValue={projects[0].project_name} className="space-y-4">
|
||||||
<TabsList>
|
<TabsList>
|
||||||
<TabsTrigger value="overview">Overview</TabsTrigger>
|
{projects.map((project) => (
|
||||||
<TabsTrigger value="analytics">Analytics</TabsTrigger>
|
<TabsTrigger value={project.project_name}>{project.project_name}</TabsTrigger>
|
||||||
|
))}
|
||||||
</TabsList>
|
</TabsList>
|
||||||
<TabsContent value="overview" className="space-y-4">
|
<TabsContent value={projects[0].project_name} className="space-y-4">
|
||||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
|
|||||||
@ -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 = (
|
export const getBusinessAndProject = (
|
||||||
client: SupabaseClient,
|
client: SupabaseClient,
|
||||||
params: { businessName?: String | null; businessId?: number | null; single?: boolean } = { single: false }
|
params: { businessName?: String | null; businessId?: number | null; single?: boolean } = { single: false }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user