diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index 9eb0d3c..627ae12 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -11,6 +11,7 @@ import { getProjectByUserId } from "@/lib/data/projectQuery"; import { Loader } from "@/components/loading/loader"; import { getInvestmentByProjectsIds } from "@/lib/data/investmentQuery"; import { useQuery } from "@supabase-cache-helpers/postgrest-react-query"; +import { getLatestInvestment } from "../portfolio/[uid]/query"; const data = [ { @@ -69,8 +70,12 @@ export default function Dashboard() { const [projects, setProjects] = useState< { id: number; project_name: string; business_id: { user_id: number }[]; dataroom_id: number }[] >([]); + const [latestInvestment, setLatestInvestment] = useState< + { projectId: number; name: any; amount: number; date: Date; logo_url: string }[] + >([]); const [isSuccess, setIsSuccess] = useState(false); const [graphType, setGraphType] = useState("line"); + const [currentProjectId, setCurrentProjectId] = useState(projects[0]?.id); const investmentDetail = useQuery( getInvestmentByProjectsIds( supabase, @@ -79,6 +84,37 @@ export default function Dashboard() { }) ) ); + useEffect(() => { + const fetchLatestInvestment = async () => { + const latest = await getLatestInvestment( + supabase, + investmentDetail?.data?.map((deal) => { + return { + project_id: deal.project_id, + deal_amount: deal.deal_amount, + created_time: deal.created_time, + }; + }) || [] + ); + const resolvedLatest = await Promise.all( + latest.map(async (investment) => ({ + ...investment, + logo_url: await investment.logo_url, + })) + ); + setLatestInvestment( + resolvedLatest.map((investment) => ({ + projectId: investment.projectId, + name: investment.name, + amount: investment.amount, + date: investment.date, + logo_url: investment.logo_url, + })) + ); + // console.table(resolvedLatest); + }; + fetchLatestInvestment(); + }, [supabase, investmentDetail]); useEffect(() => { const fetchProjects = async () => { if (userId) { @@ -99,6 +135,7 @@ export default function Dashboard() { fetchProjects(); }, [supabase, userId]); // console.table(projects); + // console.table(latestInvestment); return ( <> @@ -124,14 +161,20 @@ export default function Dashboard() {

Business Dashboard

+ {projects.map((project) => ( - + setCurrentProjectId(project.id)} + > {project.project_name} ))} + {currentProjectId} {projects.map((project) => (
@@ -259,7 +302,21 @@ export default function Dashboard() { You had {} investors invest this month. - + { + if (item.projectId === currentProjectId) { + return { + name: item.name, + amount: item.amount, + avatar: item.logo_url, + date: item.date, + }; + } + return undefined; + }) + .filter((item) => item !== undefined)} + />
diff --git a/src/app/portfolio/[uid]/query.ts b/src/app/portfolio/[uid]/query.ts index 151d0eb..d3c147a 100644 --- a/src/app/portfolio/[uid]/query.ts +++ b/src/app/portfolio/[uid]/query.ts @@ -38,6 +38,7 @@ async function getLatestInvestment( } let url = fetchLogoURL(supabase, deals[i].project_id); llist.push({ + projectId: deals[i].project_id, name: project?.[0]?.project_name, amount: deals[i].deal_amount, date: new Date(deals[i].created_time),