diff --git a/src/app/portfolio/[uid]/page.tsx b/src/app/portfolio/[uid]/page.tsx index d100da5..1922125 100644 --- a/src/app/portfolio/[uid]/page.tsx +++ b/src/app/portfolio/[uid]/page.tsx @@ -12,24 +12,82 @@ export default async function Portfolio({ if (error) { console.error(error); } - const getMonthName = (dateString: string) => { - const date = new Date(dateString); - return date.toLocaleString("default", { month: "long" }); + const yearAgo = (num: number) => { + const newDate = new Date(); + newDate.setFullYear(newDate.getFullYear() - num); + return newDate; }; - const graphData = deals - ? deals.map((item) => ({ - // convert month's index to string - name: getMonthName(item.created_time), - value: item.deal_amount as number, - })) + const getMonthName = (dateString: string) => { + const date = new Date(dateString); + return date.toLocaleString("default", { month: "long", year: "numeric" }); + }; + + const overAllGraphData = deals + ? deals + .filter((item) => new Date(item.created_time) >= yearAgo(1)) + .reduce( + (acc, item) => { + const monthName = getMonthName(item.created_time).slice(0, 3); + const existingMonth = acc.find( + (entry: { name: string }) => entry.name === monthName + ); + + if (existingMonth) { + existingMonth.value += item.deal_amount; + } else { + acc.push({ name: monthName, value: item.deal_amount }); + } + + return acc; + }, + [] as { name: string; value: number }[] + ) : []; +const threeYearGraphData = deals + ? deals + .filter((item) => new Date(item.created_time) >= yearAgo(3)) + .reduce( + (acc, item) => { + const year = new Date(item.created_time).getFullYear(); + const existingYear = acc.find( + (entry: { name: string; }) => entry.name === year.toString() + ); + + if (existingYear) { + existingYear.value += item.deal_amount; + } else { + acc.push({ name: year.toString(), value: item.deal_amount }) + } + + return acc; + }, + [] as { name: string; value: number }[] + ) + : []; + + + + // const graphData = [ + // { name: "October", value: 500 }, + // { name: "October", value: 500 }, + // { name: "November", value: 500 }, + // { name: "December", value: 500 }, + // { name: "January", value: 500 }, + // { name: "Febuary", value: 500 }, + // { name: "March", value: 500 }, + // ]; + return (
{/* {JSON.stringify(deals)} */} - {JSON.stringify(graphData)} - + {/* {JSON.stringify(deals)} */} + {/* {JSON.stringify(threeYearGraphData)} */} +
+ + +
); } diff --git a/src/components/ui/overview.tsx b/src/components/ui/overview.tsx index 1834549..8c4cf9f 100644 --- a/src/components/ui/overview.tsx +++ b/src/components/ui/overview.tsx @@ -78,7 +78,7 @@ export function Overview(props: OverViewProps) { tickFormatter={(value) => `$${value}`} /> @@ -99,7 +99,7 @@ export function Overview(props: OverViewProps) { axisLine={false} tickFormatter={(value) => `$${value}`} /> - + )} diff --git a/src/lib/data/query.ts b/src/lib/data/query.ts index da4a9da..9a06cd1 100644 --- a/src/lib/data/query.ts +++ b/src/lib/data/query.ts @@ -45,9 +45,14 @@ function getInvestmentCounts(client: SupabaseClient, projectIds: string[]) { } function getInvestorDeal(client: SupabaseClient, userId: string) { - return client.from("investment_deal").select("*").in("investor_id", [userId]); + return client + .from("investment_deal") + .select("*") + .in("investor_id", [userId]) + .order("created_time", { ascending: true }); } + export { getBusinesses, getInvestmentCounts,