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 { Overview } from "@/components/ui/overview";
|
||||||
import { RecentFunds } from "@/components/recent-funds";
|
import { RecentFunds } from "@/components/recent-funds";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useDealList } from "./hook";
|
|
||||||
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
||||||
import useSession from "@/lib/supabase/useSession";
|
import useSession from "@/lib/supabase/useSession";
|
||||||
import { getProjectByUserId } from "@/lib/data/projectQuery";
|
import { getProjectByUserId } from "@/lib/data/projectQuery";
|
||||||
@ -70,8 +69,6 @@ export default function Dashboard() {
|
|||||||
>([]);
|
>([]);
|
||||||
const [isSuccess, setIsSuccess] = useState(false);
|
const [isSuccess, setIsSuccess] = useState(false);
|
||||||
const [graphType, setGraphType] = useState("line");
|
const [graphType, setGraphType] = useState("line");
|
||||||
const dealList = useDealList();
|
|
||||||
const totalDealAmount = dealList?.reduce((sum, deal) => sum + deal.deal_amount, 0) || 0;
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchProjects = async () => {
|
const fetchProjects = async () => {
|
||||||
if (userId) {
|
if (userId) {
|
||||||
@ -91,6 +88,7 @@ export default function Dashboard() {
|
|||||||
};
|
};
|
||||||
fetchProjects();
|
fetchProjects();
|
||||||
}, [supabase, userId]);
|
}, [supabase, userId]);
|
||||||
|
// console.table(projects);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -116,7 +114,7 @@ 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={projects[0].project_name} className="space-y-4">
|
<Tabs className="space-y-4">
|
||||||
<TabsList>
|
<TabsList>
|
||||||
{projects.map((project) => (
|
{projects.map((project) => (
|
||||||
<TabsTrigger key={project.id} value={project.project_name}>
|
<TabsTrigger key={project.id} value={project.project_name}>
|
||||||
@ -124,81 +122,82 @@ export default function Dashboard() {
|
|||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
))}
|
))}
|
||||||
</TabsList>
|
</TabsList>
|
||||||
<TabsContent value={projects[0].project_name} className="space-y-4">
|
{projects.map((project) => (
|
||||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
<TabsContent value={project.project_name} className="space-y-4">
|
||||||
<Card>
|
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
<Card>
|
||||||
<CardTitle className="text-sm font-medium">Total Funds Raised</CardTitle>
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
<svg
|
<CardTitle className="text-sm font-medium">Total Funds Raised</CardTitle>
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
<svg
|
||||||
viewBox="0 0 24 24"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
fill="none"
|
viewBox="0 0 24 24"
|
||||||
stroke="currentColor"
|
fill="none"
|
||||||
strokeLinecap="round"
|
stroke="currentColor"
|
||||||
strokeLinejoin="round"
|
strokeLinecap="round"
|
||||||
strokeWidth="2"
|
strokeLinejoin="round"
|
||||||
className="h-4 w-4 text-muted-foreground"
|
strokeWidth="2"
|
||||||
>
|
className="h-4 w-4 text-muted-foreground"
|
||||||
<path d="M12 2v20M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6" />
|
>
|
||||||
</svg>
|
<path d="M12 2v20M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6" />
|
||||||
</CardHeader>
|
</svg>
|
||||||
<CardContent>
|
</CardHeader>
|
||||||
<div className="text-2xl font-bold">${totalDealAmount}</div>
|
<CardContent>
|
||||||
{/* <p className="text-xs text-muted-foreground">
|
<div className="text-2xl font-bold">${}</div>
|
||||||
|
{/* <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>
|
||||||
<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">
|
||||||
<CardTitle className="text-sm font-medium">Profile Views</CardTitle>
|
<CardTitle className="text-sm font-medium">Profile Views</CardTitle>
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
fill="none"
|
fill="none"
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
strokeLinecap="round"
|
strokeLinecap="round"
|
||||||
strokeLinejoin="round"
|
strokeLinejoin="round"
|
||||||
strokeWidth="2"
|
strokeWidth="2"
|
||||||
className="h-4 w-4 text-muted-foreground"
|
className="h-4 w-4 text-muted-foreground"
|
||||||
>
|
>
|
||||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
|
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
|
||||||
<circle cx="12" cy="12" r="3"></circle>
|
<circle cx="12" cy="12" r="3"></circle>
|
||||||
</svg>
|
</svg>
|
||||||
</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>
|
||||||
<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">
|
||||||
<CardTitle className="text-sm font-medium">Total Followers</CardTitle>
|
<CardTitle className="text-sm font-medium">Total Followers</CardTitle>
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
fill="none"
|
fill="none"
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
strokeLinecap="round"
|
strokeLinecap="round"
|
||||||
strokeLinejoin="round"
|
strokeLinejoin="round"
|
||||||
strokeWidth="2"
|
strokeWidth="2"
|
||||||
className="h-4 w-4 text-muted-foreground"
|
className="h-4 w-4 text-muted-foreground"
|
||||||
>
|
>
|
||||||
<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" />
|
<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" />
|
||||||
<circle cx="9" cy="7" r="4" />
|
<circle cx="9" cy="7" r="4" />
|
||||||
<path d="M22 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75" />
|
<path d="M22 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75" />
|
||||||
</svg>
|
</svg>
|
||||||
</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>
|
||||||
<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">
|
||||||
<CardTitle className="text-sm font-medium">
|
<CardTitle className="text-sm font-medium">
|
||||||
Active Now
|
Active Now
|
||||||
@ -223,38 +222,39 @@ export default function Dashboard() {
|
|||||||
</p>
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card> */}
|
</Card> */}
|
||||||
</div>
|
</div>
|
||||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-7">
|
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-7">
|
||||||
<Card className="col-span-4">
|
<Card className="col-span-4">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Overview</CardTitle>
|
<CardTitle>Overview</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="pl-2">
|
<CardContent className="pl-2">
|
||||||
<Overview graphType={graphType} data={data} />
|
<Overview graphType={graphType} data={data} />
|
||||||
{/* tab to switch between line and bar graph */}
|
{/* tab to switch between line and bar graph */}
|
||||||
<Tabs defaultValue="line" className="space-y-4 ml-[50%] mt-2">
|
<Tabs defaultValue="line" className="space-y-4 ml-[50%] mt-2">
|
||||||
<TabsList>
|
<TabsList>
|
||||||
<TabsTrigger value="line" onClick={() => setGraphType("line")}>
|
<TabsTrigger value="line" onClick={() => setGraphType("line")}>
|
||||||
Line
|
Line
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
<TabsTrigger value="bar" onClick={() => setGraphType("bar")}>
|
<TabsTrigger value="bar" onClick={() => setGraphType("bar")}>
|
||||||
Bar
|
Bar
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
</TabsList>
|
</TabsList>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
<Card className="col-span-3">
|
<Card className="col-span-3">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Recent Funds</CardTitle>
|
<CardTitle>Recent Funds</CardTitle>
|
||||||
<CardDescription>You made {dealList?.length || 0} sales this month.</CardDescription>
|
<CardDescription>You had {} investors invest this month.</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<RecentFunds></RecentFunds>
|
<RecentFunds></RecentFunds>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
))}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user