From f86ba5cb6d7a1a786c8692b430ce5cd42717751f Mon Sep 17 00:00:00 2001 From: Mario-SO Date: Fri, 24 Jan 2025 17:05:24 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20Added=20a=20isFeatures?= =?UTF-8?q?Available=20check=20that=20includes=20stages=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../livestreams/components/CreateLivestreamModal.tsx | 2 -- .../app/app/studio/[organization]/(root)/page.tsx | 12 +++++++++--- packages/app/components/Layout/NavbarStudio.tsx | 10 ++++++++-- packages/app/lib/utils/utils.ts | 8 ++++---- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/app/app/studio/[organization]/(root)/livestreams/components/CreateLivestreamModal.tsx b/packages/app/app/studio/[organization]/(root)/livestreams/components/CreateLivestreamModal.tsx index f28c04a10..638157570 100644 --- a/packages/app/app/studio/[organization]/(root)/livestreams/components/CreateLivestreamModal.tsx +++ b/packages/app/app/studio/[organization]/(root)/livestreams/components/CreateLivestreamModal.tsx @@ -37,8 +37,6 @@ import ImageUpload from '@/components/misc/form/imageUpload'; import { Checkbox } from '@/components/ui/checkbox'; import { Label } from '@/components/ui/label'; import { LuRadio } from 'react-icons/lu'; -import { cn } from '@/lib/utils/utils'; -import FeatureButton from '@/components/ui/feature-button'; import { useSubscription } from '@/lib/hooks/useSubscription'; const CreateLivestreamModal = ({ diff --git a/packages/app/app/studio/[organization]/(root)/page.tsx b/packages/app/app/studio/[organization]/(root)/page.tsx index 569fc9ee2..2fd1351bc 100644 --- a/packages/app/app/studio/[organization]/(root)/page.tsx +++ b/packages/app/app/studio/[organization]/(root)/page.tsx @@ -24,6 +24,12 @@ export default async function OrganizationPage({ if (!organization) return notFound(); + const hasFeatures = isFeatureAvailable( + organization.expirationDate, + organization.currentStages, + organization.paidStages + ); + // Calculate the start of the current day const startOfDay = new Date(); startOfDay.setHours(0, 0, 0, 0); @@ -33,7 +39,7 @@ export default async function OrganizationPage({

Create

- {isFeatureAvailable(organization.expirationDate) ? ( + {hasFeatures ? ( )} - {isFeatureAvailable(organization.expirationDate) ? ( + {hasFeatures ? ( ) : ( )} - {isFeatureAvailable(organization.expirationDate) ? ( + {hasFeatures ? ( diff --git a/packages/app/components/Layout/NavbarStudio.tsx b/packages/app/components/Layout/NavbarStudio.tsx index abdb1b282..2f92b469c 100644 --- a/packages/app/components/Layout/NavbarStudio.tsx +++ b/packages/app/components/Layout/NavbarStudio.tsx @@ -30,6 +30,12 @@ const NavbarStudio = ({ return notFound(); } + const hasFeatures = isFeatureAvailable( + organization.expirationDate, + organization.currentStages, + organization.paidStages + ); + return (
- {isFeatureAvailable(organization.expirationDate) ? ( + {hasFeatures ? ( )} - {isFeatureAvailable(organization.expirationDate) ? ( + {hasFeatures ? ( ) : ( { - return ( - expirationDate && new Date(expirationDate).getTime() > new Date().getTime() - ); +export const isFeatureAvailable = (expirationDate: Date | null | undefined, currentStages?: number, paidStages?: number) => { + const hasValidSubscription = expirationDate && new Date(expirationDate).getTime() > new Date().getTime(); + const hasAvailableStages = typeof currentStages === 'undefined' || typeof paidStages === 'undefined' || currentStages < paidStages; + return hasValidSubscription && hasAvailableStages; }; export const selectOptionFocusHandle = ( From 6557d894dd6a81e4b43fe69a488027afa943639a Mon Sep 17 00:00:00 2001 From: Mario-SO Date: Fri, 24 Jan 2025 17:05:59 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20Added=20cache:=20no=20?= =?UTF-8?q?store=20and=20revalidate=20to=20org=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/app/lib/services/organizationService.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/app/lib/services/organizationService.tsx b/packages/app/lib/services/organizationService.tsx index e4d0ceb40..f6e0619cc 100644 --- a/packages/app/lib/services/organizationService.tsx +++ b/packages/app/lib/services/organizationService.tsx @@ -18,7 +18,11 @@ export async function fetchOrganization({ const response = await fetch( `${apiUrl()}/organizations/${ organizationId ? organizationId : organizationSlug - }` + }`, + { + cache: 'no-store', + next: { revalidate: 0 } + } ); const data = (await response.json()).data;