TF-801 Enable vacation responder setting

This commit is contained in:
dab246
2022-08-17 20:34:26 +07:00
committed by Dat H. Pham
parent f3e6d892d8
commit c4d78f732d
10 changed files with 666 additions and 418 deletions
@@ -17,6 +17,7 @@ class BorderButtonField<T> extends StatelessWidget {
final TextStyle? textStyle; final TextStyle? textStyle;
final MouseCursor? mouseCursor; final MouseCursor? mouseCursor;
final String? hintText; final String? hintText;
final bool isEmpty;
const BorderButtonField({ const BorderButtonField({
super.key, super.key,
@@ -26,6 +27,7 @@ class BorderButtonField<T> extends StatelessWidget {
this.textStyle, this.textStyle,
this.mouseCursor, this.mouseCursor,
this.hintText, this.hintText,
this.isEmpty = false,
}); });
@override @override
@@ -40,7 +42,7 @@ class BorderButtonField<T> extends StatelessWidget {
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
border: Border.all( border: Border.all(
color: AppColor.colorInputBorderCreateMailbox, color: _getBorderColor(),
width: 1), width: 1),
color: Colors.white), color: Colors.white),
padding: const EdgeInsets.only(left: 12, right: 10), padding: const EdgeInsets.only(left: 12, right: 10),
@@ -80,4 +82,11 @@ class BorderButtonField<T> extends StatelessWidget {
} }
return hintText ?? ''; return hintText ?? '';
} }
Color _getBorderColor() {
if (!isEmpty) {
return AppColor.colorInputBorderCreateMailbox;
}
return AppColor.colorInputBorderErrorVerifyName;
}
} }
@@ -42,4 +42,12 @@ extension ValicatorFailureExtension on VerifyNameFailure {
return ''; return '';
} }
} }
String getMessageVacation(BuildContext context) {
if (exception is EmptyNameException) {
return AppLocalizations.of(context).this_field_cannot_be_blank;
} else {
return '';
}
}
} }
@@ -1,14 +1,19 @@
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:tmail_ui_user/features/base/base_bindings.dart'; import 'package:tmail_ui_user/features/base/base_bindings.dart';
import 'package:tmail_ui_user/features/mailbox_creator/domain/usecases/verify_name_interactor.dart';
import 'package:tmail_ui_user/features/manage_account/domain/repository/manage_account_repository.dart'; 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/get_all_vacation_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/configuration/vacation/vacation_controller.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/configuration/vacation/vacation_controller.dart';
class VacationBindings extends BaseBindings { class VacationBindings extends BaseBindings {
@override @override
void bindingsController() { void bindingsController() {
Get.lazyPut(() => VacationController(Get.find<GetAllVacationInteractor>())); Get.lazyPut(() => VacationController(
Get.find<GetAllVacationInteractor>(),
Get.find<UpdateVacationInteractor>(),
Get.find<VerifyNameInteractor>()));
} }
@override @override
@@ -22,6 +27,8 @@ class VacationBindings extends BaseBindings {
@override @override
void bindingsInteractor() { void bindingsInteractor() {
Get.lazyPut(() => GetAllVacationInteractor(Get.find<ManageAccountRepository>())); Get.lazyPut(() => GetAllVacationInteractor(Get.find<ManageAccountRepository>()));
Get.lazyPut(() => UpdateVacationInteractor(Get.find<ManageAccountRepository>()));
Get.lazyPut(() => VerifyNameInteractor());
} }
@override @override
@@ -1,28 +1,44 @@
import 'package:core/utils/app_logger.dart'; import 'package:core/core.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:jmap_dart_client/jmap/mail/vacation/vacation_response.dart'; import 'package:jmap_dart_client/jmap/mail/vacation/vacation_response.dart';
import 'package:tmail_ui_user/features/base/base_controller.dart'; import 'package:tmail_ui_user/features/base/base_controller.dart';
import 'package:tmail_ui_user/features/mailbox_creator/domain/model/verification/empty_name_validator.dart';
import 'package:tmail_ui_user/features/mailbox_creator/domain/state/verify_name_view_state.dart';
import 'package:tmail_ui_user/features/mailbox_creator/domain/usecases/verify_name_interactor.dart';
import 'package:tmail_ui_user/features/mailbox_creator/presentation/extensions/validator_failure_extension.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/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/get_all_vacation_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/manage_account_dashboard_controller.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/manage_account_dashboard_controller.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/model/vacation/date_type.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/model/vacation/date_type.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_presentation.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/model/vacation/vacation_responder_status.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/model/vacation/vacation_responder_status.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
class VacationController extends BaseController { class VacationController extends BaseController {
final _accountDashBoardController = Get.find<ManageAccountDashBoardController>(); final _accountDashBoardController = Get.find<ManageAccountDashBoardController>();
final _appToast = Get.find<AppToast>();
final _imagePaths = Get.find<ImagePaths>();
final GetAllVacationInteractor _getAllVacationInteractor; final GetAllVacationInteractor _getAllVacationInteractor;
final UpdateVacationInteractor _updateVacationInteractor;
final VerifyNameInteractor _verifyNameInteractor;
final vacationPresentation = VacationPresentation.initialize().obs; final vacationPresentation = VacationPresentation.initialize().obs;
final errorMessageBody = Rxn<String>();
final TextEditingController messageBodyEditorController = TextEditingController(); final TextEditingController messageBodyEditorController = TextEditingController();
VacationResponse? currentVacation; VacationController(
this._getAllVacationInteractor,
VacationController(this._getAllVacationInteractor); this._updateVacationInteractor,
this._verifyNameInteractor
);
@override @override
void onReady() { void onReady() {
@@ -37,6 +53,8 @@ class VacationController extends BaseController {
(success) { (success) {
if (success is GetAllVacationSuccess) { if (success is GetAllVacationSuccess) {
_handleGetAllVacationSuccess(success); _handleGetAllVacationSuccess(success);
} else if (success is UpdateVacationSuccess) {
_handleUpdateVacationSuccess(success);
} }
} }
); );
@@ -53,41 +71,17 @@ class VacationController extends BaseController {
} }
void _handleGetAllVacationSuccess(GetAllVacationSuccess success) { void _handleGetAllVacationSuccess(GetAllVacationSuccess success) {
if (success.listVacationResponse?.isNotEmpty == true) { if (success.listVacationResponse.isNotEmpty) {
currentVacation = success.listVacationResponse!.first; final currentVacation = success.listVacationResponse.first;
log('VacationController::_handleGetAllVacationSuccess(): $currentVacation'); log('VacationController::_handleGetAllVacationSuccess(): $currentVacation');
final vacationStatus = currentVacation?.isEnabled; final newVacationPresentation = currentVacation.toVacationPresentation();
final startDate = currentVacation?.fromDate?.value; vacationPresentation.value = newVacationPresentation;
final endDate = currentVacation?.toDate?.value; messageBodyEditorController.text = newVacationPresentation.messageBody ?? '';
final messageBody = currentVacation?.htmlBody ?? currentVacation?.textBody;
final startTime = startDate != null
? TimeOfDay.fromDateTime(startDate)
: null;
final endTime = endDate != null
? TimeOfDay.fromDateTime(endDate)
: null;
final vacationStopEnabled = endDate != null;
if (messageBody != null) {
messageBodyEditorController.text = messageBody;
}
updateVacationPresentation(
newStatus: vacationStatus == true
? VacationResponderStatus.activated
: VacationResponderStatus.deactivated,
startDate: startDate,
startTime: startTime,
endDate: endDate,
endTime: endTime,
vacationStopEnabled: vacationStopEnabled,
);
} }
} }
bool get isVacationDeactivated => bool get isVacationDeactivated => !vacationPresentation.value.isEnabled;
vacationPresentation.value.status == VacationResponderStatus.deactivated;
bool get isVacationStopEnabled => vacationPresentation.value.vacationStopEnabled; bool get isVacationStopEnabled => vacationPresentation.value.vacationStopEnabled;
@@ -100,6 +94,7 @@ class VacationController extends BaseController {
DateTime? endDate, DateTime? endDate,
TimeOfDay? endTime, TimeOfDay? endTime,
bool? vacationStopEnabled, bool? vacationStopEnabled,
String? messageBody
}) { }) {
final currentVacation = vacationPresentation.value; final currentVacation = vacationPresentation.value;
final newVacation = currentVacation.copyWidth( final newVacation = currentVacation.copyWidth(
@@ -108,7 +103,9 @@ class VacationController extends BaseController {
startTime: startTime, startTime: startTime,
endDate: endDate, endDate: endDate,
endTime: endTime, endTime: endTime,
vacationStopEnabled: vacationStopEnabled); vacationStopEnabled: vacationStopEnabled,
messageBody: messageBody);
log('VacationController::updateVacationPresentation():newVacation: $newVacation');
vacationPresentation.value = newVacation; vacationPresentation.value = newVacation;
} }
@@ -137,6 +134,11 @@ class VacationController extends BaseController {
final timePicked = await showTimePicker( final timePicked = await showTimePicker(
context: context, context: context,
initialTime: currentTime ?? TimeOfDay.now(), initialTime: currentTime ?? TimeOfDay.now(),
builder: (context, child) {
return MediaQuery(
data: const MediaQueryData(alwaysUse24HourFormat: true),
child: child!);
}
); );
if (timePicked == null) { if (timePicked == null) {
@@ -150,8 +152,88 @@ class VacationController extends BaseController {
} }
} }
void saveVacation(BuildContext context) { String? _getErrorStringByInputValue(BuildContext context, String? inputValue) {
return _verifyNameInteractor.execute(inputValue, [EmptyNameValidator()]).fold(
(failure) {
if (failure is VerifyNameFailure) {
return failure.getMessageVacation(context);
} else {
return null;
}
},
(success) => null
);
}
void updateMessageBody(BuildContext context, String? value) {
errorMessageBody.value = _getErrorStringByInputValue(context, value);
}
void saveVacation(BuildContext context) {
FocusScope.of(context).unfocus();
if (vacationPresentation.value.isEnabled) {
final fromDate = vacationPresentation.value.fromDate;
if (fromDate == null) {
_appToast.showToastWithIcon(
context,
bgColor: AppColor.toastErrorBackgroundColor,
textColor: Colors.white,
message: AppLocalizations.of(context).errorMessageWhenStartDateVacationIsEmpty);
return;
}
final vacationStopEnabled = vacationPresentation.value.vacationStopEnabled;
final toDate = vacationPresentation.value.toDate;
if (vacationStopEnabled && toDate != null && toDate.isBefore(fromDate)) {
_appToast.showToastWithIcon(
context,
bgColor: AppColor.toastErrorBackgroundColor,
textColor: Colors.white,
message: AppLocalizations.of(context).errorMessageWhenEndDateVacationIsInValid);
return;
}
final messageBody = messageBodyEditorController.text;
if (messageBody.isEmpty) {
_appToast.showToastWithIcon(
context,
bgColor: AppColor.toastErrorBackgroundColor,
textColor: Colors.white,
message: AppLocalizations.of(context).errorMessageWhenMessageVacationIsEmpty);
return;
}
final newVacationPresentation = vacationPresentation.value.copyWidth(messageBody: messageBody);
log('VacationController::saveVacation(): newVacationPresentation: $newVacationPresentation');
final newVacationResponse = newVacationPresentation.toVacationResponse();
log('VacationController::saveVacation(): newVacationResponse: $newVacationResponse');
_updateVacationAction(newVacationResponse);
}
}
void _updateVacationAction(VacationResponse vacationResponse) {
final accountId = _accountDashBoardController.accountId.value;
if (accountId != null) {
consumeState(_updateVacationInteractor.execute(accountId, vacationResponse));
}
}
void _handleUpdateVacationSuccess(UpdateVacationSuccess success) {
if (success.listVacationResponse.isNotEmpty) {
if (currentContext != null && currentOverlayContext != null) {
_appToast.showToastWithIcon(
currentOverlayContext!,
message: AppLocalizations.of(currentContext!).vacationSettingSaved,
icon: _imagePaths.icChecked);
}
final currentVacation = success.listVacationResponse.first;
log('VacationController::_handleUpdateVacationSuccess(): $currentVacation');
final newVacationPresentation = currentVacation.toVacationPresentation();
vacationPresentation.value = newVacationPresentation;
messageBodyEditorController.text = newVacationPresentation.messageBody ?? '';
}
} }
@override @override
@@ -20,7 +20,9 @@ class VacationView extends GetWidget<VacationController> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: Colors.white, backgroundColor: Colors.white,
body: Container( body: GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Container(
width: double.infinity, width: double.infinity,
color: Colors.white, color: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 16), padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 16),
@@ -41,27 +43,26 @@ class VacationView extends GetWidget<VacationController> {
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
color: Colors.black))), color: Colors.black))),
const SizedBox(width: 16), const SizedBox(width: 16),
ToggleSwitch( Obx(() => ToggleSwitch(
minWidth: 150.0, minWidth: 150.0,
cornerRadius: 20.0, cornerRadius: 20.0,
activeBgColors: const [[Colors.green], [Colors.redAccent]], activeBgColors: const [[Colors.green], [Colors.redAccent]],
activeFgColor: Colors.white, activeFgColor: Colors.white,
inactiveBgColor: Colors.grey, inactiveBgColor: Colors.grey,
inactiveFgColor: Colors.white, inactiveFgColor: Colors.white,
initialLabelIndex: 1, initialLabelIndex: controller.isVacationDeactivated ? 1 : 0,
totalSwitches: VacationResponderStatus.values.length, totalSwitches: VacationResponderStatus.values.length,
labels: VacationResponderStatus.values labels: VacationResponderStatus.values
.map((status) => status.getTitle(context)) .map((status) => status.getTitle(context))
.toList(), .toList(),
radiusStyle: true, radiusStyle: true,
onToggle: (index) { onToggle: (index) {
log('VacationView::build():ToggleSwitch:index: $index');
final newStatus = index == 0 final newStatus = index == 0
? VacationResponderStatus.activated ? VacationResponderStatus.activated
: VacationResponderStatus.deactivated; : VacationResponderStatus.deactivated;
controller.updateVacationPresentation(newStatus: newStatus); controller.updateVacationPresentation(newStatus: newStatus);
}, },
), )),
]), ]),
const SizedBox(height: 20), const SizedBox(height: 20),
Obx(() => AbsorbPointer( Obx(() => AbsorbPointer(
@@ -81,6 +82,8 @@ class VacationView extends GetWidget<VacationController> {
Expanded(child: Obx(() => BorderButtonField<DateTime>( Expanded(child: Obx(() => BorderButtonField<DateTime>(
value: controller.vacationPresentation.value.startDate, value: controller.vacationPresentation.value.startDate,
mouseCursor: SystemMouseCursors.text, mouseCursor: SystemMouseCursors.text,
isEmpty: !controller.isVacationDeactivated &&
controller.vacationPresentation.value.startDateIsNull,
textStyle: TextStyle( textStyle: TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
@@ -97,6 +100,8 @@ class VacationView extends GetWidget<VacationController> {
Expanded(child: Obx(() => BorderButtonField<TimeOfDay>( Expanded(child: Obx(() => BorderButtonField<TimeOfDay>(
value: controller.vacationPresentation.value.startTime, value: controller.vacationPresentation.value.startTime,
mouseCursor: SystemMouseCursors.text, mouseCursor: SystemMouseCursors.text,
isEmpty: !controller.isVacationDeactivated &&
controller.vacationPresentation.value.starTimeIsNull,
textStyle: TextStyle( textStyle: TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
@@ -151,6 +156,8 @@ class VacationView extends GetWidget<VacationController> {
Expanded(child: Obx(() => BorderButtonField<DateTime>( Expanded(child: Obx(() => BorderButtonField<DateTime>(
value: controller.vacationPresentation.value.endDate, value: controller.vacationPresentation.value.endDate,
mouseCursor: SystemMouseCursors.text, mouseCursor: SystemMouseCursors.text,
isEmpty: controller.canChangeEndDate &&
controller.vacationPresentation.value.endDateIsNull,
textStyle: TextStyle( textStyle: TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
@@ -167,6 +174,8 @@ class VacationView extends GetWidget<VacationController> {
Expanded(child: Obx(() => BorderButtonField<TimeOfDay>( Expanded(child: Obx(() => BorderButtonField<TimeOfDay>(
value: controller.vacationPresentation.value.endTime, value: controller.vacationPresentation.value.endTime,
mouseCursor: SystemMouseCursors.text, mouseCursor: SystemMouseCursors.text,
isEmpty: controller.canChangeEndDate &&
controller.vacationPresentation.value.endTimeIsNull,
textStyle: TextStyle( textStyle: TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
@@ -227,27 +236,26 @@ class VacationView extends GetWidget<VacationController> {
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
color: Colors.black)), color: Colors.black)),
const SizedBox(height: 16), const SizedBox(height: 16),
ToggleSwitch( Obx(() => ToggleSwitch(
minWidth: 150.0, minWidth: 150.0,
cornerRadius: 20.0, cornerRadius: 20.0,
activeBgColors: const [[Colors.green], [Colors.redAccent]], activeBgColors: const [[Colors.green], [Colors.redAccent]],
activeFgColor: Colors.white, activeFgColor: Colors.white,
inactiveBgColor: Colors.grey, inactiveBgColor: Colors.grey,
inactiveFgColor: Colors.white, inactiveFgColor: Colors.white,
initialLabelIndex: 1, initialLabelIndex: controller.isVacationDeactivated ? 1 : 0,
totalSwitches: VacationResponderStatus.values.length, totalSwitches: VacationResponderStatus.values.length,
labels: VacationResponderStatus.values labels: VacationResponderStatus.values
.map((status) => status.getTitle(context)) .map((status) => status.getTitle(context))
.toList(), .toList(),
radiusStyle: true, radiusStyle: true,
onToggle: (index) { onToggle: (index) {
log('VacationView::build():ToggleSwitch:index: $index');
final newStatus = index == 0 final newStatus = index == 0
? VacationResponderStatus.activated ? VacationResponderStatus.activated
: VacationResponderStatus.deactivated; : VacationResponderStatus.deactivated;
controller.updateVacationPresentation(newStatus: newStatus); controller.updateVacationPresentation(newStatus: newStatus);
}, },
) ))
]) ])
else else
Row(children: [ Row(children: [
@@ -260,27 +268,26 @@ class VacationView extends GetWidget<VacationController> {
color: Colors.black)), color: Colors.black)),
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
ToggleSwitch( Obx(() => ToggleSwitch(
minWidth: 150.0, minWidth: 150.0,
cornerRadius: 20.0, cornerRadius: 20.0,
activeBgColors: const [[Colors.green], [Colors.redAccent]], activeBgColors: const [[Colors.green], [Colors.redAccent]],
activeFgColor: Colors.white, activeFgColor: Colors.white,
inactiveBgColor: Colors.grey, inactiveBgColor: Colors.grey,
inactiveFgColor: Colors.white, inactiveFgColor: Colors.white,
initialLabelIndex: 1, initialLabelIndex: controller.isVacationDeactivated ? 1 : 0,
totalSwitches: VacationResponderStatus.values.length, totalSwitches: VacationResponderStatus.values.length,
labels: VacationResponderStatus.values labels: VacationResponderStatus.values
.map((status) => status.getTitle(context)) .map((status) => status.getTitle(context))
.toList(), .toList(),
radiusStyle: true, radiusStyle: true,
onToggle: (index) { onToggle: (index) {
log('VacationView::build():ToggleSwitch:index: $index');
final newStatus = index == 0 final newStatus = index == 0
? VacationResponderStatus.activated ? VacationResponderStatus.activated
: VacationResponderStatus.deactivated; : VacationResponderStatus.deactivated;
controller.updateVacationPresentation(newStatus: newStatus); controller.updateVacationPresentation(newStatus: newStatus);
}, },
) ))
]), ]),
const SizedBox(height: 20), const SizedBox(height: 20),
Obx(() => AbsorbPointer( Obx(() => AbsorbPointer(
@@ -426,10 +433,12 @@ class VacationView extends GetWidget<VacationController> {
), ),
), ),
), ),
),
); );
} }
Widget _buildMessageBodyWidget(BuildContext context, double opacity) { Widget _buildMessageBodyWidget(BuildContext context, double opacity) {
return Obx(() {
return (TextFieldBuilder() return (TextFieldBuilder()
..key(const Key('message_body_editor')) ..key(const Key('message_body_editor'))
..cursorColor(Colors.black) ..cursorColor(Colors.black)
@@ -445,10 +454,17 @@ class VacationView extends GetWidget<VacationController> {
..setHintStyle(TextStyle( ..setHintStyle(TextStyle(
color: AppColor.colorHintInputCreateMailbox.withOpacity(opacity), color: AppColor.colorHintInputCreateMailbox.withOpacity(opacity),
fontSize: 16)) fontSize: 16))
..setHintText(AppLocalizations.of(context).hintMessageBodyVacation)) ..setErrorText(controller.isVacationDeactivated
? null
: controller.errorMessageBody.value)
..setHintText(AppLocalizations
.of(context)
.hintMessageBodyVacation))
.build()) .build())
..onChange((value) => controller.updateMessageBody(context, value))
..minLines(8) ..minLines(8)
..maxLines(null)) ..maxLines(null))
.build(); .build();
});
} }
} }
@@ -5,18 +5,26 @@ extension DateTimeExtension on DateTime? {
String formatDate({String pattern = 'yyyy/MM/dd', String locale = 'en_US'}) { String formatDate({String pattern = 'yyyy/MM/dd', String locale = 'en_US'}) {
if (this != null) { if (this != null) {
return DateFormat(pattern, locale).format(this!.toLocal()); return DateFormat(pattern, locale).format(this!);
} else { } else {
return ''; return '';
} }
} }
DateTime? applied(TimeOfDay? time) {
if (this != null && time != null) {
return DateTime.utc(this!.year, this!.month, this!.day, time.hour, time.minute);
}
return null;
}
} }
extension TimeOfDayExtension on TimeOfDay? { extension TimeOfDayExtension on TimeOfDay? {
String formatTime(BuildContext context) { String formatTime(BuildContext context) {
if (this != null) { if (this != null) {
return this!.format(context); return MaterialLocalizations.of(context)
.formatTimeOfDay(this!, alwaysUse24HourFormat: true);
} }
return ''; return '';
} }
@@ -0,0 +1,26 @@
import 'package:flutter/material.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';
extension VacationResponseExtension on VacationResponse {
VacationPresentation toVacationPresentation() {
return VacationPresentation(
status: isEnabled == true
? VacationResponderStatus.activated
: VacationResponderStatus.deactivated,
startDate: fromDate?.value.toUtc(),
startTime: fromDate?.value != null
? TimeOfDay.fromDateTime(fromDate!.value.toUtc())
: null,
endDate: toDate?.value.toUtc(),
endTime: toDate?.value != null
? TimeOfDay.fromDateTime(toDate!.value.toUtc())
: null,
messageBody: textBody ?? htmlBody,
vacationStopEnabled: toDate != null
);
}
}
@@ -1,8 +1,12 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/material.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/extensions/datetime_extension.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/model/vacation/vacation_responder_status.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/model/vacation/vacation_responder_status.dart';
class VacationPresentation { class VacationPresentation with EquatableMixin {
final VacationResponderStatus status; final VacationResponderStatus status;
final DateTime? startDate; final DateTime? startDate;
final TimeOfDay? startTime; final TimeOfDay? startTime;
@@ -44,4 +48,40 @@ class VacationPresentation {
vacationStopEnabled: vacationStopEnabled ?? this.vacationStopEnabled vacationStopEnabled: vacationStopEnabled ?? this.vacationStopEnabled
); );
} }
bool get startDateIsNull => startDate == null;
bool get starTimeIsNull => startTime == null;
bool get endDateIsNull => endDate == null;
bool get endTimeIsNull => endTime == null;
DateTime? get fromDate => startDate.applied(startTime);
DateTime? get toDate => endDate.applied(endTime);
bool get isEnabled => status == VacationResponderStatus.activated;
@override
List<Object?> get props => [
status,
startDate,
startTime,
endDate,
endTime,
vacationStopEnabled,
messageBody
];
}
extension VacationPresentationExtension on VacationPresentation {
VacationResponse toVacationResponse() {
return VacationResponse(
isEnabled: isEnabled,
fromDate: fromDate != null ? UTCDate(fromDate!) : null,
toDate: toDate != null ? UTCDate(toDate!) : null,
textBody: messageBody
);
}
} }
+25 -1
View File
@@ -1,5 +1,5 @@
{ {
"@@last_modified": "2022-08-17T17:27:40.386002", "@@last_modified": "2022-08-17T20:19:48.796318",
"initializing_data": "Initializing data...", "initializing_data": "Initializing data...",
"@initializing_data": { "@initializing_data": {
"type": "text", "type": "text",
@@ -1981,5 +1981,29 @@
"type": "text", "type": "text",
"placeholders_order": [], "placeholders_order": [],
"placeholders": {} "placeholders": {}
},
"errorMessageWhenStartDateVacationIsEmpty": "Please enter a valid start date",
"@errorMessageWhenStartDateVacationIsEmpty": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"errorMessageWhenEndDateVacationIsInValid": "End date must be greater than start date",
"@errorMessageWhenEndDateVacationIsInValid": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"errorMessageWhenMessageVacationIsEmpty": "Message body cannot be blank",
"@errorMessageWhenMessageVacationIsEmpty": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"vacationSettingSaved": "Vacation settings saved",
"@vacationSettingSaved": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
} }
} }
@@ -2050,4 +2050,32 @@ class AppLocalizations {
name: 'noEndDate', name: 'noEndDate',
); );
} }
String get errorMessageWhenStartDateVacationIsEmpty {
return Intl.message(
'Please enter a valid start date',
name: 'errorMessageWhenStartDateVacationIsEmpty',
);
}
String get errorMessageWhenEndDateVacationIsInValid {
return Intl.message(
'End date must be greater than start date',
name: 'errorMessageWhenEndDateVacationIsInValid',
);
}
String get errorMessageWhenMessageVacationIsEmpty {
return Intl.message(
'Message body cannot be blank',
name: 'errorMessageWhenMessageVacationIsEmpty',
);
}
String get vacationSettingSaved {
return Intl.message(
'Vacation settings saved',
name: 'vacationSettingSaved',
);
}
} }