TF-1677: Fix validation for email forward
(cherry picked from commit b8741e08799c84ff96fd349d264f00d6b71e08cc)
This commit is contained in:
+26
-2
@@ -21,7 +21,7 @@ import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
|||||||
|
|
||||||
typedef OnSuggestionContactCallbackAction = Future<List<EmailAddress>> Function(String query);
|
typedef OnSuggestionContactCallbackAction = Future<List<EmailAddress>> Function(String query);
|
||||||
typedef OnAddListContactCallbackAction = Function(List<EmailAddress> listEmailAddress);
|
typedef OnAddListContactCallbackAction = Function(List<EmailAddress> listEmailAddress);
|
||||||
typedef OnExceptionAddListContactCallbackAction = Function();
|
typedef OnExceptionAddListContactCallbackAction = Function(bool isListEmpty);
|
||||||
|
|
||||||
class AutocompleteContactTextFieldWithTags extends StatefulWidget {
|
class AutocompleteContactTextFieldWithTags extends StatefulWidget {
|
||||||
|
|
||||||
@@ -49,6 +49,7 @@ class _AutocompleteContactTextFieldWithTagsState extends State<AutocompleteConta
|
|||||||
|
|
||||||
final _responsiveUtils = Get.find<ResponsiveUtils>();
|
final _responsiveUtils = Get.find<ResponsiveUtils>();
|
||||||
final _imagePaths = Get.find<ImagePaths>();
|
final _imagePaths = Get.find<ImagePaths>();
|
||||||
|
final GlobalKey<TagsEditorState> keyToEmailTagEditor = GlobalKey<TagsEditorState>();
|
||||||
|
|
||||||
late List<EmailAddress> listEmailAddress;
|
late List<EmailAddress> listEmailAddress;
|
||||||
|
|
||||||
@@ -70,6 +71,7 @@ class _AutocompleteContactTextFieldWithTagsState extends State<AutocompleteConta
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final itemTagEditor = TagEditor<SuggestionEmailAddress>(
|
final itemTagEditor = TagEditor<SuggestionEmailAddress>(
|
||||||
|
key: keyToEmailTagEditor,
|
||||||
length: listEmailAddress.length,
|
length: listEmailAddress.length,
|
||||||
controller: widget.controller,
|
controller: widget.controller,
|
||||||
borderRadius: 12,
|
borderRadius: 12,
|
||||||
@@ -278,6 +280,23 @@ class _AutocompleteContactTextFieldWithTagsState extends State<AutocompleteConta
|
|||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
fontWeight: FontWeight.w500))
|
fontWeight: FontWeight.w500))
|
||||||
..onPressActionClick(() {
|
..onPressActionClick(() {
|
||||||
|
if (widget.controller?.text.isNotEmpty == true) {
|
||||||
|
if (!_isDuplicatedRecipient(widget.controller?.text ?? '')) {
|
||||||
|
setState(() {
|
||||||
|
listEmailAddress.add(EmailAddress(null, widget.controller?.text));
|
||||||
|
});
|
||||||
|
_closeSuggestionBox();
|
||||||
|
} else {
|
||||||
|
_closeSuggestionBox();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listEmailAddress.isEmpty) {
|
||||||
|
widget.onExceptionCallback?.call(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_isValidAllEmailAddress(listEmailAddress) && _inputFieldIsEmpty()) {
|
if (_isValidAllEmailAddress(listEmailAddress) && _inputFieldIsEmpty()) {
|
||||||
widget.onAddContactCallback?.call(List.from(listEmailAddress));
|
widget.onAddContactCallback?.call(List.from(listEmailAddress));
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -285,10 +304,15 @@ class _AutocompleteContactTextFieldWithTagsState extends State<AutocompleteConta
|
|||||||
listEmailAddress.clear();
|
listEmailAddress.clear();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
widget.onExceptionCallback?.call();
|
widget.onExceptionCallback?.call(false);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
..text(AppLocalizations.of(context).addRecipientButton, isVertical: false)
|
..text(AppLocalizations.of(context).addRecipientButton, isVertical: false)
|
||||||
).build();
|
).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _closeSuggestionBox() {
|
||||||
|
keyToEmailTagEditor.currentState?.resetTextField();
|
||||||
|
keyToEmailTagEditor.currentState?.closeSuggestionBox();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -302,4 +302,16 @@ class ForwardController extends BaseController {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handleExceptionCallback(BuildContext context, bool isListEmailEmpty) {
|
||||||
|
if (isListEmailEmpty) {
|
||||||
|
_appToast.showToastErrorMessage(
|
||||||
|
context,
|
||||||
|
AppLocalizations.of(context).emptyListEmailForward);
|
||||||
|
} else {
|
||||||
|
_appToast.showToastErrorMessage(
|
||||||
|
context,
|
||||||
|
AppLocalizations.of(context).incorrectEmailFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import 'package:core/presentation/extensions/color_extension.dart';
|
import 'package:core/presentation/extensions/color_extension.dart';
|
||||||
import 'package:core/presentation/resources/image_paths.dart';
|
import 'package:core/presentation/resources/image_paths.dart';
|
||||||
import 'package:core/presentation/state/success.dart';
|
import 'package:core/presentation/state/success.dart';
|
||||||
import 'package:core/presentation/utils/app_toast.dart';
|
|
||||||
import 'package:core/presentation/utils/responsive_utils.dart';
|
import 'package:core/presentation/utils/responsive_utils.dart';
|
||||||
import 'package:core/presentation/utils/style_utils.dart';
|
import 'package:core/presentation/utils/style_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -18,7 +17,6 @@ import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
|||||||
class ForwardView extends GetWidget<ForwardController> with AppLoaderMixin {
|
class ForwardView extends GetWidget<ForwardController> with AppLoaderMixin {
|
||||||
final _responsiveUtils = Get.find<ResponsiveUtils>();
|
final _responsiveUtils = Get.find<ResponsiveUtils>();
|
||||||
final _imagePaths = Get.find<ImagePaths>();
|
final _imagePaths = Get.find<ImagePaths>();
|
||||||
final _appToast = Get.find<AppToast>();
|
|
||||||
|
|
||||||
ForwardView({Key? key}) : super(key: key);
|
ForwardView({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@@ -134,10 +132,8 @@ class ForwardView extends GetWidget<ForwardController> with AppLoaderMixin {
|
|||||||
onAddContactCallback: (listRecipientsSelected) {
|
onAddContactCallback: (listRecipientsSelected) {
|
||||||
controller.addRecipientAction(context, listRecipientsSelected);
|
controller.addRecipientAction(context, listRecipientsSelected);
|
||||||
},
|
},
|
||||||
onExceptionCallback: () {
|
onExceptionCallback: (isListEmailEmpty) {
|
||||||
_appToast.showToastErrorMessage(
|
controller.handleExceptionCallback(context, isListEmailEmpty);
|
||||||
context,
|
|
||||||
AppLocalizations.of(context).incorrectEmailFormat);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2827,4 +2827,10 @@ class AppLocalizations {
|
|||||||
name: 'mailboxVisibilitySubtitle',
|
name: 'mailboxVisibilitySubtitle',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String get emptyListEmailForward {
|
||||||
|
return Intl.message(
|
||||||
|
'Please input at least one recipient',
|
||||||
|
name: 'emptyListEmailForward');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user