"use client"; import { Price, Product, SourceModal } from "@/types"; import { createCheckoutSession, isAuthenticated } from "@/app/actions"; import { toast } from "react-toastify"; import { useRouter } from "next/navigation"; import Icon from "@/components/Icons/Icon"; export default function PriceCard({ product, isAnnual, loading, }: { product?: Product; isAnnual?: boolean; loading?: boolean; }) { const router = useRouter(); const openSignUpModalOnPriceClick = (price: Price, type: string) => { const signUpModal = document.getElementById("sign-up-modal"); if (!signUpModal) return; signUpModal.click(); }; const generateCheckoutPage = async (price: Price, type: string) => { try { const checkoutSessionResponse = await createCheckoutSession( price.price_id, type ); console.log(checkoutSessionResponse); router.push(checkoutSessionResponse.url); } catch (error) { if (error instanceof Error) { toast.error(error.message, { position: "bottom-left", autoClose: 5000, hideProgressBar: false, closeOnClick: true, pauseOnHover: true, draggable: true, progress: undefined, theme: "colored", }); } } }; const submitForm = async (product: Product) => { const userIsAuthenticated = await isAuthenticated(); console.log("userIsAuthenticated", userIsAuthenticated); const price = isAnnual ? product.yearlyPrice : product.monthlyPrice; console.log("price", price); console.log("product.type", product.type); localStorage.setItem("price", JSON.stringify(price)); localStorage.setItem("type", product.type); if (userIsAuthenticated) { await generateCheckoutPage(price, product.type); } else { openSignUpModalOnPriceClick(price, product.type); } }; return (
$30 off for the first 5 customers{" "} (4 left)
)}{x}
per user per {isAnnual ? "year" : "month"}
) : (One Time
)}