"use client"; import React, { useState, useEffect } from "react"; import { toast } from "react-toastify"; import { useRouter } from "next/navigation"; import { useQRCode } from "next-qrcode"; import { createManagementSubscriptionSession, getSubscriptions } from "@/app/actions"; function AccountContent({ user }) { const router = useRouter(); const { Canvas } = useQRCode(); const [subscription, setSubscription] = useState(); const [loading, setLoading] = useState(true); useEffect(() => { (async () => { if (!user) { setLoading(false); return; } try { setLoading(true); const subscriptions = await getSubscriptions(); if (subscriptions.length > 0) { setSubscription(subscriptions[0]); } setLoading(false); } catch (err) { setLoading(false); } })(); }, [user]); const manageSubscription = async () => { try { const managementSession = await createManagementSubscriptionSession(); router.push(managementSession.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", }); } } }; return loading ? (
) : ({subscription.product?.description}
> ) : ( <>{"You haven’t upgraded your workflow yet"}