diff --git a/src/app/(investment)/deals/[id]/page.tsx b/src/app/(investment)/deals/[id]/page.tsx index 0bb363d..15398c3 100644 --- a/src/app/(investment)/deals/[id]/page.tsx +++ b/src/app/(investment)/deals/[id]/page.tsx @@ -15,6 +15,7 @@ import FollowShareButtons from "./followShareButton"; import { getProjectData } from "@/lib/data/projectQuery"; import { getDealList } from "@/app/api/dealApi"; import { sumByKey, toPercentage } from "@/lib/utils"; +import { redirect } from "next/navigation"; export default async function ProjectDealPage({ params }: { params: { id: number } }) { const supabase = createSupabaseClient(); @@ -22,18 +23,25 @@ export default async function ProjectDealPage({ params }: { params: { id: number const { data: projectData, error: projectDataError } = await getProjectData(supabase, params.id); if (!projectData) { - return
No data available
; + redirect("/deals"); } if (projectDataError) { - return
Error
; + return ( +
+

Error fetching data. Please try again.

+ +
+ ); } 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 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({ @@ -94,8 +102,8 @@ export default async function ProjectDealPage({ params }: { params: { id: number

${totalDealAmount}

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

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

{Math.floor(hourLeft)} hours

-

Left to invest

- - ) : ( -

No deadline

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

{Math.floor(hourLeft)} hours

+

Left to invest

+ + ) : ( +

No deadline

)}