fix: missing getInvestorDeal function

This commit is contained in:
Sosokker 2024-11-04 11:50:12 +07:00
parent 2db77b80a5
commit 00c6b847e7
2 changed files with 31 additions and 76 deletions

View File

@ -1,6 +1,6 @@
import { Overview } from "@/components/ui/overview"; import { Overview } from "@/components/ui/overview";
import { createSupabaseClient } from "@/lib/supabase/serverComponentClient"; import { createSupabaseClient } from "@/lib/supabase/serverComponentClient";
import { getInvestorDeal } from "@/lib/data/query"; import { getInvestorDeal } from "@/lib/data/investmentQuery";
import PieChart from "@/components/pieChart"; import PieChart from "@/components/pieChart";
import { import {
overAllGraphData, overAllGraphData,
@ -16,12 +16,7 @@ import {
} from "./hook"; } from "./hook";
import CountUpComponent from "@/components/countUp"; import CountUpComponent from "@/components/countUp";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { RecentFunds } from "@/components/recent-funds"; import { RecentFunds } from "@/components/recent-funds";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import QuestionMarkIcon from "@/components/icon/questionMark"; import QuestionMarkIcon from "@/components/icon/questionMark";
@ -29,11 +24,7 @@ import { NoDataAlert } from "@/components/alert/noData/alert";
import { error } from "console"; import { error } from "console";
import { UnAuthorizedAlert } from "@/components/alert/unauthorized/alert"; import { UnAuthorizedAlert } from "@/components/alert/unauthorized/alert";
export default async function Portfolio({ export default async function Portfolio({ params }: { params: { uid: string } }) {
params,
}: {
params: { uid: string };
}) {
const supabase = createSupabaseClient(); const supabase = createSupabaseClient();
// if user hasn't invest in anything // if user hasn't invest in anything
const hasInvestments = await checkForInvest(supabase, params.uid); const hasInvestments = await checkForInvest(supabase, params.uid);
@ -44,15 +35,11 @@ export default async function Portfolio({
</div> </div>
); );
} }
const { data: deals, error: investorDealError } = await getInvestorDeal( const { data: deals, error: investorDealError } = await getInvestorDeal(supabase, params.uid);
supabase,
params.uid
);
if (investorDealError) { if (investorDealError) {
console.error(investorDealError); console.error(investorDealError);
} }
const { data: localUser, error: localUserError } = const { data: localUser, error: localUserError } = await supabase.auth.getUser();
await supabase.auth.getUser();
if (localUserError) { if (localUserError) {
console.error("Error while fetching user" + error); console.error("Error while fetching user" + error);
} }
@ -76,15 +63,9 @@ export default async function Portfolio({
const tagCount = countTags(tags); const tagCount = countTags(tags);
// console.log(investedBusinessIds); // console.log(investedBusinessIds);
const businessType = deals const businessType = deals
? await Promise.all( ? await Promise.all(deals.map(async (item) => await getBusinessTypeName(supabase, item.project_id)))
deals.map(
async (item) => await getBusinessTypeName(supabase, item.project_id)
)
)
: []; : [];
const countedBusinessType = countValues( const countedBusinessType = countValues(businessType.filter((item) => item !== null));
businessType.filter((item) => item !== null)
);
// console.log(countedBusinessType); // console.log(countedBusinessType);
// console.log(tagCount); // console.log(tagCount);
@ -103,9 +84,7 @@ export default async function Portfolio({
</div> */} </div> */}
{/* <CountUpComponent end={100} duration={3} /> */} {/* <CountUpComponent end={100} duration={3} /> */}
<div className="text-center py-4"> <div className="text-center py-4">
<h1 className="text-2xl font-semibold"> <h1 className="text-2xl font-semibold">Welcome to your Portfolio, {username}!</h1>
Welcome to your Portfolio, {username}!
</h1>
<p className="text-lg text-muted-foreground"> <p className="text-lg text-muted-foreground">
Here&lsquo;s an overview of your investment journey and progress. Here&lsquo;s an overview of your investment journey and progress.
</p> </p>
@ -125,9 +104,7 @@ export default async function Portfolio({
<TabsContent value="monthly"> <TabsContent value="monthly">
<Card className="w-full"> <Card className="w-full">
<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-md font-bold"> <CardTitle className="text-md font-bold">Monthly Investment Trend</CardTitle>
Monthly Investment Trend
</CardTitle>
<TooltipProvider> <TooltipProvider>
<Tooltip> <Tooltip>
<TooltipTrigger> <TooltipTrigger>
@ -135,8 +112,7 @@ export default async function Portfolio({
</TooltipTrigger> </TooltipTrigger>
<TooltipContent> <TooltipContent>
<p> <p>
Displays total investments each month over the past 12{" "} Displays total investments each month over the past 12 <br />
<br />
months, up to today. months, up to today.
</p> </p>
</TooltipContent> </TooltipContent>
@ -144,20 +120,14 @@ export default async function Portfolio({
</TooltipProvider> </TooltipProvider>
</CardHeader> </CardHeader>
<CardContent className="mt-5"> <CardContent className="mt-5">
<Overview <Overview graphType="line" data={overAllData} graphHeight={500}></Overview>
graphType="line"
data={overAllData}
graphHeight={500}
></Overview>
</CardContent> </CardContent>
</Card> </Card>
</TabsContent> </TabsContent>
<TabsContent value="yearly"> <TabsContent value="yearly">
<Card className="w-full"> <Card className="w-full">
<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-md font-bold"> <CardTitle className="text-md font-bold">Yearly Investment Summary</CardTitle>
Yearly Investment Summary
</CardTitle>
<TooltipProvider> <TooltipProvider>
<Tooltip> <Tooltip>
<TooltipTrigger> <TooltipTrigger>
@ -165,8 +135,7 @@ export default async function Portfolio({
</TooltipTrigger> </TooltipTrigger>
<TooltipContent> <TooltipContent>
<p> <p>
Shows total investments for each of the last four years,{" "} Shows total investments for each of the last four years, <br />
<br />
including the current year to date. including the current year to date.
</p> </p>
</TooltipContent> </TooltipContent>
@ -174,20 +143,14 @@ export default async function Portfolio({
</TooltipProvider> </TooltipProvider>
</CardHeader> </CardHeader>
<CardContent className="mt-5"> <CardContent className="mt-5">
<Overview <Overview graphType="bar" data={fourYearData} graphHeight={500}></Overview>
graphType="bar"
data={fourYearData}
graphHeight={500}
></Overview>
</CardContent> </CardContent>
</Card> </Card>
</TabsContent> </TabsContent>
<TabsContent value="daily"> <TabsContent value="daily">
<Card className="w-full"> <Card className="w-full">
<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-md font-bold"> <CardTitle className="text-md font-bold">Daily Investment Breakdown</CardTitle>
Daily Investment Breakdown
</CardTitle>
<TooltipProvider> <TooltipProvider>
<Tooltip> <Tooltip>
<TooltipTrigger> <TooltipTrigger>
@ -195,8 +158,7 @@ export default async function Portfolio({
</TooltipTrigger> </TooltipTrigger>
<TooltipContent> <TooltipContent>
<p> <p>
Illustrates total investments for each day over the past{" "} Illustrates total investments for each day over the past <br />
<br />
year, up to today. year, up to today.
</p> </p>
</TooltipContent> </TooltipContent>
@ -204,11 +166,7 @@ export default async function Portfolio({
</TooltipProvider> </TooltipProvider>
</CardHeader> </CardHeader>
<CardContent className="mt-5"> <CardContent className="mt-5">
<Overview <Overview graphType="bar" data={dayOfWeekData} graphHeight={500}></Overview>
graphType="bar"
data={dayOfWeekData}
graphHeight={500}
></Overview>
</CardContent> </CardContent>
</Card> </Card>
</TabsContent> </TabsContent>
@ -217,9 +175,7 @@ export default async function Portfolio({
<div className="flex flex-cols-3 w-full gap-5 mt-5"> <div className="flex flex-cols-3 w-full gap-5 mt-5">
<Card className="w-1/3"> <Card className="w-1/3">
<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-md font-bold"> <CardTitle className="text-md font-bold">Categories of Invested Projects</CardTitle>
Categories of Invested Projects
</CardTitle>
<TooltipProvider> <TooltipProvider>
<Tooltip> <Tooltip>
<TooltipTrigger> <TooltipTrigger>
@ -236,21 +192,15 @@ export default async function Portfolio({
</CardHeader> </CardHeader>
<CardContent className="mt-5"> <CardContent className="mt-5">
<PieChart <PieChart
data={tagCount.map( data={tagCount.map((item: { name: string; count: number }) => item.count)}
(item: { name: string; count: number }) => item.count labels={tagCount.map((item: { name: string; count: number }) => item.name)}
)}
labels={tagCount.map(
(item: { name: string; count: number }) => item.name
)}
header="Total" header="Total"
/> />
</CardContent> </CardContent>
</Card> </Card>
<Card className="w-1/3"> <Card className="w-1/3">
<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-md font-bold"> <CardTitle className="text-md font-bold">Types of Businesses Invested In</CardTitle>
Types of Businesses Invested In
</CardTitle>
<TooltipProvider> <TooltipProvider>
<Tooltip> <Tooltip>
<TooltipTrigger> <TooltipTrigger>
@ -258,8 +208,7 @@ export default async function Portfolio({
</TooltipTrigger> </TooltipTrigger>
<TooltipContent> <TooltipContent>
<p> <p>
Shows the breakdown of business types in your portfolio,{" "} Shows the breakdown of business types in your portfolio, <br />
<br />
illustrating sector diversity. illustrating sector diversity.
</p> </p>
</TooltipContent> </TooltipContent>
@ -276,9 +225,7 @@ export default async function Portfolio({
</Card> </Card>
<Card className="w-1/3"> <Card className="w-1/3">
<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-md font-bold"> <CardTitle className="text-md font-bold">Recent investment</CardTitle>
Recent investment
</CardTitle>
</CardHeader> </CardHeader>
<CardContent className="mt-5"> <CardContent className="mt-5">
<RecentFunds data={latestDeals} /> <RecentFunds data={latestDeals} />

View File

@ -29,3 +29,11 @@ export const getInvestmentByUserId = (client: SupabaseClient, userId: string) =>
) )
.eq("investor_id", userId); .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 });
}