From 3fbf7be3ab0b8482e7e8917f65b48490d51b93bb Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 20 Nov 2023 19:23:39 +0530 Subject: [PATCH] Toggle current sub active flag based on add-on Signed-off-by: Neeraj Gupta <254676+ua741@users.noreply.github.com> --- lib/ui/payment/store_subscription_page.dart | 6 +++++- lib/ui/payment/stripe_subscription_page.dart | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/ui/payment/store_subscription_page.dart b/lib/ui/payment/store_subscription_page.dart index e544ca702..722d6d5d2 100644 --- a/lib/ui/payment/store_subscription_page.dart +++ b/lib/ui/payment/store_subscription_page.dart @@ -52,6 +52,7 @@ class _StoreSubscriptionPageState extends State { late ProgressDialog _dialog; late UserDetails _userDetails; late bool _hasActiveSubscription; + bool _hideCurrentPlanSelection = false; late FreePlan _freePlan; late List _plans; bool _hasLoadedData = false; @@ -177,7 +178,10 @@ class _StoreSubscriptionPageState extends State { _userService.getUserDetailsV2(memoryCount: false).then((userDetails) async { _userDetails = userDetails; _currentSubscription = userDetails.subscription; + _hasActiveSubscription = _currentSubscription!.isValid(); + _hideCurrentPlanSelection = + _currentSubscription?.attributes?.isCancelled ?? false; showYearlyPlan = _currentSubscription!.isYearlyPlan(); final billingPlans = await _billingService.getBillingPlans(); _isActiveStripeSubscriber = @@ -458,7 +462,7 @@ class _StoreSubscriptionPageState extends State { storage: plan.storage, price: plan.price, period: plan.period, - isActive: isActive, + isActive: isActive && !_hideCurrentPlanSelection, ), ), ), diff --git a/lib/ui/payment/stripe_subscription_page.dart b/lib/ui/payment/stripe_subscription_page.dart index b48e59f75..e205fb062 100644 --- a/lib/ui/payment/stripe_subscription_page.dart +++ b/lib/ui/payment/stripe_subscription_page.dart @@ -53,6 +53,7 @@ class _StripeSubscriptionPageState extends State { // indicates if user's subscription plan is still active late bool _hasActiveSubscription; + bool _hideCurrentPlanSelection = false; late FreePlan _freePlan; List _plans = []; bool _hasLoadedData = false; @@ -73,7 +74,11 @@ class _StripeSubscriptionPageState extends State { .then((userDetails) async { _userDetails = userDetails; _currentSubscription = userDetails.subscription; + _showYearlyPlan = _currentSubscription!.isYearlyPlan(); + _hideCurrentPlanSelection = + (_currentSubscription?.attributes?.isCancelled ?? false) && + userDetails.hasPaidAddon(); _hasActiveSubscription = _currentSubscription!.isValid(); _isStripeSubscriber = _currentSubscription!.paymentProvider == stripe; return _filterStripeForUI().then((value) { @@ -340,6 +345,9 @@ class _StripeSubscriptionPageState extends State { Widget _stripeRenewOrCancelButton() { final bool isRenewCancelled = _currentSubscription!.attributes?.isCancelled ?? false; + if (isRenewCancelled && _userDetails.hasPaidAddon()) { + return const SizedBox.shrink(); + } final String title = isRenewCancelled ? S.of(context).renewSubscription : S.of(context).cancelSubscription; @@ -503,7 +511,7 @@ class _StripeSubscriptionPageState extends State { storage: plan.storage, price: plan.price, period: plan.period, - isActive: isActive, + isActive: isActive && !_hideCurrentPlanSelection, ), ), ), @@ -594,7 +602,7 @@ class _StripeSubscriptionPageState extends State { storage: _currentSubscription!.storage, price: _currentSubscription!.price, period: _currentSubscription!.period, - isActive: true, + isActive: !_hasActiveSubscription, ), ), ),