import React, { useState, useRef, useEffect } from 'react'; import { useSession } from 'next-auth/react'; import { useRouter } from 'next/router'; import { useToast } from '@/hooks/useToast'; import axios from 'axios'; import { Card } from 'primereact/card'; import { Message } from 'primereact/message'; import useWindowWidth from '@/hooks/useWindowWidth'; import { Menu } from "primereact/menu"; import GenericButton from '@/components/buttons/GenericButton'; import { ProgressSpinner } from 'primereact/progressspinner'; import SubscriptionPaymentButtons from '@/components/bitcoinConnect/SubscriptionPaymentButton'; const Subscribe = () => { const { data: session, update } = useSession(); const { showToast } = useToast(); const router = useRouter(); const windowWidth = useWindowWidth(); const [isProcessing, setIsProcessing] = useState(false); const [subscribed, setSubscribed] = useState(false); const [subscribedUntil, setSubscribedUntil] = useState(null); const [subscriptionExpiredAt, setSubscriptionExpiredAt] = useState(null); const menu = useRef(null); useEffect(() => { if (session && session?.user) { setSubscribed(session?.user.role.subscribed); const subscribedAt = new Date(session?.user.role.lastPaymentAt); const subscribedUntil = new Date(subscribedAt.getTime() + 31 * 24 * 60 * 60 * 1000); setSubscribedUntil(subscribedUntil); if (session?.user.role.subscriptionExpiredAt) { const expiredAt = new Date(session?.user.role.subscriptionExpiredAt) setSubscriptionExpiredAt(expiredAt); } } }, [session, session?.user]); const handleSubscriptionSuccess = async (paymentResponse) => { setIsProcessing(true); try { const response = await axios.post('/api/subscription/create', { paymentResponse, }); if (response.data.success) { showToast('success', 'Subscription successful!'); await update(); router.push('/dashboard'); } else { showToast('error', 'Subscription failed. Please try again.'); } } catch (error) { console.error('Subscription error:', error); showToast('error', 'An error occurred. Please try again.'); } finally { setIsProcessing(false); } }; const handleSubscriptionError = (error) => { console.error('Subscription error:', error); showToast('error', 'An error occurred during subscription. Please try again.'); }; const handleRecurringSubscriptionSuccess = async (paymentResponse) => { setIsProcessing(true); try { const response = await axios.post('/api/subscription/recurring', { paymentResponse, }); if (response.data.success) { showToast('success', 'Recurring subscription set up successfully!'); await update(); router.push('/dashboard'); } else { showToast('error', 'Failed to set up recurring subscription. Please try again.'); } } catch (error) { console.error('Recurring subscription error:', error); showToast('error', 'An error occurred. Please try again.'); } finally { setIsProcessing(false); } }; const menuItems = [ { label: "Renew Subscription", icon: "pi pi-bolt", command: () => { // Add your renew functionality here }, }, { label: "Schedule 1:1", icon: "pi pi-calendar", command: () => { // Add your schedule functionality here }, }, { label: "Cancel Subscription", icon: "pi pi-trash", command: () => { // Add your cancel functionality here }, }, ]; const subscriptionCardTitleAndButton = (
Thank you for your support 🎉
Pay-as-you-go subscription will renew on {subscribedUntil.toLocaleDateString()}
The plebdevs subscription is a monthly subscription that unlocks all of the paid content, grants you access to the plebdevs 1:1 calendar for tutoring, support, and mentorship, and gives you an exclusive invite to the pleblab bitcoin hackerspace community.
The plebdevs subscription is Lightning only and you can subscribe a month at a time with the pay as you go option or easily setup an auto recurring monthly subscription using Nostr Wallet Connect.
Login to start your subscription
Get access to all PlebDevs features / content one month at a time.
Setup auto recurring monthly payments for uninterrupted access.
Our subscription provides monthly access to all PlebDevs features. You can choose between a one-time payment or a recurring subscription.
Yes, you can cancel your subscription at any time. Your access will remain active until the end of the current billing period.