diff --git a/src/app/(investment)/invest/[id]/checkoutPage.tsx b/src/app/(investment)/invest/[id]/checkoutPage.tsx index 7c6bbb4..0563e6a 100644 --- a/src/app/(investment)/invest/[id]/checkoutPage.tsx +++ b/src/app/(investment)/invest/[id]/checkoutPage.tsx @@ -83,12 +83,11 @@ const CheckoutPage = ({ const supabase = createSupabaseClient(); const { data, error } = await supabase.from("investment_deal").insert([ { - investorId: investor_id, - projectId: project_id, - dealAmount: amount, + investor_id: investor_id, + project_id: project_id, + deal_amount: amount, }, ]); - console.log("ADADSADWADWWAD"); if (error) { console.error("Supabase Insert Error:", error.message); diff --git a/src/app/(investment)/invest/[id]/page.tsx b/src/app/(investment)/invest/[id]/page.tsx index 1409243..04dc0d2 100644 --- a/src/app/(investment)/invest/[id]/page.tsx +++ b/src/app/(investment)/invest/[id]/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { useParams } from "next/navigation"; import { Separator } from "@/components/ui/separator"; @@ -52,13 +52,26 @@ const term_data = [ export default function InvestPage() { const [checkedTerms, setCheckedTerms] = useState(Array(term_data.length).fill(false)); const [investAmount, setInvestAmount] = useState(10); - - const { session } = useSession(); - const investor_id = session!.user.id; + 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) => {