diff --git a/src/app/(investment)/deals/[id]/page.tsx b/src/app/(investment)/deals/[id]/page.tsx index 9001daa..a84ee65 100644 --- a/src/app/(investment)/deals/[id]/page.tsx +++ b/src/app/(investment)/deals/[id]/page.tsx @@ -14,6 +14,7 @@ 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(); @@ -28,13 +29,13 @@ export default async function ProjectDealPage({ params }: { params: { id: number return
Error
; } - console.log(projectData); - const projectBusinessOwnerId = projectData.user_id; - // console.log(projectBusinessOwnerId); - const dealData = await getDealList(projectBusinessOwnerId); - // console.log(dealData); - + 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)); + console.log(hourLeft) const carouselData = [ { src: "/boiler1.jpg", alt: "Boiler 1" }, { src: "/boiler1.jpg", alt: "Boiler 1" }, @@ -95,27 +96,33 @@ export default async function ProjectDealPage({ params }: { params: { id: number
{/* #TODO use sum() instead of storing total in database */} -

${projectData?.total_investment}

+

${totalDealAmount}

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

-

{dealData ? dealData.length: 0}

+

{dealList.length}

Investors

-

1 hours

-

Left to invest

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

{Math.floor(hourLeft)} hours

+

Left to invest

+ + ) : ( +

No deadline

+ )}