diff --git a/lib/features/email/presentation/email_view.dart b/lib/features/email/presentation/email_view.dart index e4823ce1c..b11ee43c7 100644 --- a/lib/features/email/presentation/email_view.dart +++ b/lib/features/email/presentation/email_view.dart @@ -70,7 +70,8 @@ class EmailView extends GetWidget with NetworkConnectionMixin { child: VacationNotificationMessageWidget( radius: 0, margin: EdgeInsets.zero, - vacationResponse: controller.mailboxDashBoardController.vacationResponse.value!), + vacationResponse: controller.mailboxDashBoardController.vacationResponse.value!, + action: () => controller.mailboxDashBoardController.disableVacationResponder()), ); } else { return const SizedBox.shrink(); diff --git a/lib/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart b/lib/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart index 8891f3426..b4327d8a3 100644 --- a/lib/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart +++ b/lib/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart @@ -74,6 +74,7 @@ import 'package:tmail_ui_user/features/manage_account/data/repository/manage_acc import 'package:tmail_ui_user/features/manage_account/domain/repository/manage_account_repository.dart'; import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_vacation_interactor.dart'; import 'package:tmail_ui_user/features/manage_account/domain/usecases/log_out_oidc_interactor.dart'; +import 'package:tmail_ui_user/features/manage_account/domain/usecases/update_vacation_interactor.dart'; import 'package:tmail_ui_user/features/thread/data/datasource/thread_datasource.dart'; import 'package:tmail_ui_user/features/thread/data/datasource_impl/local_thread_datasource_impl.dart'; import 'package:tmail_ui_user/features/thread/data/datasource_impl/thread_datasource_impl.dart'; @@ -110,6 +111,7 @@ class MailboxDashBoardBindings extends BaseBindings { Get.find(), Get.find(), Get.find(), + Get.find(), )); Get.put(AdvancedFilterController()); } @@ -192,6 +194,7 @@ class MailboxDashBoardBindings extends BaseBindings { Get.lazyPut(() => SaveComposerCacheOnWebInteractor(Get.find())); Get.lazyPut(() => RemoveComposerCacheOnWebInteractor(Get.find())); Get.lazyPut(() => GetAllVacationInteractor(Get.find())); + Get.lazyPut(() => UpdateVacationInteractor(Get.find())); } @override diff --git a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart index fdb58a985..41acd17e0 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -45,8 +45,11 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/comp import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/download/download_task_state.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/search/quick_search_filter.dart'; import 'package:tmail_ui_user/features/manage_account/domain/state/get_all_vacation_state.dart'; +import 'package:tmail_ui_user/features/manage_account/domain/state/update_vacation_state.dart'; import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_vacation_interactor.dart'; import 'package:tmail_ui_user/features/manage_account/domain/usecases/log_out_oidc_interactor.dart'; +import 'package:tmail_ui_user/features/manage_account/domain/usecases/update_vacation_interactor.dart'; +import 'package:tmail_ui_user/features/manage_account/presentation/extensions/vacation_response_extension.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/model/manage_account_arguments.dart'; import 'package:tmail_ui_user/features/thread/domain/model/filter_message_option.dart'; import 'package:tmail_ui_user/features/thread/domain/model/search_query.dart'; @@ -75,6 +78,7 @@ class MailboxDashBoardController extends ReloadableController { final MarkAsMailboxReadInteractor _markAsMailboxReadInteractor; final GetComposerCacheOnWebInteractor _getEmailCacheOnWebInteractor; final GetAllVacationInteractor _getAllVacationInteractor; + final UpdateVacationInteractor _updateVacationInteractor; final scaffoldKey = GlobalKey(); final selectedMailbox = Rxn(); @@ -112,6 +116,7 @@ class MailboxDashBoardController extends ReloadableController { this._markAsMailboxReadInteractor, this._getEmailCacheOnWebInteractor, this._getAllVacationInteractor, + this._updateVacationInteractor, ) : super(logoutOidcInteractor, deleteAuthorityOidcInteractor, getAuthenticatedAccountInteractor); @@ -221,6 +226,8 @@ class MailboxDashBoardController extends ReloadableController { if (success.listVacationResponse.isNotEmpty) { vacationResponse.value = success.listVacationResponse.first; } + } else if (success is UpdateVacationSuccess) { + _handleUpdateVacationSuccess(success); } } ); @@ -611,6 +618,28 @@ class MailboxDashBoardController extends ReloadableController { downloadController.deleteDownloadTask(taskId); } + void disableVacationResponder() { + if (accountId.value != null) { + final vacationDisabled = vacationResponse.value != null + ? vacationResponse.value!.copyWith(isEnabled: false) + : VacationResponse(isEnabled: false); + consumeState(_updateVacationInteractor.execute(accountId.value!, vacationDisabled)); + } + } + + void _handleUpdateVacationSuccess(UpdateVacationSuccess success) { + if (success.listVacationResponse.isNotEmpty) { + if (currentContext != null && currentOverlayContext != null) { + _appToast.showToastWithIcon( + currentOverlayContext!, + message: AppLocalizations.of(currentContext!).yourVacationResponderIsDisabledSuccessfully, + icon: _imagePaths.icChecked); + } + vacationResponse.value = success.listVacationResponse.first; + log('MailboxDashBoardController::_handleUpdateVacationSuccess(): $vacationResponse'); + } + } + @override void onClose() { _emailReceiveManager.closeEmailReceiveManagerStream(); diff --git a/lib/features/mailbox_dashboard/presentation/mailbox_dashboard_view_web.dart b/lib/features/mailbox_dashboard/presentation/mailbox_dashboard_view_web.dart index feeba1245..e42ac31fc 100644 --- a/lib/features/mailbox_dashboard/presentation/mailbox_dashboard_view_web.dart +++ b/lib/features/mailbox_dashboard/presentation/mailbox_dashboard_view_web.dart @@ -99,7 +99,8 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView { if (controller.vacationResponse.value?.vacationResponderIsReady == true) { return VacationNotificationMessageWidget( margin: const EdgeInsets.only(top: 16, right: 16), - vacationResponse: controller.vacationResponse.value!); + vacationResponse: controller.vacationResponse.value!, + action: () => controller.disableVacationResponder()); } else { return const SizedBox.shrink(); } diff --git a/lib/features/manage_account/presentation/manage_account_dashboard_bindings.dart b/lib/features/manage_account/presentation/manage_account_dashboard_bindings.dart index 0e29be507..2a5ae39de 100644 --- a/lib/features/manage_account/presentation/manage_account_dashboard_bindings.dart +++ b/lib/features/manage_account/presentation/manage_account_dashboard_bindings.dart @@ -27,6 +27,7 @@ import 'package:tmail_ui_user/features/manage_account/data/repository/manage_acc import 'package:tmail_ui_user/features/manage_account/domain/repository/manage_account_repository.dart'; import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_vacation_interactor.dart'; import 'package:tmail_ui_user/features/manage_account/domain/usecases/log_out_oidc_interactor.dart'; +import 'package:tmail_ui_user/features/manage_account/domain/usecases/update_vacation_interactor.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/language_and_region/language_and_region_bindings.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/manage_account_dashboard_controller.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/menu/manage_account_menu_bindings.dart'; @@ -50,7 +51,8 @@ class ManageAccountDashBoardBindings extends BaseBindings { Get.find(), Get.find(), Get.find(), - Get.find() + Get.find(), + Get.find() )); } @@ -94,6 +96,7 @@ class ManageAccountDashBoardBindings extends BaseBindings { Get.find(), )); Get.lazyPut(() => GetAllVacationInteractor(Get.find())); + Get.lazyPut(() => UpdateVacationInteractor(Get.find())); } @override diff --git a/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart b/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart index 3bbaedf1f..decd800d1 100644 --- a/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart +++ b/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart @@ -15,18 +15,26 @@ import 'package:tmail_ui_user/features/login/domain/usecases/delete_authority_oi import 'package:tmail_ui_user/features/login/domain/usecases/get_authenticated_account_interactor.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_user_profile_state.dart'; import 'package:tmail_ui_user/features/manage_account/domain/state/get_all_vacation_state.dart'; +import 'package:tmail_ui_user/features/manage_account/domain/state/update_vacation_state.dart'; import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_vacation_interactor.dart'; import 'package:tmail_ui_user/features/manage_account/domain/usecases/log_out_oidc_interactor.dart'; +import 'package:tmail_ui_user/features/manage_account/domain/usecases/update_vacation_interactor.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/email_rules/email_rules_bindings.dart'; +import 'package:tmail_ui_user/features/manage_account/presentation/extensions/vacation_response_extension.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/forward/forward_bindings.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/model/account_menu_item.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/model/manage_account_arguments.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/route_navigation.dart'; class ManageAccountDashBoardController extends ReloadableController { + final _appToast = Get.find(); + final _imagePaths = Get.find(); + final GetAllVacationInteractor _getAllVacationInteractor; + final UpdateVacationInteractor _updateVacationInteractor; final menuDrawerKey = GlobalKey(debugLabel: 'manage_account'); @@ -42,6 +50,7 @@ class ManageAccountDashBoardController extends ReloadableController { DeleteAuthorityOidcInteractor deleteAuthorityOidcInteractor, GetAuthenticatedAccountInteractor getAuthenticatedAccountInteractor, this._getAllVacationInteractor, + this._updateVacationInteractor, ) : super(logoutOidcInteractor, deleteAuthorityOidcInteractor, getAuthenticatedAccountInteractor); @@ -64,6 +73,8 @@ class ManageAccountDashBoardController extends ReloadableController { if (success.listVacationResponse.isNotEmpty) { vacationResponse.value = success.listVacationResponse.first; } + } else if (success is UpdateVacationSuccess) { + _handleUpdateVacationSuccess(success); } } ); @@ -162,4 +173,25 @@ class ManageAccountDashBoardController extends ReloadableController { bool checkAvailableForwardInSession() => sessionCurrent.value?.capabilities.containsKey(capabilityForward) ?? false; + void disableVacationResponder() { + if (accountId.value != null) { + final vacationDisabled = vacationResponse.value != null + ? vacationResponse.value!.copyWith(isEnabled: false) + : VacationResponse(isEnabled: false); + consumeState(_updateVacationInteractor.execute(accountId.value!, vacationDisabled)); + } + } + + void _handleUpdateVacationSuccess(UpdateVacationSuccess success) { + if (success.listVacationResponse.isNotEmpty) { + if (currentContext != null && currentOverlayContext != null) { + _appToast.showToastWithIcon( + currentOverlayContext!, + message: AppLocalizations.of(currentContext!).yourVacationResponderIsDisabledSuccessfully, + icon: _imagePaths.icChecked); + } + vacationResponse.value = success.listVacationResponse.first; + log('ManageAccountDashBoardController::_handleUpdateVacationSuccess(): $vacationResponse'); + } + } } \ No newline at end of file diff --git a/lib/features/manage_account/presentation/manage_account_dashboard_view.dart b/lib/features/manage_account/presentation/manage_account_dashboard_view.dart index 11c252648..1bbcb4cfe 100644 --- a/lib/features/manage_account/presentation/manage_account_dashboard_view.dart +++ b/lib/features/manage_account/presentation/manage_account_dashboard_view.dart @@ -91,7 +91,8 @@ class ManageAccountDashBoardView extends GetWidget controller.disableVacationResponder()); } else { return const SizedBox.shrink(); } @@ -116,7 +117,8 @@ class ManageAccountDashBoardView extends GetWidget controller.disableVacationResponder()); } else { return const SizedBox.shrink(); } diff --git a/lib/features/manage_account/presentation/vacation/vacation_controller.dart b/lib/features/manage_account/presentation/vacation/vacation_controller.dart index e8f405863..27d852419 100644 --- a/lib/features/manage_account/presentation/vacation/vacation_controller.dart +++ b/lib/features/manage_account/presentation/vacation/vacation_controller.dart @@ -35,6 +35,7 @@ class VacationController extends BaseController { final TextEditingController messageBodyEditorController = TextEditingController(); VacationResponse? currentVacation; + late Worker vacationWorker; VacationController( this._getAllVacationInteractor, @@ -42,6 +43,12 @@ class VacationController extends BaseController { this._verifyNameInteractor ); + @override + void onInit() { + _initWorker(); + super.onInit(); + } + @override void onReady() { _getAllVacation(); @@ -65,6 +72,17 @@ class VacationController extends BaseController { @override void onError(error) {} + void _initWorker() { + vacationWorker = ever(_accountDashBoardController.vacationResponse, (vacation) { + if (vacation is VacationResponse) { + currentVacation = vacation; + final newVacationPresentation = currentVacation?.toVacationPresentation(); + vacationPresentation.value = newVacationPresentation ?? VacationPresentation.initialize(); + messageBodyEditorController.text = newVacationPresentation?.messageBody ?? ''; + } + }); + } + void _getAllVacation() { final accountId = _accountDashBoardController.accountId.value; if (accountId != null) { @@ -273,6 +291,7 @@ class VacationController extends BaseController { @override void onClose() { messageBodyEditorController.dispose(); + vacationWorker.dispose(); super.onClose(); } } \ No newline at end of file diff --git a/lib/features/thread/presentation/thread_view.dart b/lib/features/thread/presentation/thread_view.dart index a4307f251..bb450c579 100644 --- a/lib/features/thread/presentation/thread_view.dart +++ b/lib/features/thread/presentation/thread_view.dart @@ -67,7 +67,8 @@ class ThreadView extends GetWidget with AppLoaderMixin, return Padding( padding: const EdgeInsets.only(bottom: 16), child: VacationNotificationMessageWidget( - vacationResponse: controller.mailboxDashBoardController.vacationResponse.value!), + vacationResponse: controller.mailboxDashBoardController.vacationResponse.value!, + action: () => controller.mailboxDashBoardController.disableVacationResponder()), ); } else { return const SizedBox.shrink(); diff --git a/lib/l10n/intl_messages.arb b/lib/l10n/intl_messages.arb index c33805f9e..a935d77e3 100644 --- a/lib/l10n/intl_messages.arb +++ b/lib/l10n/intl_messages.arb @@ -1,5 +1,5 @@ { - "@@last_modified": "2022-08-18T14:30:25.186365", + "@@last_modified": "2022-08-18T16:16:05.548805", "initializing_data": "Initializing data...", "@initializing_data": { "type": "text", @@ -2011,5 +2011,11 @@ "type": "text", "placeholders_order": [], "placeholders": {} + }, + "yourVacationResponderIsDisabledSuccessfully": "Your vacation responder is disabled successfully", + "@yourVacationResponderIsDisabledSuccessfully": { + "type": "text", + "placeholders_order": [], + "placeholders": {} } } \ No newline at end of file diff --git a/lib/main/localizations/app_localizations.dart b/lib/main/localizations/app_localizations.dart index c97e80368..2816a1210 100644 --- a/lib/main/localizations/app_localizations.dart +++ b/lib/main/localizations/app_localizations.dart @@ -2085,4 +2085,11 @@ class AppLocalizations { name: 'disable', ); } + + String get yourVacationResponderIsDisabledSuccessfully { + return Intl.message( + 'Your vacation responder is disabled successfully', + name: 'yourVacationResponderIsDisabledSuccessfully', + ); + } } \ No newline at end of file