From 00c6b847e77e79664c0db571bb5b5b56c37f754f Mon Sep 17 00:00:00 2001 From: Sosokker Date: Mon, 4 Nov 2024 11:50:12 +0700 Subject: [PATCH] fix: missing getInvestorDeal function --- src/app/portfolio/[uid]/page.tsx | 99 ++++++++------------------------ src/lib/data/investmentQuery.ts | 8 +++ 2 files changed, 31 insertions(+), 76 deletions(-) diff --git a/src/app/portfolio/[uid]/page.tsx b/src/app/portfolio/[uid]/page.tsx index 3cdc730..dd8ec1a 100644 --- a/src/app/portfolio/[uid]/page.tsx +++ b/src/app/portfolio/[uid]/page.tsx @@ -1,6 +1,6 @@ import { Overview } from "@/components/ui/overview"; import { createSupabaseClient } from "@/lib/supabase/serverComponentClient"; -import { getInvestorDeal } from "@/lib/data/query"; +import { getInvestorDeal } from "@/lib/data/investmentQuery"; import PieChart from "@/components/pieChart"; import { overAllGraphData, @@ -16,12 +16,7 @@ import { } from "./hook"; import CountUpComponent from "@/components/countUp"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; -import { - Tooltip, - TooltipContent, - TooltipProvider, - TooltipTrigger, -} from "@/components/ui/tooltip"; +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import { RecentFunds } from "@/components/recent-funds"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import QuestionMarkIcon from "@/components/icon/questionMark"; @@ -29,11 +24,7 @@ import { NoDataAlert } from "@/components/alert/noData/alert"; import { error } from "console"; import { UnAuthorizedAlert } from "@/components/alert/unauthorized/alert"; -export default async function Portfolio({ - params, -}: { - params: { uid: string }; -}) { +export default async function Portfolio({ params }: { params: { uid: string } }) { const supabase = createSupabaseClient(); // if user hasn't invest in anything const hasInvestments = await checkForInvest(supabase, params.uid); @@ -44,15 +35,11 @@ export default async function Portfolio({ ); } - const { data: deals, error: investorDealError } = await getInvestorDeal( - supabase, - params.uid - ); + const { data: deals, error: investorDealError } = await getInvestorDeal(supabase, params.uid); if (investorDealError) { console.error(investorDealError); } - const { data: localUser, error: localUserError } = - await supabase.auth.getUser(); + const { data: localUser, error: localUserError } = await supabase.auth.getUser(); if (localUserError) { console.error("Error while fetching user" + error); } @@ -76,15 +63,9 @@ export default async function Portfolio({ const tagCount = countTags(tags); // console.log(investedBusinessIds); const businessType = deals - ? await Promise.all( - deals.map( - async (item) => await getBusinessTypeName(supabase, item.project_id) - ) - ) + ? await Promise.all(deals.map(async (item) => await getBusinessTypeName(supabase, item.project_id))) : []; - const countedBusinessType = countValues( - businessType.filter((item) => item !== null) - ); + const countedBusinessType = countValues(businessType.filter((item) => item !== null)); // console.log(countedBusinessType); // console.log(tagCount); @@ -103,9 +84,7 @@ export default async function Portfolio({ */} {/* */}
-

- Welcome to your Portfolio, {username}! -

+

Welcome to your Portfolio, {username}!

Here‘s an overview of your investment journey and progress.

@@ -125,9 +104,7 @@ export default async function Portfolio({ - - Monthly Investment Trend - + Monthly Investment Trend @@ -135,8 +112,7 @@ export default async function Portfolio({

- Displays total investments each month over the past 12{" "} -
+ Displays total investments each month over the past 12
months, up to today.

@@ -144,20 +120,14 @@ export default async function Portfolio({
- +
- - Yearly Investment Summary - + Yearly Investment Summary @@ -165,8 +135,7 @@ export default async function Portfolio({

- Shows total investments for each of the last four years,{" "} -
+ Shows total investments for each of the last four years,
including the current year to date.

@@ -174,20 +143,14 @@ export default async function Portfolio({
- +
- - Daily Investment Breakdown - + Daily Investment Breakdown @@ -195,8 +158,7 @@ export default async function Portfolio({

- Illustrates total investments for each day over the past{" "} -
+ Illustrates total investments for each day over the past
year, up to today.

@@ -204,11 +166,7 @@ export default async function Portfolio({
- +
@@ -217,9 +175,7 @@ export default async function Portfolio({
- - Categories of Invested Projects - + Categories of Invested Projects @@ -236,21 +192,15 @@ export default async function Portfolio({ item.count - )} - labels={tagCount.map( - (item: { name: string; count: number }) => item.name - )} + data={tagCount.map((item: { name: string; count: number }) => item.count)} + labels={tagCount.map((item: { name: string; count: number }) => item.name)} header="Total" /> - - Types of Businesses Invested In - + Types of Businesses Invested In @@ -258,8 +208,7 @@ export default async function Portfolio({

- Shows the breakdown of business types in your portfolio,{" "} -
+ Shows the breakdown of business types in your portfolio,
illustrating sector diversity.

@@ -276,9 +225,7 @@ export default async function Portfolio({
- - Recent investment - + Recent investment diff --git a/src/lib/data/investmentQuery.ts b/src/lib/data/investmentQuery.ts index bf8b349..da17b3b 100644 --- a/src/lib/data/investmentQuery.ts +++ b/src/lib/data/investmentQuery.ts @@ -29,3 +29,11 @@ export const getInvestmentByUserId = (client: SupabaseClient, userId: string) => ) .eq("investor_id", userId); }; + +export function getInvestorDeal(client: SupabaseClient, userId: string) { + return client + .from("investment_deal") + .select("*") + .in("investor_id", [userId]) + .order("created_time", { ascending: true }); +}