mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-19 05:54:06 +01:00
feat: add logo URL fetching for investment deals and update recent funds component
This commit is contained in:
parent
a007a649f0
commit
2d67eedc59
@ -1,6 +1,22 @@
|
||||
import { SupabaseClient } from "@supabase/supabase-js";
|
||||
import { getProjectTag, getTagName } from "@/lib/data/tagQuery";
|
||||
|
||||
async function fetchLogoURL(supabase: SupabaseClient, projectId: number) {
|
||||
const logoIndex = 1;
|
||||
let { data: project_material, error } = await supabase
|
||||
.from("project_material")
|
||||
.select("material_url")
|
||||
.eq("project_id", projectId)
|
||||
.eq("material_type_id", logoIndex);
|
||||
if (error) {
|
||||
console.error("Error while fetching golo url" + error);
|
||||
}
|
||||
if (project_material && project_material.length > 0) {
|
||||
return project_material[0].material_url;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function getTotalInvestment(deals: { deal_amount: number }[]) {
|
||||
let total = 0;
|
||||
for (let index = 0; index < deals.length; index++) {
|
||||
@ -20,10 +36,12 @@ async function getLatestInvestment(
|
||||
if (error) {
|
||||
console.error(error);
|
||||
}
|
||||
let url = fetchLogoURL(supabase, deals[i].project_id);
|
||||
llist.push({
|
||||
name: project?.[0]?.project_name,
|
||||
amount: deals[i].deal_amount,
|
||||
date: new Date(deals[i].created_time),
|
||||
logo_url: url,
|
||||
});
|
||||
}
|
||||
|
||||
@ -234,4 +252,5 @@ export {
|
||||
checkForInvest,
|
||||
getLatestInvestment,
|
||||
getTotalInvestment,
|
||||
fetchLogoURL,
|
||||
};
|
||||
|
||||
@ -57,9 +57,17 @@ export default async function Portfolio({ params }: { params: { uid: string } })
|
||||
const fourYearData = deals ? fourYearGraphData(deals) : [];
|
||||
const dayOfWeekData = deals ? dayOftheWeekData(deals) : [];
|
||||
const tags = deals ? await getInvestorProjectTag(supabase, deals) : [];
|
||||
const latestDeals = deals ? await getLatestInvestment(supabase, deals) : [];
|
||||
const latestDeals = deals
|
||||
? await Promise.all(
|
||||
(await getLatestInvestment(supabase, deals)).map(async (deal) => ({
|
||||
...deal,
|
||||
logo_url: await deal.logo_url,
|
||||
}))
|
||||
)
|
||||
: [];
|
||||
const totalInvestment = deals ? getTotalInvestment(deals) : 0;
|
||||
// console.log(latestDeals);
|
||||
|
||||
const tagCount = countTags(tags);
|
||||
// console.log(investedBusinessIds);
|
||||
const businessType = deals
|
||||
|
||||
@ -5,12 +5,12 @@ export type RecentDealData = {
|
||||
deal_amount: number;
|
||||
investor_id: string;
|
||||
username: string;
|
||||
avatar_url?: string;
|
||||
logo_url?: string;
|
||||
// email: string;
|
||||
};
|
||||
|
||||
interface RecentFundsProps {
|
||||
data?: { name?: string; amount?: number; avatar?: string; date?: Date }[];
|
||||
data?: { name?: string; amount?: number; avatar?: string; date?: Date; logo_url?: string }[];
|
||||
}
|
||||
|
||||
export function RecentFunds(props: RecentFundsProps) {
|
||||
@ -19,7 +19,7 @@ export function RecentFunds(props: RecentFundsProps) {
|
||||
{(props?.data || []).map((deal, index) => (
|
||||
<div className="flex items-center" key={index}>
|
||||
<Avatar className="h-9 w-9">
|
||||
<AvatarImage src={deal.avatar} alt={deal.name} />
|
||||
<AvatarImage src={deal.logo_url} alt={deal.name} />
|
||||
<AvatarFallback>{(deal.name ?? "").slice(0, 2)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="ml-4 space-y-1">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user