fix: hide Storage section in settings menu when quota is empty

This commit is contained in:
dab246
2025-10-22 15:20:55 +07:00
committed by Dat H. Pham
parent 2f9e6d61c9
commit 7f5c48cbe3
10 changed files with 128 additions and 96 deletions
@@ -1,12 +1,9 @@
import 'package:get/get.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/storage/storage_controller.dart';
import 'package:tmail_ui_user/features/quotas/domain/use_case/get_quotas_interactor.dart';
import 'package:tmail_ui_user/features/quotas/presentation/quotas_interactor_bindings.dart';
class StorageBindings extends Bindings {
@override
void dependencies() {
QuotasInteractorBindings().dependencies();
Get.lazyPut(() => StorageController(Get.find<GetQuotasInteractor>()));
Get.lazyPut(() => StorageController());
}
}
@@ -1,50 +1,12 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/quotas/quota.dart';
import 'package:tmail_ui_user/features/base/base_controller.dart';
import 'package:tmail_ui_user/features/home/data/exceptions/session_exceptions.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/manage_account_dashboard_controller.dart';
import 'package:tmail_ui_user/features/paywall/presentation/saas_premium_mixin.dart';
import 'package:tmail_ui_user/features/quotas/domain/extensions/list_quotas_extensions.dart';
import 'package:tmail_ui_user/features/quotas/domain/state/get_quotas_state.dart';
import 'package:tmail_ui_user/features/quotas/domain/use_case/get_quotas_interactor.dart';
class StorageController extends BaseController with SaaSPremiumMixin {
final dashBoardController = Get.find<ManageAccountDashBoardController>();
final GetQuotasInteractor _getQuotasInteractor;
final octetsQuota = Rxn<Quota>();
StorageController(this._getQuotasInteractor);
@override
void onReady() {
final accountId = dashBoardController.accountId.value;
if (accountId != null) {
_getQuotasAction(accountId);
} else {
consumeState(
Stream.value(
Left(GetQuotasFailure(NotFoundAccountIdException())),
),
);
}
super.onReady();
}
void _getQuotasAction(AccountId accountId) {
consumeState(_getQuotasInteractor.execute(accountId));
}
void _handleGetQuotasSuccess(GetQuotasSuccess success) {
octetsQuota.value = success.quotas.octetsQuota;
}
bool validatePremiumIsAvailable() {
final accountId = dashBoardController.accountId.value;
final session = dashBoardController.sessionCurrent;
@@ -58,25 +20,4 @@ class StorageController extends BaseController with SaaSPremiumMixin {
void onUpgradeStorage(BuildContext context) {
dashBoardController.paywallController?.navigateToPaywall(context);
}
bool get isLoading => viewState.value
.fold((failure) => false, (success) => success is GetQuotasLoading);
@override
void handleSuccessViewState(Success success) {
if (success is GetQuotasSuccess) {
_handleGetQuotasSuccess(success);
} else {
super.handleSuccessViewState(success);
}
}
@override
void handleFailureViewState(Failure failure) {
if (failure is GetQuotasFailure) {
octetsQuota.value = null;
} else {
super.handleFailureViewState(failure);
}
}
}
@@ -3,7 +3,6 @@ import 'package:core/utils/platform_info.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart';
import 'package:tmail_ui_user/features/base/widget/circle_loading_widget.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/base/setting_detail_view_builder.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/menu/settings_utils.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/model/account_menu_item.dart';
@@ -61,23 +60,13 @@ class StorageView extends GetWidget<StorageController> with AppLoaderMixin {
isCenter: true,
textAlign: TextAlign.center,
),
Obx(() {
if (!controller.isLoading) {
return const SizedBox.shrink();
}
return Center(
child: Padding(
padding: SettingsUtils.getSettingProgressBarPadding(
context,
controller.responsiveUtils,
),
child: const CircleLoadingWidget(),
),
);
}),
Expanded(
child: Obx(() {
final octetsQuota = controller.octetsQuota.value;
final octetsQuota = controller
.dashBoardController
.octetsQuota
.value;
if (octetsQuota != null && octetsQuota.storageAvailable) {
return SingleChildScrollView(
child: Padding(