"use client"; import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { useParams } from "next/navigation"; import { Separator } from "@/components/ui/separator"; import { Input } from "@/components/ui/input"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { useQuery } from "@supabase-cache-helpers/postgrest-react-query"; import convertToSubcurrency from "@/lib/convertToSubcurrency"; import CheckoutPage from "./checkoutPage"; import { Elements } from "@stripe/react-stripe-js"; import { loadStripe } from "@stripe/stripe-js"; import { getProjectDataQuery } from "@/lib/data/projectQuery"; import { createSupabaseClient } from "@/lib/supabase/clientComponentClient"; import useSession from "@/lib/supabase/useSession"; if (process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY === undefined) { throw new Error("NEXT_PUBLIC_STRIPE_PUBLIC_KEY is not defined"); } const stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY); const term_data = [ { term: "Minimum Investment", description: "The minimum investment amount is $500.", }, { term: "Investment Horizon", description: "Investments are typically locked for a minimum of 12 months.", }, { term: "Fees", description: "A management fee of 2% will be applied annually.", }, { term: "Returns", description: "Expected annual returns are between 8% and 12%.", }, { term: "Risk Disclosure", description: "Investments carry risks, including the loss of principal.", }, { term: "Withdrawal Policy", description: "Withdrawals can be made after the lock-in period.", }, ]; export default function InvestPage() { const [checkedTerms, setCheckedTerms] = useState(Array(term_data.length).fill(false)); const [investAmount, setInvestAmount] = useState(10); const [investor_id, setInvestorId] = useState(""); const params = useParams<{ id: string }>(); const supabase = createSupabaseClient(); useEffect(() => { const fetchInvestorData = async () => { const { data, error } = await supabase.auth.getSession(); if (error) { console.error("Error fetching session:", error); return; } if (data.session) { setInvestorId(data.session.user.id); } }; fetchInvestorData(); }, [supabase]); const { data: projectData, isLoading: isLoadingProject } = useQuery(getProjectDataQuery(supabase, Number(params.id))); const handleCheckboxChange = (index: number) => { const updatedCheckedTerms = [...checkedTerms]; updatedCheckedTerms[index] = !updatedCheckedTerms[index]; setCheckedTerms(updatedCheckedTerms); }; const isAcceptTermAndService = () => { if (checkedTerms.some((checked) => !checked)) { return false; } return true; }; return (

Invest on ${projectData?.project_name}

Investment Amount

setInvestAmount(Number(e.currentTarget.value))} />

Terms and Services

Select Term Description {term_data.map((item, index) => ( handleCheckboxChange(index)} /> {item.term} {item.description} ))}

Payment Information

); }