bugfix - fixed button press issue
This commit is contained in:
parent
afa4040243
commit
4d98a54da4
|
@ -188,6 +188,16 @@ export async function createCheckoutSession(price_id: string, type: string) {
|
||||||
}
|
}
|
||||||
console.log('token', token);
|
console.log('token', token);
|
||||||
console.log('url ', `${pocketbaseUrl}/create-checkout-session`);
|
console.log('url ', `${pocketbaseUrl}/create-checkout-session`);
|
||||||
|
|
||||||
|
const body = JSON.stringify({
|
||||||
|
price: {
|
||||||
|
id: price_id,
|
||||||
|
type: type
|
||||||
|
},
|
||||||
|
quantity: 1
|
||||||
|
});
|
||||||
|
console.log('body',body);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
const createCheckoutSessionResponse = await fetch(
|
const createCheckoutSessionResponse = await fetch(
|
||||||
`${pocketbaseUrl}/create-checkout-session`,
|
`${pocketbaseUrl}/create-checkout-session`,
|
||||||
|
@ -197,20 +207,18 @@ export async function createCheckoutSession(price_id: string, type: string) {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: token,
|
Authorization: token,
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: body,
|
||||||
price: {
|
|
||||||
id: price_id,
|
|
||||||
type: type
|
|
||||||
},
|
|
||||||
quantity: 1
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
console.log('createCheckoutSessionResponse.status', createCheckoutSessionResponse.status)
|
|
||||||
if (createCheckoutSessionResponse.status !== 200) {
|
if (createCheckoutSessionResponse.status !== 200) {
|
||||||
throw new Error("Failed to process Request");
|
throw new Error("Failed to process Request");
|
||||||
}
|
}
|
||||||
|
|
||||||
const createCheckoutSessionData: CheckoutSession = await createCheckoutSessionResponse.json();
|
const createCheckoutSessionData: CheckoutSession = await createCheckoutSessionResponse.json();
|
||||||
|
|
||||||
|
if (createCheckoutSessionData.url === "") {
|
||||||
|
throw new Error("Failed to process request an invalid URL was served");
|
||||||
|
}
|
||||||
return createCheckoutSessionData;
|
return createCheckoutSessionData;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
@ -112,6 +112,7 @@ export default function Header({ isUserLoggedIn }: HeaderProps) {
|
||||||
document.getElementById("sign-up-modal")?.click();
|
document.getElementById("sign-up-modal")?.click();
|
||||||
}}
|
}}
|
||||||
className={`btn btn-primary btn-sm text-primary-content`}
|
className={`btn btn-primary btn-sm text-primary-content`}
|
||||||
|
id="sign-up-modal-button"
|
||||||
>
|
>
|
||||||
Sign Up
|
Sign Up
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
import { Price, Product, SourceModal } from "@/types";
|
import { Price, Product, SourceModal } from "@/types";
|
||||||
import { createCheckoutSession, isAuthenticated } from "@/app/(auth)/actions";
|
import { createCheckoutSession, isAuthenticated } from "@/app/(auth)/actions";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
|
@ -15,7 +17,7 @@ export default function PriceCard({
|
||||||
}) {
|
}) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const openSignUpModalOnPriceClick = (price: Price, type: string) => {
|
const openSignUpModalOnPriceClick = (price: Price, type: string) => {
|
||||||
const signUpModal = document.getElementById("sign-up-modal");
|
const signUpModal = document.getElementById("sign-up-modal-button");
|
||||||
if (!signUpModal) return;
|
if (!signUpModal) return;
|
||||||
signUpModal.setAttribute("price_id", price.price_id);
|
signUpModal.setAttribute("price_id", price.price_id);
|
||||||
signUpModal.setAttribute("type", type);
|
signUpModal.setAttribute("type", type);
|
||||||
|
@ -28,6 +30,7 @@ export default function PriceCard({
|
||||||
price.price_id,
|
price.price_id,
|
||||||
type
|
type
|
||||||
);
|
);
|
||||||
|
console.log(checkoutSessionResponse);
|
||||||
router.push(checkoutSessionResponse.url);
|
router.push(checkoutSessionResponse.url);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
|
@ -46,6 +49,7 @@ export default function PriceCard({
|
||||||
};
|
};
|
||||||
const submitForm = async (product: Product) => {
|
const submitForm = async (product: Product) => {
|
||||||
const userIsAuthenticated = await isAuthenticated();
|
const userIsAuthenticated = await isAuthenticated();
|
||||||
|
console.log("userIsAuthenticated", userIsAuthenticated);
|
||||||
const price = isAnnual ? product.yearlyPrice : product.monthlyPrice;
|
const price = isAnnual ? product.yearlyPrice : product.monthlyPrice;
|
||||||
if (userIsAuthenticated) {
|
if (userIsAuthenticated) {
|
||||||
await generateCheckoutPage(price, product.type);
|
await generateCheckoutPage(price, product.type);
|
||||||
|
|
|
@ -174,7 +174,7 @@ function AccountContent({ user }: ManageSubscriptionProps) {
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={manageSubscription}
|
onClick={manageSubscription}
|
||||||
className="btn btn-neutral text-base-content capitalize border-none"
|
className="btn btn-neutral text-primary-content capitalize border-none"
|
||||||
>
|
>
|
||||||
Manage Purchases
|
Manage Purchases
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -45,7 +45,7 @@ const WaitingListWithImageHero = () => {
|
||||||
return (
|
return (
|
||||||
<Background>
|
<Background>
|
||||||
<div className="h-screen w-full bg-clip flex items-center justify-center">
|
<div className="h-screen w-full bg-clip flex items-center justify-center">
|
||||||
<div className="text-center py-8 px-4 sm:px-6 lg:px-8 bg-base-300 rounded-xl shadow-lg">
|
<div className="text-center py-8 px-4 sm:px-6 lg:px-8 bg-base-100 rounded-xl shadow-lg">
|
||||||
<h1 className=" text-3xl sm:text-6xl text-base-content font-heading whitespace-nowrap flex flex-row justify-center pb-6 gap-x-3">
|
<h1 className=" text-3xl sm:text-6xl text-base-content font-heading whitespace-nowrap flex flex-row justify-center pb-6 gap-x-3">
|
||||||
<Logo />
|
<Logo />
|
||||||
{title}
|
{title}
|
||||||
|
|
Loading…
Reference in New Issue