From aaad0d9931bf6cfc183abe30c11f20f3e9e5847b Mon Sep 17 00:00:00 2001 From: austinkelsay Date: Tue, 10 Sep 2024 18:15:12 -0500 Subject: [PATCH] Fix small issue with subscription button flows, got started on paid course cleanup --- .../SubscriptionPaymentButton.js | 2 -- .../content/courses/CourseLesson.js | 26 ++++++++++++++++--- .../profile/subscription/SubscribeModal.js | 7 ++++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/components/bitcoinConnect/SubscriptionPaymentButton.js b/src/components/bitcoinConnect/SubscriptionPaymentButton.js index 87c8e39..27be3c9 100644 --- a/src/components/bitcoinConnect/SubscriptionPaymentButton.js +++ b/src/components/bitcoinConnect/SubscriptionPaymentButton.js @@ -73,14 +73,12 @@ const SubscriptionPaymentButtons = ({ onSuccess, onError, onRecurringSubscriptio const handlePaymentSuccess = async (response) => { console.log('Payment successful', response); - clearInterval(checkPaymentInterval); showToast('success', 'Payment Successful', 'Your payment has been processed successfully.'); if (onSuccess) onSuccess(response); }; const handlePaymentError = async (error) => { console.error('Payment error', error); - clearInterval(checkPaymentInterval); showToast('error', 'Payment Failed', `An error occurred during payment: ${error.message}`); if (onError) onError(error); }; diff --git a/src/components/content/courses/CourseLesson.js b/src/components/content/courses/CourseLesson.js index f6cfc3d..9d510d3 100644 --- a/src/components/content/courses/CourseLesson.js +++ b/src/components/content/courses/CourseLesson.js @@ -16,10 +16,17 @@ const MDDisplay = dynamic( const CourseLesson = ({ lesson, course }) => { const [zapAmount, setZapAmount] = useState(0); - + const [paidResource, setPaidResource] = useState(false); + const [decryptedContent, setDecryptedContent] = useState(false); const { zaps, zapsLoading, zapsError } = useZapsQuery({ event: lesson, type: "lesson" }); const { returnImageProxy } = useImageProxy(); + useEffect(() => { + if (course.price) { + setPaidResource(true); + } + }, [course]); + useEffect(() => { if (!zaps || zapsLoading || zapsError) return; @@ -28,6 +35,19 @@ const CourseLesson = ({ lesson, course }) => { setZapAmount(total); }, [zaps, zapsLoading, zapsError, lesson]); + const renderContent = () => { + if (decryptedContent) { + return ; + } + if (paidResource && !decryptedContent) { + return

This content is paid and needs to be purchased before viewing.

; + } + if (lesson?.content) { + return ; + } + return null; + } + return (
@@ -91,9 +111,7 @@ const CourseLesson = ({ lesson, course }) => {
- { - lesson?.content && - } + {renderContent()}
) diff --git a/src/components/profile/subscription/SubscribeModal.js b/src/components/profile/subscription/SubscribeModal.js index de1dfd7..6a60097 100644 --- a/src/components/profile/subscription/SubscribeModal.js +++ b/src/components/profile/subscription/SubscribeModal.js @@ -78,6 +78,11 @@ const SubscribeModal = ({ user }) => { } }; + const onHide = () => { + setVisible(false); + setIsProcessing(false); + } + const menuItems = [ { label: "Renew Subscription", @@ -147,7 +152,7 @@ const SubscribeModal = ({ user }) => { setVisible(false)} + onHide={onHide} className="p-fluid pb-0 w-fit" > {isProcessing ? (