diff --git a/src/components/Sidebar/SubscriptionStatus/index.tsx b/src/components/Sidebar/SubscriptionStatus/index.tsx index 76d05b7a7..1bf7f314b 100644 --- a/src/components/Sidebar/SubscriptionStatus/index.tsx +++ b/src/components/Sidebar/SubscriptionStatus/index.tsx @@ -5,6 +5,7 @@ import { isFamilyAdmin, isOnFreePlan, isPartOfFamily, + hasExceededStorageQuota, isSubscriptionActive, isSubscriptionCancelled, } from 'utils/billing'; @@ -55,10 +56,12 @@ export default function SubscriptionStatus({ ? constants.FREE_SUBSCRIPTION_INFO( userDetails.subscription?.expiryTime ) - : isSubscriptionCancelled(userDetails.subscription) && - constants.RENEWAL_CANCELLED_SUBSCRIPTION_INFO( + : isSubscriptionCancelled(userDetails.subscription) + ? constants.RENEWAL_CANCELLED_SUBSCRIPTION_INFO( userDetails.subscription?.expiryTime ) + : hasExceededStorageQuota(userDetails) && + constants.STORAGE_QUOTA_EXCEEDED_SUBSCRIPTION_INFO : constants.SUBSCRIPTION_EXPIRED_MESSAGE( showPlanSelectorModal )} diff --git a/src/utils/billing/index.ts b/src/utils/billing/index.ts index 21c3b0897..7f41f95c7 100644 --- a/src/utils/billing/index.ts +++ b/src/utils/billing/index.ts @@ -8,7 +8,7 @@ import { CustomError } from '../error'; import { logError } from '../sentry'; import { SetDialogBoxAttributes } from 'types/dialogBox'; import { getFamilyPortalRedirectURL } from 'services/userService'; -import { FamilyData, FamilyMember, User } from 'types/user'; +import { FamilyData, FamilyMember, User, UserDetails } from 'types/user'; const PAYMENT_PROVIDER_STRIPE = 'stripe'; const PAYMENT_PROVIDER_APPSTORE = 'appstore'; @@ -186,6 +186,15 @@ export function hasPaypalSubscription(subscription: Subscription) { ); } +export function hasExceededStorageQuota(userDetails: UserDetails) { + if (isPartOfFamily(userDetails.familyData)) { + const usage = getTotalFamilyUsage(userDetails.familyData); + return usage > userDetails.familyData.storage; + } else { + return userDetails.usage > userDetails.subscription.storage; + } +} + export async function updateSubscription( plan: Plan, setDialogMessage: SetDialogBoxAttributes, diff --git a/src/utils/strings/englishConstants.tsx b/src/utils/strings/englishConstants.tsx index b89aed79c..a84761d60 100644 --- a/src/utils/strings/englishConstants.tsx +++ b/src/utils/strings/englishConstants.tsx @@ -264,13 +264,14 @@ const englishConstants = { FAMILY_SUBSCRIPTION_INFO: 'You are on a family plan managed by', RENEWAL_ACTIVE_SUBSCRIPTION_INFO: (expiryTime) => ( - <>Your subscription will renew on {dateString(expiryTime)} + <>Renew on {dateString(expiryTime)} ), RENEWAL_CANCELLED_SUBSCRIPTION_INFO: (expiryTime) => ( <>Your subscription will be cancelled on {dateString(expiryTime)} ), + STORAGE_QUOTA_EXCEEDED_SUBSCRIPTION_INFO: `You have exceeded your storage quota, please upgrade your plan.`, SUBSCRIPTION_PURCHASE_SUCCESS: (expiryTime) => ( <>

We've received your payment