"use client" import { createCheckoutSession, isAuthenticated } from "@/app/actions" import { toast } from "react-toastify" import { useRouter } from "next/navigation" import { CheckmarkCircle24Filled } from "@fluentui/react-icons" export default function PriceCard({ product, isAnnual, loading }) { const router = useRouter() const openSignUpModalOnPriceClick = (price, type) => { const signUpModal = document.getElementById("sign-up-modal") if (!signUpModal) return signUpModal.click() } const generateCheckoutPage = async (price, type) => { 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 => { 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 (
{!loading && (

$30 off for the first 5 customers{" "} (3 left)

)}

{product?.name}

{product?.description}

    {product?.metadata?.benefits?.map((x, i) => (
  • {x}

  • ))}
{!loading && (

$ {isAnnual ? (product?.yearlyPrice?.unit_amount ?? 0) / 100 : (product?.monthlyPrice?.unit_amount ?? 0) / 100}

{product?.type != "one_time" ? (

per user per {isAnnual ? "year" : "month"}

) : (

One Time

)}
)} {product && ( )}
) }