diff --git a/lib/features/mailbox/presentation/mailbox_controller.dart b/lib/features/mailbox/presentation/mailbox_controller.dart index ef528eb31a..9b7fc72a5c 100644 --- a/lib/features/mailbox/presentation/mailbox_controller.dart +++ b/lib/features/mailbox/presentation/mailbox_controller.dart @@ -490,7 +490,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM _openMailboxEventController.add(OpenMailboxViewEvent(context, presentationMailboxSelected)); } - void goToCreateNewMailboxView(BuildContext context, PresentationMailbox? parentMailbox) async { + void goToCreateNewMailboxView(BuildContext context, {PresentationMailbox? parentMailbox}) async { final accountId = mailboxDashBoardController.accountId.value; final session = mailboxDashBoardController.sessionCurrent; if (session !=null && accountId != null) { @@ -953,7 +953,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM emptySpamAction(context, mailbox, mailboxDashBoardController); break; case MailboxActions.newSubfolder: - goToCreateNewMailboxView(context, mailbox); + goToCreateNewMailboxView(context, parentMailbox: mailbox); break; default: break; diff --git a/lib/features/mailbox/presentation/mailbox_view.dart b/lib/features/mailbox/presentation/mailbox_view.dart index 11975db51d..c432d9272d 100644 --- a/lib/features/mailbox/presentation/mailbox_view.dart +++ b/lib/features/mailbox/presentation/mailbox_view.dart @@ -249,7 +249,7 @@ class MailboxView extends BaseMailboxView { colorFilter: AppColor.colorTextButton.asFilter(), fit: BoxFit.fill), tooltip: AppLocalizations.of(context).new_mailbox, - onTap: () => controller.goToCreateNewMailboxView(context, null)), + onTap: () => controller.goToCreateNewMailboxView(context)), ]), ]), ), diff --git a/lib/features/mailbox/presentation/mailbox_view_web.dart b/lib/features/mailbox/presentation/mailbox_view_web.dart index c49d681b12..f30f0eeaa9 100644 --- a/lib/features/mailbox/presentation/mailbox_view_web.dart +++ b/lib/features/mailbox/presentation/mailbox_view_web.dart @@ -171,7 +171,7 @@ class MailboxView extends BaseMailboxView { colorFilter: AppColor.colorTextButton.asFilter(), fit: BoxFit.fill), tooltip: AppLocalizations.of(context).new_mailbox, - onTap: () => controller.goToCreateNewMailboxView(context, null)), + onTap: () => controller.goToCreateNewMailboxView(context)), ], )), ]), diff --git a/lib/features/search/mailbox/presentation/search_mailbox_bindings.dart b/lib/features/search/mailbox/presentation/search_mailbox_bindings.dart index fe45e026d0..92fa3dfb94 100644 --- a/lib/features/search/mailbox/presentation/search_mailbox_bindings.dart +++ b/lib/features/search/mailbox/presentation/search_mailbox_bindings.dart @@ -13,6 +13,7 @@ import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart'; import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_isolate_worker.dart'; import 'package:tmail_ui_user/features/mailbox/data/repository/mailbox_repository_impl.dart'; import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart'; +import 'package:tmail_ui_user/features/mailbox/domain/usecases/create_new_mailbox_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/delete_multiple_mailbox_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/move_mailbox_interactor.dart'; @@ -38,6 +39,7 @@ class SearchMailboxBindings extends BaseBindings { Get.find(), Get.find(), Get.find(), + Get.find(), Get.find(), Get.find(), Get.find(), diff --git a/lib/features/search/mailbox/presentation/search_mailbox_controller.dart b/lib/features/search/mailbox/presentation/search_mailbox_controller.dart index 77a2622930..d99b33d7ca 100644 --- a/lib/features/search/mailbox/presentation/search_mailbox_controller.dart +++ b/lib/features/search/mailbox/presentation/search_mailbox_controller.dart @@ -12,6 +12,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; +import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.dart'; +import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:jmap_dart_client/jmap/core/session/session.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:model/email/presentation_email.dart'; @@ -21,6 +23,7 @@ import 'package:tmail_ui_user/features/base/base_mailbox_controller.dart'; import 'package:debounce_throttle/debounce_throttle.dart'; import 'package:tmail_ui_user/features/base/mixin/mailbox_action_handler_mixin.dart'; import 'package:tmail_ui_user/features/email/domain/model/move_action.dart'; +import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_request.dart'; import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_action_state.dart'; import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_state.dart'; import 'package:tmail_ui_user/features/mailbox/domain/model/move_mailbox_request.dart'; @@ -28,6 +31,7 @@ import 'package:tmail_ui_user/features/mailbox/domain/model/rename_mailbox_reque import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_mailbox_request.dart'; import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_multiple_mailbox_request.dart'; import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_request.dart'; +import 'package:tmail_ui_user/features/mailbox/domain/state/create_new_mailbox_state.dart'; import 'package:tmail_ui_user/features/mailbox/domain/state/delete_multiple_mailbox_state.dart'; import 'package:tmail_ui_user/features/mailbox/domain/state/get_all_mailboxes_state.dart'; import 'package:tmail_ui_user/features/mailbox/domain/state/mark_as_mailbox_read_state.dart'; @@ -37,6 +41,7 @@ import 'package:tmail_ui_user/features/mailbox/domain/state/rename_mailbox_state import 'package:tmail_ui_user/features/mailbox/domain/state/search_mailbox_state.dart'; import 'package:tmail_ui_user/features/mailbox/domain/state/subscribe_mailbox_state.dart'; import 'package:tmail_ui_user/features/mailbox/domain/state/subscribe_multiple_mailbox_state.dart'; +import 'package:tmail_ui_user/features/mailbox/domain/usecases/create_new_mailbox_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/delete_multiple_mailbox_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/move_mailbox_interactor.dart'; @@ -51,13 +56,18 @@ import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_action import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/utils/mailbox_utils.dart'; import 'package:tmail_ui_user/features/mailbox_creator/domain/usecases/verify_name_interactor.dart'; +import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/mailbox_creator_arguments.dart'; +import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/new_mailbox_arguments.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/dashboard_routes.dart'; import 'package:tmail_ui_user/features/search/mailbox/presentation/search_mailbox_bindings.dart'; import 'package:tmail_ui_user/features/thread/domain/model/search_query.dart'; import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; +import 'package:tmail_ui_user/main/routes/app_routes.dart'; +import 'package:tmail_ui_user/main/routes/dialog_router.dart'; import 'package:tmail_ui_user/main/routes/route_navigation.dart'; import 'package:jmap_dart_client/jmap/core/state.dart' as jmap; +import 'package:uuid/uuid.dart'; class SearchMailboxController extends BaseMailboxController with MailboxActionHandlerMixin { @@ -67,11 +77,13 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa final DeleteMultipleMailboxInteractor _deleteMultipleMailboxInteractor; final SubscribeMailboxInteractor _subscribeMailboxInteractor; final SubscribeMultipleMailboxInteractor _subscribeMultipleMailboxInteractor; + final CreateNewMailboxInteractor _createNewMailboxInteractor; final dashboardController = Get.find(); final responsiveUtils = Get.find(); final imagePaths = Get.find(); final _appToast = Get.find(); + final _uuid = Get.find(); final currentSearchQuery = RxString(''); final listMailboxSearched = RxList(); @@ -89,6 +101,7 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa this._deleteMultipleMailboxInteractor, this._subscribeMailboxInteractor, this._subscribeMultipleMailboxInteractor, + this._createNewMailboxInteractor, TreeBuilder treeBuilder, VerifyNameInteractor verifyNameInteractor, GetAllMailboxInteractor getAllMailboxInteractor, @@ -112,6 +125,8 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa super.handleFailureViewState(failure); if (failure is SearchMailboxFailure) { _handleSearchMailboxFailure(failure); + } else if (failure is CreateNewMailboxFailure) { + _createNewMailboxFailure(failure); } } @@ -151,6 +166,8 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa _handleSubscribeMultipleMailboxAllSuccess(success); } else if (success is SubscribeMultipleMailboxHasSomeSuccess) { _handleSubscribeMultipleMailboxHasSomeSuccess(success); + } else if (success is CreateNewMailboxSuccess) { + _createNewMailboxSuccess(success); } } @@ -297,6 +314,9 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa case MailboxActions.emptySpam: emptySpamAction(context, mailbox, dashboardController); break; + case MailboxActions.newSubfolder: + goToCreateNewMailboxView(context, parentMailbox: mailbox); + break; default: break; } @@ -622,6 +642,60 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa } } + void goToCreateNewMailboxView(BuildContext context, {PresentationMailbox? parentMailbox}) async { + final accountId = dashboardController.accountId.value; + final session = dashboardController.sessionCurrent; + if (session != null && accountId != null) { + final arguments = MailboxCreatorArguments( + accountId, + defaultMailboxTree.value, + personalMailboxTree.value, + teamMailboxesTree.value, + dashboardController.sessionCurrent!, + parentMailbox + ); + + final result = PlatformInfo.isWeb + ? await DialogRouter.pushGeneralDialog(routeName: AppRoutes.mailboxCreator, arguments: arguments) + : await push(AppRoutes.mailboxCreator, arguments: arguments); + + if (result != null && result is NewMailboxArguments) { + final generateCreateId = Id(_uuid.v1()); + _createNewMailboxAction(session, accountId, CreateNewMailboxRequest( + generateCreateId, + result.newName, + parentId: result.mailboxLocation?.id)); + } + } + } + + void _createNewMailboxAction(Session session, AccountId accountId, CreateNewMailboxRequest request) async { + consumeState(_createNewMailboxInteractor.execute(session, accountId, request)); + } + + void _createNewMailboxSuccess(CreateNewMailboxSuccess success) { + if (currentOverlayContext != null && currentContext != null) { + _appToast.showToastSuccessMessage( + currentOverlayContext!, + AppLocalizations.of(currentContext!).createFolderSuccessfullyMessage(success.newMailbox.name?.name ?? ''), + leadingSVGIconColor: Colors.white, + leadingSVGIcon: imagePaths.icFolderMailbox); + } + + _refreshMailboxChanges(mailboxState: success.currentMailboxState); + } + + void _createNewMailboxFailure(CreateNewMailboxFailure failure) { + if (currentOverlayContext != null && currentContext != null) { + final exception = failure.exception; + var messageError = AppLocalizations.of(currentContext!).create_new_mailbox_failure; + if (exception is ErrorMethodResponse) { + messageError = exception.description ?? AppLocalizations.of(currentContext!).create_new_mailbox_failure; + } + _appToast.showToastErrorMessage(currentOverlayContext!, messageError); + } + } + void clearAllTextInputSearchForm() { textInputSearchController.clear(); currentSearchQuery.value = '';