diff --git a/src/app/(investment)/deals/[id]/page.tsx b/src/app/(investment)/deals/[id]/page.tsx index 6f1181a..0bb363d 100644 --- a/src/app/(investment)/deals/[id]/page.tsx +++ b/src/app/(investment)/deals/[id]/page.tsx @@ -13,24 +13,34 @@ import { createSupabaseClient } from "@/lib/supabase/serverComponentClient"; import FollowShareButtons from "./followShareButton"; import { getProjectData } from "@/lib/data/projectQuery"; +import { getDealList } from "@/app/api/dealApi"; +import { sumByKey, toPercentage } from "@/lib/utils"; export default async function ProjectDealPage({ params }: { params: { id: number } }) { const supabase = createSupabaseClient(); const { data: projectData, error: projectDataError } = await getProjectData(supabase, params.id); - const carouselData = [ - { src: "/boiler1.jpg", alt: "Boiler 1" }, - { src: "/boiler1.jpg", alt: "Boiler 1" }, - { src: "/boiler1.jpg", alt: "Boiler 1" }, - { src: "/boiler1.jpg", alt: "Boiler 1" }, - { src: "/boiler1.jpg", alt: "Boiler 1" }, - ]; + if (!projectData) { + return
No data available
; + } if (projectDataError) { return
Error
; } + const projectBusinessOwnerId = projectData.user_id; + const dealList = await getDealList(projectBusinessOwnerId); + const totalDealAmount = sumByKey(dealList, "deal_amount"); + // timeDiff, if negative convert to zero + const timeDiff = Math.max((new Date(projectData.investment_deadline)).getTime() - new Date().getTime(), 0) + const hourLeft = Math.floor(timeDiff / (1000 * 60 * 60)); + + const carouselData = Array(5).fill({ + src: projectData.card_image_url || "/boiler1.jpg", + alt: `${projectData.project_name} Image`, + }); + return (
@@ -82,24 +92,33 @@ export default async function ProjectDealPage({ params }: { params: { id: number
-

${projectData?.total_investment}

-

5% raised of \$5M max goal

+

${totalDealAmount}

+

+ {toPercentage(totalDealAmount, projectData?.target_investment)}% + raised of ${projectData?.target_investment} max goal +

-

{projectData?.total_investment}

+

{dealList.length}

-

Investors

+

Investors

-

1 hours

-

Left to invest

+ {projectData?.investment_deadline ? ( + <> +

{Math.floor(hourLeft)} hours

+

Left to invest

+ + ) : ( +

No deadline

+ )}