From 4d98a54da4e43d8b2223dbbf85ca5bf0700d5b41 Mon Sep 17 00:00:00 2001 From: James Wyndham Date: Thu, 29 Feb 2024 09:05:02 +0800 Subject: [PATCH] bugfix - fixed button press issue --- Frontend/app/(auth)/actions.ts | 24 ++++++++++++------- Frontend/components/Header.tsx | 1 + Frontend/components/PriceCard.tsx | 6 ++++- Frontend/sections/AccountContent.tsx | 2 +- .../Hero/WaitingListWithImageHero.tsx | 2 +- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Frontend/app/(auth)/actions.ts b/Frontend/app/(auth)/actions.ts index 87378de..d746186 100644 --- a/Frontend/app/(auth)/actions.ts +++ b/Frontend/app/(auth)/actions.ts @@ -188,6 +188,16 @@ export async function createCheckoutSession(price_id: string, type: string) { } console.log('token', token); console.log('url ', `${pocketbaseUrl}/create-checkout-session`); + + const body = JSON.stringify({ + price: { + id: price_id, + type: type + }, + quantity: 1 + }); + console.log('body',body); + try{ const createCheckoutSessionResponse = await fetch( `${pocketbaseUrl}/create-checkout-session`, @@ -197,20 +207,18 @@ export async function createCheckoutSession(price_id: string, type: string) { "Content-Type": "application/json", Authorization: token, }, - body: JSON.stringify({ - price: { - id: price_id, - type: type - }, - quantity: 1 - }), + body: body, } ); - console.log('createCheckoutSessionResponse.status', createCheckoutSessionResponse.status) if (createCheckoutSessionResponse.status !== 200) { throw new Error("Failed to process Request"); } + const createCheckoutSessionData: CheckoutSession = await createCheckoutSessionResponse.json(); + + if (createCheckoutSessionData.url === "") { + throw new Error("Failed to process request an invalid URL was served"); + } return createCheckoutSessionData; } catch (error) { throw error; diff --git a/Frontend/components/Header.tsx b/Frontend/components/Header.tsx index 4ded34c..c8afdcc 100644 --- a/Frontend/components/Header.tsx +++ b/Frontend/components/Header.tsx @@ -112,6 +112,7 @@ export default function Header({ isUserLoggedIn }: HeaderProps) { document.getElementById("sign-up-modal")?.click(); }} className={`btn btn-primary btn-sm text-primary-content`} + id="sign-up-modal-button" > Sign Up diff --git a/Frontend/components/PriceCard.tsx b/Frontend/components/PriceCard.tsx index d52dd31..4d46c3f 100644 --- a/Frontend/components/PriceCard.tsx +++ b/Frontend/components/PriceCard.tsx @@ -1,3 +1,5 @@ +"use client"; + import { Price, Product, SourceModal } from "@/types"; import { createCheckoutSession, isAuthenticated } from "@/app/(auth)/actions"; import { toast } from "react-toastify"; @@ -15,7 +17,7 @@ export default function PriceCard({ }) { const router = useRouter(); const openSignUpModalOnPriceClick = (price: Price, type: string) => { - const signUpModal = document.getElementById("sign-up-modal"); + const signUpModal = document.getElementById("sign-up-modal-button"); if (!signUpModal) return; signUpModal.setAttribute("price_id", price.price_id); signUpModal.setAttribute("type", type); @@ -28,6 +30,7 @@ export default function PriceCard({ price.price_id, type ); + console.log(checkoutSessionResponse); router.push(checkoutSessionResponse.url); } catch (error) { if (error instanceof Error) { @@ -46,6 +49,7 @@ export default function PriceCard({ }; const submitForm = async (product: Product) => { const userIsAuthenticated = await isAuthenticated(); + console.log("userIsAuthenticated", userIsAuthenticated); const price = isAnnual ? product.yearlyPrice : product.monthlyPrice; if (userIsAuthenticated) { await generateCheckoutPage(price, product.type); diff --git a/Frontend/sections/AccountContent.tsx b/Frontend/sections/AccountContent.tsx index d75accf..4c3efc1 100644 --- a/Frontend/sections/AccountContent.tsx +++ b/Frontend/sections/AccountContent.tsx @@ -174,7 +174,7 @@ function AccountContent({ user }: ManageSubscriptionProps) { diff --git a/Frontend/sections/Hero/WaitingListWithImageHero.tsx b/Frontend/sections/Hero/WaitingListWithImageHero.tsx index f481137..cc9ab94 100644 --- a/Frontend/sections/Hero/WaitingListWithImageHero.tsx +++ b/Frontend/sections/Hero/WaitingListWithImageHero.tsx @@ -45,7 +45,7 @@ const WaitingListWithImageHero = () => { return (
-
+

{title}