mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-19 22:14:06 +01:00
refactor: remove unused custom hooks for deal list and graph data
This commit is contained in:
parent
578cff2507
commit
a1158907fb
@ -1,53 +0,0 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Deal, getDealList, convertToGraphData, getRecentDealData } from "../api/dealApi";
|
||||
import { RecentDealData } from "@/components/recent-funds";
|
||||
import { getCurrentUserID } from "../api/userApi";
|
||||
|
||||
// custom hook for deal list
|
||||
export function useDealList() {
|
||||
const [dealList, setDealList] = useState<Deal[]>([]);
|
||||
|
||||
const fetchDealList = async () => {
|
||||
// set the state to the deal list of current business user
|
||||
setDealList(await getDealList(await getCurrentUserID()));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchDealList();
|
||||
}, []);
|
||||
|
||||
return dealList;
|
||||
}
|
||||
|
||||
export function useGraphData() {
|
||||
const [graphData, setGraphData] = useState({});
|
||||
|
||||
const fetchGraphData = async () => {
|
||||
// fetch the state to the deal list of current business user
|
||||
const dealList = await getDealList(await getCurrentUserID());
|
||||
if (dealList) {
|
||||
setGraphData(convertToGraphData(dealList));
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchGraphData();
|
||||
}, []);
|
||||
|
||||
return graphData;
|
||||
}
|
||||
|
||||
export function useRecentDealData() {
|
||||
const [recentDealData, setRecentDealData] = useState<RecentDealData[]>();
|
||||
|
||||
const fetchRecentDealData = async () => {
|
||||
// set the state to the deal list of current business user
|
||||
setRecentDealData(await getRecentDealData(await getCurrentUserID()));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchRecentDealData();
|
||||
}, []);
|
||||
|
||||
return recentDealData;
|
||||
}
|
||||
@ -5,7 +5,6 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { Overview } from "@/components/ui/overview";
|
||||
import { RecentFunds } from "@/components/recent-funds";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useDealList } from "./hook";
|
||||
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
||||
import useSession from "@/lib/supabase/useSession";
|
||||
import { getProjectByUserId } from "@/lib/data/projectQuery";
|
||||
@ -70,8 +69,6 @@ export default function Dashboard() {
|
||||
>([]);
|
||||
const [isSuccess, setIsSuccess] = useState(false);
|
||||
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) {
|
||||
@ -91,6 +88,7 @@ export default function Dashboard() {
|
||||
};
|
||||
fetchProjects();
|
||||
}, [supabase, userId]);
|
||||
// console.table(projects);
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -116,7 +114,7 @@ export default function Dashboard() {
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<h2 className="text-3xl font-bold tracking-tight">Business Dashboard</h2>
|
||||
</div>
|
||||
<Tabs defaultValue={projects[0].project_name} className="space-y-4">
|
||||
<Tabs className="space-y-4">
|
||||
<TabsList>
|
||||
{projects.map((project) => (
|
||||
<TabsTrigger key={project.id} value={project.project_name}>
|
||||
@ -124,7 +122,8 @@ export default function Dashboard() {
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
<TabsContent value={projects[0].project_name} className="space-y-4">
|
||||
{projects.map((project) => (
|
||||
<TabsContent value={project.project_name} className="space-y-4">
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
@ -143,7 +142,7 @@ export default function Dashboard() {
|
||||
</svg>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">${totalDealAmount}</div>
|
||||
<div className="text-2xl font-bold">${}</div>
|
||||
{/* <p className="text-xs text-muted-foreground">
|
||||
+20.1% from last month
|
||||
</p> */}
|
||||
@ -247,7 +246,7 @@ export default function Dashboard() {
|
||||
<Card className="col-span-3">
|
||||
<CardHeader>
|
||||
<CardTitle>Recent Funds</CardTitle>
|
||||
<CardDescription>You made {dealList?.length || 0} sales this month.</CardDescription>
|
||||
<CardDescription>You had {} investors invest this month.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<RecentFunds></RecentFunds>
|
||||
@ -255,6 +254,7 @@ export default function Dashboard() {
|
||||
</Card>
|
||||
</div>
|
||||
</TabsContent>
|
||||
))}
|
||||
</Tabs>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user