From 71d1d3c1fcc38e27014a6d17e64b9dc5ac007cd9 Mon Sep 17 00:00:00 2001 From: Naytitorn Chaovirachot Date: Fri, 1 Nov 2024 22:28:01 +0700 Subject: [PATCH] connect deal data of detail page to database --- src/app/(investment)/deals/[id]/page.tsx | 31 +++++++++++++++--------- src/app/dashboard/page.tsx | 7 ------ src/lib/utils.ts | 5 ++++ 3 files changed, 24 insertions(+), 19 deletions(-) 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

+ )}