Skip to content

Commit 9a84f12

Browse files
dab246hoangdat
authored andcommitted
TF-3985 Allow retry get paywall url when paywall is not available
1 parent fa2d304 commit 9a84f12

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ class MailboxDashBoardController extends ReloadableController
309309
int minInputLengthAutocomplete = AppConfig.defaultMinInputLengthAutocomplete;
310310
EmailSortOrderType currentSortOrder = SearchEmailFilter.defaultSortOrder;
311311
PaywallUrlPattern? paywallUrlPattern;
312+
bool isRetryGetPaywallUrl = false;
312313

313314
final StreamController<Either<Failure, Success>> _progressStateController =
314315
StreamController<Either<Failure, Success>>.broadcast();
@@ -551,6 +552,8 @@ class MailboxDashBoardController extends ReloadableController
551552
tryGetAuthenticatedAccountToUseApp();
552553
} else if (isGetTokenOIDCFailure(failure)) {
553554
backToHomeScreen();
555+
} else if (failure is GetPaywallUrlFailure) {
556+
loadPaywallUrlFailure();
554557
} else {
555558
super.handleFailureViewState(failure);
556559
}

lib/features/mailbox_dashboard/presentation/extensions/handle_paywall_extension.dart

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import 'package:core/presentation/extensions/color_extension.dart';
12
import 'package:flutter/material.dart';
3+
import 'package:flutter_svg/flutter_svg.dart';
24
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
35
import 'package:tmail_ui_user/features/paywall/domain/model/paywall_url_pattern.dart';
46
import 'package:tmail_ui_user/features/paywall/domain/usecases/get_paywall_url_interactor.dart';
@@ -7,7 +9,7 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';
79
import 'package:tmail_ui_user/main/routes/route_utils.dart';
810
import 'package:tmail_ui_user/main/utils/app_utils.dart';
911

10-
extension ValidateSaasPremiumAvailableExtension on MailboxDashBoardController {
12+
extension HandlePaywallExtension on MailboxDashBoardController {
1113
bool validatePremiumIsAvailable() {
1214
if (accountId.value == null || sessionCurrent == null) {
1315
return false;
@@ -26,19 +28,56 @@ extension ValidateSaasPremiumAvailableExtension on MailboxDashBoardController {
2628
consumeState(getPaywallUrlInteractor.execute(jmapUrl));
2729
} else {
2830
paywallUrlPattern = null;
31+
if (isRetryGetPaywallUrl) {
32+
_showMessagePaywallUrlNotAvailable();
33+
isRetryGetPaywallUrl = false;
34+
}
2935
}
3036
}
3137

3238
void loadPaywallUrlSuccess(PaywallUrlPattern newPattern) {
3339
paywallUrlPattern = newPattern;
3440
}
3541

42+
void loadPaywallUrlFailure() {
43+
paywallUrlPattern = null;
44+
if (isRetryGetPaywallUrl) {
45+
_showMessagePaywallUrlNotAvailable();
46+
isRetryGetPaywallUrl = false;
47+
}
48+
}
49+
50+
void _showMessagePaywallUrlNotAvailable({BuildContext? context}) {
51+
final overlayContext = context ?? currentOverlayContext;
52+
AppLocalizations? appLocalizations;
53+
if (context != null) {
54+
appLocalizations = AppLocalizations.of(context);
55+
} else if (currentContext != null) {
56+
appLocalizations = AppLocalizations.of(currentContext!);
57+
}
58+
59+
if (overlayContext == null || appLocalizations == null) return;
60+
61+
appToast.showToastMessage(
62+
overlayContext,
63+
appLocalizations.paywallUrlNotAvailable,
64+
actionName: appLocalizations.retry,
65+
onActionClick: _handleRetryGetPaywallUrl,
66+
leadingSVGIcon: imagePaths.icQuotasWarning,
67+
leadingSVGIconColor: Colors.white,
68+
backgroundColor: AppColor.toastErrorBackgroundColor,
69+
textColor: Colors.white,
70+
actionIcon: SvgPicture.asset(
71+
imagePaths.icRefreshQuotas,
72+
colorFilter: Colors.white.asFilter(),
73+
),
74+
duration: const Duration(seconds: 5),
75+
);
76+
}
77+
3678
void navigateToPaywall(BuildContext context) {
3779
if (paywallUrlPattern == null) {
38-
appToast.showToastErrorMessage(
39-
context,
40-
AppLocalizations.of(context).paywallUrlNotAvailable,
41-
);
80+
_showMessagePaywallUrlNotAvailable(context: context);
4281
return;
4382
}
4483

@@ -49,4 +88,9 @@ extension ValidateSaasPremiumAvailableExtension on MailboxDashBoardController {
4988

5089
AppUtils.launchLink(qualifiedPaywall);
5190
}
91+
92+
void _handleRetryGetPaywallUrl() {
93+
isRetryGetPaywallUrl = true;
94+
loadPaywallUrl();
95+
}
5296
}

0 commit comments

Comments
 (0)