Fix small issue with subscription button flows, got started on paid course cleanup

This commit is contained in:
austinkelsay 2024-09-10 18:15:12 -05:00
parent b686f613b7
commit aaad0d9931
3 changed files with 28 additions and 7 deletions

View File

@ -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);
};

View File

@ -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 <MDDisplay className='p-4 rounded-lg w-full' source={decryptedContent} />;
}
if (paidResource && !decryptedContent) {
return <p className="text-center text-xl text-red-500">This content is paid and needs to be purchased before viewing.</p>;
}
if (lesson?.content) {
return <MDDisplay className='p-4 rounded-lg w-full' source={lesson.content} />;
}
return null;
}
return (
<div className='w-full px-24 pt-12 mx-auto mt-4 max-tab:px-0 max-mob:px-0 max-tab:pt-2 max-mob:pt-2'>
<div className='w-full flex flex-row justify-between max-tab:flex-col max-mob:flex-col'>
@ -91,9 +111,7 @@ const CourseLesson = ({ lesson, course }) => {
</div>
</div>
<div className='w-[75vw] mx-auto mt-12 p-12 border-t-2 border-gray-300 max-tab:p-0 max-mob:p-0 max-tab:max-w-[100vw] max-mob:max-w-[100vw]'>
{
lesson?.content && <MDDisplay className='p-4 rounded-lg' source={lesson.content} />
}
{renderContent()}
</div>
</div>
)

View File

@ -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 }) => {
<Dialog
header="Subscribe to PlebDevs"
visible={visible}
onHide={() => setVisible(false)}
onHide={onHide}
className="p-fluid pb-0 w-fit"
>
{isProcessing ? (