mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-20 14:34:05 +01:00
refactor: redirect when no project data
This commit is contained in:
parent
5f1c99cb00
commit
5636abc609
@ -15,6 +15,7 @@ import FollowShareButtons from "./followShareButton";
|
|||||||
import { getProjectData } from "@/lib/data/projectQuery";
|
import { getProjectData } from "@/lib/data/projectQuery";
|
||||||
import { getDealList } from "@/app/api/dealApi";
|
import { getDealList } from "@/app/api/dealApi";
|
||||||
import { sumByKey, toPercentage } from "@/lib/utils";
|
import { sumByKey, toPercentage } from "@/lib/utils";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
export default async function ProjectDealPage({ params }: { params: { id: number } }) {
|
export default async function ProjectDealPage({ params }: { params: { id: number } }) {
|
||||||
const supabase = createSupabaseClient();
|
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);
|
const { data: projectData, error: projectDataError } = await getProjectData(supabase, params.id);
|
||||||
|
|
||||||
if (!projectData) {
|
if (!projectData) {
|
||||||
return <div>No data available</div>;
|
redirect("/deals");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (projectDataError) {
|
if (projectDataError) {
|
||||||
return <div>Error</div>;
|
return (
|
||||||
|
<div className="container max-w-screen-xl my-5">
|
||||||
|
<p className="text-red-600">Error fetching data. Please try again.</p>
|
||||||
|
<Button className="mt-4" onClick={() => window.location.reload()}>
|
||||||
|
Refresh
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const projectBusinessOwnerId = projectData.user_id;
|
const projectBusinessOwnerId = projectData.user_id;
|
||||||
const dealList = await getDealList(projectBusinessOwnerId);
|
const dealList = await getDealList(projectBusinessOwnerId);
|
||||||
const totalDealAmount = sumByKey(dealList, "deal_amount");
|
const totalDealAmount = sumByKey(dealList, "deal_amount");
|
||||||
// timeDiff, if negative convert to zero
|
// 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 hourLeft = Math.floor(timeDiff / (1000 * 60 * 60));
|
||||||
|
|
||||||
const carouselData = Array(5).fill({
|
const carouselData = Array(5).fill({
|
||||||
@ -94,8 +102,8 @@ export default async function ProjectDealPage({ params }: { params: { id: number
|
|||||||
<span>
|
<span>
|
||||||
<h1 className="font-semibold text-xl md:text-4xl mt-8">${totalDealAmount}</h1>
|
<h1 className="font-semibold text-xl md:text-4xl mt-8">${totalDealAmount}</h1>
|
||||||
<p className="text-sm md:text-lg">
|
<p className="text-sm md:text-lg">
|
||||||
{toPercentage(totalDealAmount, projectData?.target_investment)}%
|
{toPercentage(totalDealAmount, projectData?.target_investment)}% raised of $
|
||||||
raised of ${projectData?.target_investment} max goal
|
{projectData?.target_investment} max goal
|
||||||
</p>
|
</p>
|
||||||
<Progress
|
<Progress
|
||||||
value={toPercentage(totalDealAmount, projectData?.target_investment)}
|
value={toPercentage(totalDealAmount, projectData?.target_investment)}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user