diff --git a/lib/features/manage_account/presentation/extensions/vacation_response_extension.dart b/lib/features/manage_account/presentation/extensions/vacation_response_extension.dart index ce0453126..24f88a873 100644 --- a/lib/features/manage_account/presentation/extensions/vacation_response_extension.dart +++ b/lib/features/manage_account/presentation/extensions/vacation_response_extension.dart @@ -1,6 +1,7 @@ import 'package:core/utils/app_logger.dart'; import 'package:flutter/material.dart'; +import 'package:jmap_dart_client/jmap/core/utc_date.dart'; import 'package:jmap_dart_client/jmap/mail/vacation/vacation_response.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/model/vacation/vacation_presentation.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/model/vacation/vacation_responder_status.dart'; @@ -40,4 +41,22 @@ extension VacationResponseExtension on VacationResponse { } return false; } + + VacationResponse copyWith({ + bool? isEnabled, + UTCDate? fromDate, + UTCDate? toDate, + String? subject, + String? textBody, + String? htmlBody + }) { + return VacationResponse( + isEnabled: isEnabled ?? this.isEnabled, + fromDate: fromDate ?? this.fromDate, + toDate: toDate ?? this.toDate, + subject: subject ?? this.subject, + textBody: textBody ?? this.textBody, + htmlBody: htmlBody ?? this.htmlBody + ); + } } \ No newline at end of file diff --git a/lib/features/manage_account/presentation/vacation/vacation_controller.dart b/lib/features/manage_account/presentation/vacation/vacation_controller.dart index a3bab4d33..e8f405863 100644 --- a/lib/features/manage_account/presentation/vacation/vacation_controller.dart +++ b/lib/features/manage_account/presentation/vacation/vacation_controller.dart @@ -34,6 +34,8 @@ class VacationController extends BaseController { final TextEditingController messageBodyEditorController = TextEditingController(); + VacationResponse? currentVacation; + VacationController( this._getAllVacationInteractor, this._updateVacationInteractor, @@ -72,12 +74,14 @@ class VacationController extends BaseController { void _handleGetAllVacationSuccess(GetAllVacationSuccess success) { if (success.listVacationResponse.isNotEmpty) { - final currentVacation = success.listVacationResponse.first; + currentVacation = success.listVacationResponse.first; log('VacationController::_handleGetAllVacationSuccess(): $currentVacation'); - final newVacationPresentation = currentVacation.toVacationPresentation(); - vacationPresentation.value = newVacationPresentation; - messageBodyEditorController.text = newVacationPresentation.messageBody ?? ''; + if (currentVacation != null) { + final newVacationPresentation = currentVacation!.toVacationPresentation(); + vacationPresentation.value = newVacationPresentation; + messageBodyEditorController.text = newVacationPresentation.messageBody ?? ''; + } } } @@ -229,6 +233,12 @@ class VacationController extends BaseController { final newVacationResponse = newVacationPresentation.toVacationResponse(); log('VacationController::saveVacation(): newVacationResponse: $newVacationResponse'); _updateVacationAction(newVacationResponse); + } else { + final vacationDisabled = currentVacation != null + ? currentVacation!.copyWith(isEnabled: false) + : VacationResponse(isEnabled: false); + log('VacationController::saveVacation(): vacationDisabled: $vacationDisabled'); + _updateVacationAction(vacationDisabled); } } @@ -247,12 +257,14 @@ class VacationController extends BaseController { message: AppLocalizations.of(currentContext!).vacationSettingSaved, icon: _imagePaths.icChecked); } - final currentVacation = success.listVacationResponse.first; + currentVacation = success.listVacationResponse.first; log('VacationController::_handleUpdateVacationSuccess(): $currentVacation'); - final newVacationPresentation = currentVacation.toVacationPresentation(); - vacationPresentation.value = newVacationPresentation; - messageBodyEditorController.text = newVacationPresentation.messageBody ?? ''; + if (currentVacation != null) { + final newVacationPresentation = currentVacation!.toVacationPresentation(); + vacationPresentation.value = newVacationPresentation; + messageBodyEditorController.text = newVacationPresentation.messageBody ?? ''; + } _accountDashBoardController.updateVacationResponse(currentVacation); }