feat: prevent access removal if user has paid for a product

This commit is contained in:
swve 2024-11-03 00:56:52 +01:00
parent 0e97580747
commit cdd893ca6f
7 changed files with 40 additions and 17 deletions

View file

@ -7,7 +7,7 @@ import useSWR from 'swr'
import { getOwnedCourses } from '@services/payments/payments'
import CourseThumbnail from '@components/Objects/Thumbnails/CourseThumbnail'
import PageLoading from '@components/Objects/Loaders/PageLoading'
import { BookOpen } from 'lucide-react'
import { BookOpen, Package2 } from 'lucide-react'
function OwnedCoursesPage() {
const org = useOrg() as any
@ -24,9 +24,14 @@ function OwnedCoursesPage() {
return (
<div className="h-full w-full bg-[#f8f8f8] pl-10 pr-10 pt-5 ">
<div className="flex flex-col bg-gray-50 -space-y-1 px-5 py-3 rounded-md mb-6">
<h1 className="font-bold text-xl text-gray-800">My Courses</h1>
<h2 className="text-gray-500 text-md">Courses you have purchased or subscribed to</h2>
<div className="flex flex-col bg-white nice-shadow px-5 py-3 rounded-md mb-6">
<div className="flex items-center gap-4">
<Package2 className="w-8 h-8 text-gray-800" />
<div className="flex flex-col -space-y-1">
<h1 className="font-bold text-xl text-gray-800">My Courses</h1>
<h2 className="text-gray-500 text-md">Courses you have purchased or subscribed to</h2>
</div>
</div>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4 w-full">

View file

@ -55,12 +55,12 @@ function PaymentsProductPage() {
}, [paymentConfigs]);
const handleArchiveProduct = async (productId: string) => {
try {
await archiveProduct(org.id, productId, session.data?.tokens?.access_token);
mutate([`/payments/${org.id}/products`, session.data?.tokens?.access_token]);
const res = await archiveProduct(org.id, productId, session.data?.tokens?.access_token);
mutate([`/payments/${org.id}/products`, session.data?.tokens?.access_token]);
if (res.status === 200) {
toast.success('Product archived successfully');
} catch (error) {
toast.error('Failed to archive product');
} else {
toast.error(res.data.detail);
}
}
@ -77,7 +77,7 @@ function PaymentsProductPage() {
return (
<div className="h-full w-full bg-[#f8f8f8]">
<div className="pl-10 pr-10 mx-auto">
<Modal
isDialogOpen={isCreateModalOpen}
@ -185,9 +185,8 @@ function PaymentsProductPage() {
<div className="flex justify-center items-center py-10">
<button
onClick={() => setIsCreateModalOpen(true)}
className={`mb-4 flex items-center space-x-2 px-3 py-1.5 rounded-lg bg-gradient-to-bl text-white font-medium from-gray-700 to-gray-900 border border-gray-600 shadow-gray-900/20 nice-shadow transition duration-300 ${
isStripeEnabled ? 'hover:from-gray-600 hover:to-gray-800' : 'opacity-50 cursor-not-allowed'
}`}
className={`mb-4 flex items-center space-x-2 px-3 py-1.5 rounded-lg bg-gradient-to-bl text-white font-medium from-gray-700 to-gray-900 border border-gray-600 shadow-gray-900/20 nice-shadow transition duration-300 ${isStripeEnabled ? 'hover:from-gray-600 hover:to-gray-800' : 'opacity-50 cursor-not-allowed'
}`}
disabled={!isStripeEnabled}
>
<Plus size={18} />

View file

@ -1,3 +1,4 @@
'use server';
import { getAPIUrl } from '@services/config/config';
import { RequestBodyWithAuthHeader, errorHandling } from '@services/utils/ts/requests';

View file

@ -1,3 +1,4 @@
'use server';
import { getAPIUrl } from '@services/config/config';
import { RequestBodyWithAuthHeader, getResponseMetadata } from '@services/utils/ts/requests';