TF-802 Disable vacation responder in setting

This commit is contained in:
dab246
2022-08-18 15:35:47 +07:00
committed by Dat H. Pham
parent f2a72ac883
commit 610d5771b4
2 changed files with 39 additions and 8 deletions
@@ -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
);
}
}
@@ -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);
}