TF-3051 Fix should not allow create rule with no actions

This commit is contained in:
dab246
2024-09-10 16:02:08 +07:00
committed by Dat H. Pham
parent 3c5b0d9da4
commit 489db053ee
4 changed files with 110 additions and 64 deletions
@@ -0,0 +1,7 @@
import 'package:tmail_ui_user/features/rules_filter_creator/presentation/model/rule_filter_action_arguments.dart';
extension ListRuleFilterActionArgumentExtension on List<RuleFilterActionArguments> {
bool isEmptySelectedRuleAction() => every((argument) => argument is EmptyRuleFilterActionArguments);
}
@@ -32,6 +32,7 @@ import 'package:tmail_ui_user/features/manage_account/domain/model/create_new_em
import 'package:tmail_ui_user/features/manage_account/domain/model/edit_email_rule_filter_request.dart'; import 'package:tmail_ui_user/features/manage_account/domain/model/edit_email_rule_filter_request.dart';
import 'package:tmail_ui_user/features/manage_account/domain/state/get_all_rules_state.dart'; import 'package:tmail_ui_user/features/manage_account/domain/state/get_all_rules_state.dart';
import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_rules_interactor.dart'; import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_rules_interactor.dart';
import 'package:tmail_ui_user/features/rules_filter_creator/presentation/extensions/list_rule_filter_action_argument_extension.dart';
import 'package:tmail_ui_user/features/rules_filter_creator/presentation/model/creator_action_type.dart'; import 'package:tmail_ui_user/features/rules_filter_creator/presentation/model/creator_action_type.dart';
import 'package:tmail_ui_user/features/rules_filter_creator/presentation/model/email_rule_filter_action.dart'; import 'package:tmail_ui_user/features/rules_filter_creator/presentation/model/email_rule_filter_action.dart';
import 'package:tmail_ui_user/features/rules_filter_creator/presentation/model/rule_filter_action_arguments.dart'; import 'package:tmail_ui_user/features/rules_filter_creator/presentation/model/rule_filter_action_arguments.dart';
@@ -442,10 +443,18 @@ class RulesFilterCreatorController extends BaseMailboxController {
return; return;
} }
if (listRuleCondition.isNotEmpty) { if (listRuleCondition.isEmpty
String? errorConditionString; && currentOverlayContext != null
&& currentContext != null
) {
appToast.showToastErrorMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).youHaveNotAddedConditionToRule);
return;
}
for (var ruleCondition in listRuleCondition) { for (var ruleCondition in listRuleCondition) {
errorConditionString = _getErrorStringByInputValue(context, ruleCondition.value); final errorConditionString = _getErrorStringByInputValue(context, ruleCondition.value);
log('RulesFilterCreatorController::createNewRuleFilter:errorConditionString: $errorConditionString'); log('RulesFilterCreatorController::createNewRuleFilter:errorConditionString: $errorConditionString');
if (errorConditionString != null) { if (errorConditionString != null) {
int ruleConditionIndex = listRuleCondition.indexOf(ruleCondition); int ruleConditionIndex = listRuleCondition.indexOf(ruleCondition);
@@ -456,23 +465,30 @@ class RulesFilterCreatorController extends BaseMailboxController {
); );
listRuleConditionValueArguments[ruleConditionIndex] = newRuleConditionValueArguments; listRuleConditionValueArguments[ruleConditionIndex] = newRuleConditionValueArguments;
listRuleConditionValueArguments[listRuleCondition.indexOf(ruleCondition)].focusNode.requestFocus(); listRuleConditionValueArguments[listRuleCondition.indexOf(ruleCondition)].focusNode.requestFocus();
}
}
if (errorConditionString?.isNotEmpty == true) {
return; return;
} }
} }
if (listRuleCondition.isEmpty == true || listEmailRuleFilterActionSelected.isEmpty == true) { if (listEmailRuleFilterActionSelected.isEmpty
if (currentOverlayContext != null && currentContext != null) { && currentOverlayContext != null
&& currentContext != null
) {
appToast.showToastErrorMessage( appToast.showToastErrorMessage(
currentOverlayContext!, currentOverlayContext!,
AppLocalizations.of(currentContext!).toastErrorMessageWhenCreateNewRule); AppLocalizations.of(currentContext!).youHaveNotAddedActionToRule);
} return;
}
if (listEmailRuleFilterActionSelected.isEmptySelectedRuleAction()
&& currentOverlayContext != null
&& currentContext != null
) {
appToast.showToastErrorMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).youHaveNotSelectedAnyActionForRule);
return; return;
} }
if (listEmailRuleFilterActionSelected.isNotEmpty == true) {
for (var ruleFilterAction in listEmailRuleFilterActionSelected) { for (var ruleFilterAction in listEmailRuleFilterActionSelected) {
if (ruleFilterAction is MoveMessageActionArguments) { if (ruleFilterAction is MoveMessageActionArguments) {
final errorAction = _getErrorStringByInputValue(context, mailboxSelected.value?.getDisplayName(context)); final errorAction = _getErrorStringByInputValue(context, mailboxSelected.value?.getDisplayName(context));
@@ -504,7 +520,6 @@ class RulesFilterCreatorController extends BaseMailboxController {
} }
} }
} }
}
late EquatableMixin ruleFilterRequest; late EquatableMixin ruleFilterRequest;
+19 -7
View File
@@ -1,5 +1,5 @@
{ {
"@@last_modified": "2024-08-23T16:45:33.629548", "@@last_modified": "2024-09-10T15:59:25.469570",
"initializing_data": "Initializing data...", "initializing_data": "Initializing data...",
"@initializing_data": { "@initializing_data": {
"type": "text", "type": "text",
@@ -2134,12 +2134,6 @@
"placeholders_order": [], "placeholders_order": [],
"placeholders": {} "placeholders": {}
}, },
"toastErrorMessageWhenCreateNewRule": "You have not filled in the information completely.",
"@toastErrorMessageWhenCreateNewRule": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"vacationSettingExplanation": "Sends an automated reply to incoming messages.", "vacationSettingExplanation": "Sends an automated reply to incoming messages.",
"@vacationSettingExplanation": { "@vacationSettingExplanation": {
"type": "text", "type": "text",
@@ -3993,5 +3987,23 @@
"type": "text", "type": "text",
"placeholders_order": [], "placeholders_order": [],
"placeholders": {} "placeholders": {}
},
"youHaveNotAddedConditionToRule": "You have not added a condition to the rule.",
"@youHaveNotAddedConditionToRule": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"youHaveNotAddedActionToRule": "You have not added a action to the rule.",
"@youHaveNotAddedActionToRule": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"youHaveNotSelectedAnyActionForRule": "You have not selected any action for the rule.",
"@youHaveNotSelectedAnyActionForRule": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
} }
} }
+18 -6
View File
@@ -2192,12 +2192,6 @@ class AppLocalizations {
name: 'toastMessageDeleteEmailRuleSuccessfully'); name: 'toastMessageDeleteEmailRuleSuccessfully');
} }
String get toastErrorMessageWhenCreateNewRule {
return Intl.message(
'You have not filled in the information completely.',
name: 'toastErrorMessageWhenCreateNewRule');
}
String get vacationSettingExplanation { String get vacationSettingExplanation {
return Intl.message( return Intl.message(
'Sends an automated reply to incoming messages.', 'Sends an automated reply to incoming messages.',
@@ -4187,4 +4181,22 @@ class AppLocalizations {
name: 'spamFolderNotFound', name: 'spamFolderNotFound',
); );
} }
String get youHaveNotAddedConditionToRule {
return Intl.message(
'You have not added a condition to the rule.',
name: 'youHaveNotAddedConditionToRule');
}
String get youHaveNotAddedActionToRule {
return Intl.message(
'You have not added a action to the rule.',
name: 'youHaveNotAddedActionToRule');
}
String get youHaveNotSelectedAnyActionForRule {
return Intl.message(
'You have not selected any action for the rule.',
name: 'youHaveNotSelectedAnyActionForRule');
}
} }