"use client"; import React, { useEffect } from "react"; import PageHeader from "@/sections/PageHeader"; import { Price, Product, SourceModal } from "@/types"; import { Check } from "@styled-icons/entypo/Check"; import { ChangeEventHandler, useState } from "react"; import { apiPrices } from "./actions"; import Newsletter from "@/sections/Newsletter/Newsletter"; import { createCheckoutSession, isAuthenticated } from "@/app/(auth)/actions"; import { toast } from "react-toastify"; import { useRouter } from "next/navigation"; export default function PricingPage() { const [isAnnual, setIsAnnual] = useState(false); const [products, setProducts] = useState([]); const handleToggle = () => { setIsAnnual((prev) => !prev); }; useEffect(() => { (async () => { const resposeProducts: Product[] = await apiPrices(); setProducts(resposeProducts); })(); }, []); return ( <> {" "}

Select a subscription plan for your team or try advanced functionality for free.

} />
{products.map((x, i) => ( ))}
); } function PriceCard({ product, isAnnual, }: { product: Product; isAnnual: boolean; }) { const router = useRouter(); const openSignUpModalOnPriceClick = (price: Price) => { const signUpModal = document.getElementById("sign-up-modal"); if (!signUpModal) return; signUpModal.setAttribute("price_id", price.price_id); signUpModal.setAttribute("name", SourceModal.SignUpViaPurchase); signUpModal.click(); }; const generateCheckoutPage = async (price: Price) => { try { const checkoutSessionResponse = await createCheckoutSession( price.price_id ); 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 (price: Price) => { const userIsAuthenticated = await isAuthenticated(); if (userIsAuthenticated) { await generateCheckoutPage(price); } else { openSignUpModalOnPriceClick(price); } }; return (
{false && (

Popular

)}

{product.name}

{product.description}

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

  • ))}

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

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

); } function PriceToggle({ isAnnual, onChange, }: { isAnnual: boolean; onChange?: ChangeEventHandler; }) { return ( <> ); }