diff --git a/frontend/src/container/BillingContainer/BillingContainer.test.tsx b/frontend/src/container/BillingContainer/BillingContainer.test.tsx index 8354bdff99..b433959384 100644 --- a/frontend/src/container/BillingContainer/BillingContainer.test.tsx +++ b/frontend/src/container/BillingContainer/BillingContainer.test.tsx @@ -51,14 +51,12 @@ describe('BillingContainer', () => { expect(cost).toBeInTheDocument(); const dayRemainingInBillingPeriod = await screen.findByText( - /11 days_remaining/i, + /Please upgrade plan now to retain your data./i, ); expect(dayRemainingInBillingPeriod).toBeInTheDocument(); - const manageBilling = screen.getByRole('button', { - name: 'manage_billing', - }); - expect(manageBilling).toBeInTheDocument(); + const upgradePlanButton = screen.getByTestId('upgrade-plan-button'); + expect(upgradePlanButton).toBeInTheDocument(); const dollar = screen.getByText(/\$1,278.3/i); await waitFor(() => expect(dollar).toBeInTheDocument()); diff --git a/frontend/src/container/BillingContainer/BillingContainer.tsx b/frontend/src/container/BillingContainer/BillingContainer.tsx index 55e35deaa6..291528cfc5 100644 --- a/frontend/src/container/BillingContainer/BillingContainer.tsx +++ b/frontend/src/container/BillingContainer/BillingContainer.tsx @@ -202,15 +202,16 @@ export default function BillingContainer(): JSX.Element { const isSubscriptionPastDue = apiResponse.subscriptionStatus === SubscriptionStatus.PastDue; - const { isLoading, isFetching: isFetchingBillingData } = useQuery( - [REACT_QUERY_KEY.GET_BILLING_USAGE, user?.id], - { - queryFn: () => getUsage(activeLicense?.key || ''), - onError: handleError, - enabled: activeLicense !== null, - onSuccess: processUsageData, - }, - ); + const { + isLoading, + isFetching: isFetchingBillingData, + data: billingData, + } = useQuery([REACT_QUERY_KEY.GET_BILLING_USAGE, user?.id], { + queryFn: () => getUsage(activeLicense?.key || ''), + onError: handleError, + enabled: activeLicense !== null, + onSuccess: processUsageData, + }); useEffect(() => { const activeValidLicense = @@ -318,7 +319,7 @@ export default function BillingContainer(): JSX.Element { }); const handleBilling = useCallback(async () => { - if (isFreeTrial && !licenses?.trialConvertedToSubscription) { + if (!licenses?.trialConvertedToSubscription) { logEvent('Billing : Upgrade Plan', { user: pick(user, ['email', 'userId', 'name']), org, @@ -411,6 +412,12 @@ export default function BillingContainer(): JSX.Element { } }, [apiResponse, notifications]); + const showGracePeriodMessage = + !isLoading && + !licenses?.trialConvertedToSubscription && + !licenses?.onTrial && + licenses?.gracePeriodEnd; + return (
@@ -433,7 +440,8 @@ export default function BillingContainer(): JSX.Element { {isCloudUserVal ? t('teams_cloud') : t('teams')}{' '} {isFreeTrial ? Free Trial : ''} - {!isLoading && !isFetchingBillingData ? ( + + {!isLoading && !isFetchingBillingData && !showGracePeriodMessage ? ( {daysRemaining} {daysRemainingStr} @@ -451,15 +459,16 @@ export default function BillingContainer(): JSX.Element { Download CSV @@ -473,18 +482,35 @@ export default function BillingContainer(): JSX.Element { )} - {!isLoading && !isFetchingBillingData ? ( - headerText && ( - - ) - ) : ( + {!isLoading && !isFetchingBillingData && !showGracePeriodMessage + ? headerText && ( + + ) + : null} + + {isLoading || isFetchingBillingData ? ( - )} + ) : null} + + {!isLoading && + !isFetchingBillingData && + billingData && + licenses?.gracePeriodEnd && + showGracePeriodMessage ? ( + + ) : null} {isSubscriptionPastDue && (!isLoading && !isFetchingBillingData ? ( @@ -514,7 +540,7 @@ export default function BillingContainer(): JSX.Element { {(isLoading || isFetchingBillingData) && renderTableSkeleton()}
- {isFreeTrial && !licenses?.trialConvertedToSubscription && ( + {!licenses?.trialConvertedToSubscription && (