Add business ID and type retrieval functions; integrate into Portfolio component

This commit is contained in:
THIS ONE IS A LITTLE BIT TRICKY KRUB 2024-10-30 20:44:25 +07:00
parent 6298abe0c9
commit bbee901bce
3 changed files with 56 additions and 3 deletions

View File

@ -1,6 +1,27 @@
import { SupabaseClient } from "@supabase/supabase-js"; import { SupabaseClient } from "@supabase/supabase-js";
import { getProjectTag, getTagName } from "@/lib/data/query"; import { getProjectTag, getTagName } from "@/lib/data/query";
async function getBusinessId(supabase: SupabaseClient, projectId: number) {
let { data: project, error } = await supabase
.from("project")
.select("business_id")
.eq("id", projectId);
if (error) {
console.error(error);
}
return project?.[0]?.business_id;
}
async function getBusinessType(supabase: SupabaseClient, businessId: number) {
let { data: business, error } = await supabase
.from("business")
.select("business_type")
.eq("id", businessId);
if (error) {
console.error(error);
}
return business?.[0]?.business_type;
}
// only use deal that were made at most year ago // only use deal that were made at most year ago
interface Deal { interface Deal {
created_time: string | number | Date; created_time: string | number | Date;
@ -173,4 +194,6 @@ export {
dayOftheWeekData, dayOftheWeekData,
getInvestorProjectTag, getInvestorProjectTag,
countTags, countTags,
getBusinessId,
getBusinessType,
}; };

View File

@ -8,7 +8,10 @@ import {
dayOftheWeekData, dayOftheWeekData,
getInvestorProjectTag, getInvestorProjectTag,
countTags, countTags,
getBusinessId,
getBusinessType,
} from "./hook"; } from "./hook";
import CountUpComponent from "@/components/countUp";
export default async function Portfolio({ export default async function Portfolio({
params, params,
@ -28,16 +31,23 @@ export default async function Portfolio({
const dayOfWeekData = deals ? dayOftheWeekData(deals) : []; const dayOfWeekData = deals ? dayOftheWeekData(deals) : [];
const tags = deals ? await getInvestorProjectTag(supabase, deals) : []; const tags = deals ? await getInvestorProjectTag(supabase, deals) : [];
const tagCount = countTags(tags); const tagCount = countTags(tags);
// get business id from project id
const investedBusinessIds = deals
? await Promise.all(
deals.map(
async (item) => await getBusinessId(supabase, item.project_id)
)
)
: [];
console.log(investedBusinessIds);
// console.log(tags); // console.log(tags);
// console.log(tagCount); // console.log(tagCount);
return ( return (
<div> <div>
{/* {JSON.stringify(params.uid)} */} {/* {JSON.stringify(params.uid)} */}
{/* {JSON.stringify(tagCount)} */} {/* {JSON.stringify(tagCount)} */}
{/* {JSON.stringify(deals)} */} {JSON.stringify(deals)}
{/* {JSON.stringify(dayOfWeekData)} */} {/* {JSON.stringify(dayOfWeekData)} */}
{/* {JSON.stringify(overAllGraphData)} */} {/* {JSON.stringify(overAllGraphData)} */}
{/* {JSON.stringify(threeYearGraphData)} */} {/* {JSON.stringify(threeYearGraphData)} */}
@ -46,6 +56,7 @@ export default async function Portfolio({
<h1>Total Invest : </h1> <h1>Total Invest : </h1>
<div>{totalInvest}</div> <div>{totalInvest}</div>
</div> */} </div> */}
{/* <CountUpComponent end={100} duration={3} /> */}
<div className="flex w-full gap-10"> <div className="flex w-full gap-10">
<Overview graphType="line" data={overAllData}></Overview> <Overview graphType="line" data={overAllData}></Overview>
<Overview graphType="bar" data={fourYearData}></Overview> <Overview graphType="bar" data={fourYearData}></Overview>

View File

@ -0,0 +1,19 @@
"use client";
import CountUp from "react-countup";
interface CountUpComponentProps {
end: number;
duration: number;
}
export default function CountUpComponent(props: CountUpComponentProps) {
return (
<>
<CountUp
end={props.end}
duration={props.duration}
start={props.end / 2}
/>
</>
);
}