mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-19 05:54:06 +01:00
connect total funds raised to database
This commit is contained in:
parent
7f885008f8
commit
a41e028bdc
@ -14,9 +14,16 @@ import { useEffect, useState } from "react";
|
|||||||
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
||||||
|
|
||||||
export default function Dashboard() {
|
export default function Dashboard() {
|
||||||
|
type Deal = {
|
||||||
|
deal_amount: number;
|
||||||
|
created_time: Date;
|
||||||
|
investor_id: string;
|
||||||
|
};
|
||||||
|
|
||||||
let supabase = createSupabaseClient();
|
let supabase = createSupabaseClient();
|
||||||
const [graphType, setGraphType] = useState("line");
|
const [graphType, setGraphType] = useState("line");
|
||||||
const [totalFundsRaised, setTotalFundsRaised] = useState();
|
const [dealList, setDealList] = useState<Deal[]>();
|
||||||
|
const totalDealAmount = dealList?.reduce((sum, deal) => sum + deal.deal_amount, 0) || 0;
|
||||||
|
|
||||||
// get current user id
|
// get current user id
|
||||||
// #TODO extract function to lib/util
|
// #TODO extract function to lib/util
|
||||||
@ -31,9 +38,8 @@ export default function Dashboard() {
|
|||||||
return user.id;
|
return user.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchTotalFundsRaised = async () => {
|
const getDealList = async () => {
|
||||||
const userId = await getUserID();
|
const userId = await getUserID();
|
||||||
|
|
||||||
const { data: dealData, error } = await supabase
|
const { data: dealData, error } = await supabase
|
||||||
.from('business')
|
.from('business')
|
||||||
.select(`
|
.select(`
|
||||||
@ -54,17 +60,36 @@ export default function Dashboard() {
|
|||||||
alert(JSON.stringify(error));
|
alert(JSON.stringify(error));
|
||||||
console.error('Error fetching deal amount:', error);
|
console.error('Error fetching deal amount:', error);
|
||||||
} else {
|
} else {
|
||||||
alert(JSON.stringify(dealData));
|
const dealList = dealData.project[0].investment_deal;
|
||||||
// setTotalFundsRaised(deal); #TODO
|
|
||||||
|
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(() => {
|
useEffect(() => {
|
||||||
fetchTotalFundsRaised();
|
fetchDealList();
|
||||||
}, []);
|
}, []);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{totalFundsRaised}
|
{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"
|
||||||
@ -84,7 +109,7 @@ export default function Dashboard() {
|
|||||||
<div className="hidden flex-col md:flex">
|
<div className="hidden flex-col md:flex">
|
||||||
<div className="flex-1 space-y-4 p-8 pt-6">
|
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||||
<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">Dashboard</h2>
|
<h2 className="text-3xl font-bold tracking-tight">Business Dashboard</h2>
|
||||||
</div>
|
</div>
|
||||||
<Tabs defaultValue="overview" className="space-y-4">
|
<Tabs defaultValue="overview" className="space-y-4">
|
||||||
<TabsList>
|
<TabsList>
|
||||||
@ -112,10 +137,10 @@ export default function Dashboard() {
|
|||||||
</svg>
|
</svg>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-2xl font-bold">$45,231.89</div>
|
<div className="text-2xl font-bold">${totalDealAmount}</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
{/* <p className="text-xs text-muted-foreground">
|
||||||
+20.1% from last month
|
+20.1% from last month
|
||||||
</p>
|
</p> */}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
<Card>
|
<Card>
|
||||||
@ -139,9 +164,9 @@ export default function Dashboard() {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-2xl font-bold">+2350</div>
|
<div className="text-2xl font-bold">+2350</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
{/* <p className="text-xs text-muted-foreground">
|
||||||
+180.1% from last month
|
+180.1% from last month
|
||||||
</p>
|
</p> */}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
<Card>
|
<Card>
|
||||||
@ -166,9 +191,9 @@ export default function Dashboard() {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-2xl font-bold">+12,234</div>
|
<div className="text-2xl font-bold">+12,234</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
{/* <p className="text-xs text-muted-foreground">
|
||||||
+19% from last month
|
+19% from last month
|
||||||
</p>
|
</p> */}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
{/* <Card>
|
{/* <Card>
|
||||||
@ -230,11 +255,12 @@ export default function Dashboard() {
|
|||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Recent Funds</CardTitle>
|
<CardTitle>Recent Funds</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
You made 265 sales this month.
|
You made {dealList?.length || 0} sales this month.
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<RecentFunds />
|
<RecentFunds>
|
||||||
|
</RecentFunds>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user