Skip to content

Commit

Permalink
TF-3051 Fix should not allow create rule with no actions
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 authored and hoangdat committed Sep 13, 2024
1 parent 3c5b0d9 commit 489db05
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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/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/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/email_rule_filter_action.dart';
import 'package:tmail_ui_user/features/rules_filter_creator/presentation/model/rule_filter_action_arguments.dart';
Expand Down Expand Up @@ -442,66 +443,80 @@ class RulesFilterCreatorController extends BaseMailboxController {
return;
}

if (listRuleCondition.isNotEmpty) {
String? errorConditionString;
for (var ruleCondition in listRuleCondition) {
errorConditionString = _getErrorStringByInputValue(context, ruleCondition.value);
log('RulesFilterCreatorController::createNewRuleFilter:errorConditionString: $errorConditionString');
if (errorConditionString != null) {
int ruleConditionIndex = listRuleCondition.indexOf(ruleCondition);
RulesFilterInputFieldArguments newRuleConditionValueArguments = RulesFilterInputFieldArguments(
focusNode: listRuleConditionValueArguments[ruleConditionIndex].focusNode,
errorText: errorConditionString,
controller: listRuleConditionValueArguments[ruleConditionIndex].controller,
);
listRuleConditionValueArguments[ruleConditionIndex] = newRuleConditionValueArguments;
listRuleConditionValueArguments[listRuleCondition.indexOf(ruleCondition)].focusNode.requestFocus();
}
}
if (errorConditionString?.isNotEmpty == true) {
if (listRuleCondition.isEmpty
&& currentOverlayContext != null
&& currentContext != null
) {
appToast.showToastErrorMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).youHaveNotAddedConditionToRule);
return;
}

for (var ruleCondition in listRuleCondition) {
final errorConditionString = _getErrorStringByInputValue(context, ruleCondition.value);
log('RulesFilterCreatorController::createNewRuleFilter:errorConditionString: $errorConditionString');
if (errorConditionString != null) {
int ruleConditionIndex = listRuleCondition.indexOf(ruleCondition);
RulesFilterInputFieldArguments newRuleConditionValueArguments = RulesFilterInputFieldArguments(
focusNode: listRuleConditionValueArguments[ruleConditionIndex].focusNode,
errorText: errorConditionString,
controller: listRuleConditionValueArguments[ruleConditionIndex].controller,
);
listRuleConditionValueArguments[ruleConditionIndex] = newRuleConditionValueArguments;
listRuleConditionValueArguments[listRuleCondition.indexOf(ruleCondition)].focusNode.requestFocus();
return;
}
}

if (listRuleCondition.isEmpty == true || listEmailRuleFilterActionSelected.isEmpty == true) {
if (currentOverlayContext != null && currentContext != null) {
appToast.showToastErrorMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).toastErrorMessageWhenCreateNewRule);
}
if (listEmailRuleFilterActionSelected.isEmpty
&& currentOverlayContext != null
&& currentContext != null
) {
appToast.showToastErrorMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).youHaveNotAddedActionToRule);
return;
}

if (listEmailRuleFilterActionSelected.isNotEmpty == true) {
for (var ruleFilterAction in listEmailRuleFilterActionSelected) {
if (ruleFilterAction is MoveMessageActionArguments) {
final errorAction = _getErrorStringByInputValue(context, mailboxSelected.value?.getDisplayName(context));
log('RulesFilterCreatorController::createNewRuleFilter:errorAction: $errorAction');
if (errorAction?.isNotEmpty == true) {
appToast.showToastErrorMessage(
context,
AppLocalizations.of(context).notSelectedMailboxToMoveMessage);
return;
}
if (listEmailRuleFilterActionSelected.isEmptySelectedRuleAction()
&& currentOverlayContext != null
&& currentContext != null
) {
appToast.showToastErrorMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).youHaveNotSelectedAnyActionForRule);
return;
}

for (var ruleFilterAction in listEmailRuleFilterActionSelected) {
if (ruleFilterAction is MoveMessageActionArguments) {
final errorAction = _getErrorStringByInputValue(context, mailboxSelected.value?.getDisplayName(context));
log('RulesFilterCreatorController::createNewRuleFilter:errorAction: $errorAction');
if (errorAction?.isNotEmpty == true) {
appToast.showToastErrorMessage(
context,
AppLocalizations.of(context).notSelectedMailboxToMoveMessage);
return;
}
if (ruleFilterAction is MarkAsSpamActionArguments) {
final spamMailboxId = getSpamMailboxId();
log('RulesFilterCreatorController::createNewRuleFilter:spamMailboxId: ${spamMailboxId?.asString}');
if (spamMailboxId == null) {
appToast.showToastErrorMessage(
context,
AppLocalizations.of(context).spamFolderNotFound);
return;
}
}
if (ruleFilterAction is MarkAsSpamActionArguments) {
final spamMailboxId = getSpamMailboxId();
log('RulesFilterCreatorController::createNewRuleFilter:spamMailboxId: ${spamMailboxId?.asString}');
if (spamMailboxId == null) {
appToast.showToastErrorMessage(
context,
AppLocalizations.of(context).spamFolderNotFound);
return;
}
if (ruleFilterAction is ForwardActionArguments) {
final errorAction = _getErrorStringByInputValue(context, ruleFilterAction.forwardEmail);
log('RulesFilterCreatorController::createNewRuleFilter:errorAction: $errorAction');
if (errorAction?.isNotEmpty == true) {
errorForwardEmailValue.value = errorAction;
forwardEmailFocusNode.requestFocus();
return;
}
}
if (ruleFilterAction is ForwardActionArguments) {
final errorAction = _getErrorStringByInputValue(context, ruleFilterAction.forwardEmail);
log('RulesFilterCreatorController::createNewRuleFilter:errorAction: $errorAction');
if (errorAction?.isNotEmpty == true) {
errorForwardEmailValue.value = errorAction;
forwardEmailFocusNode.requestFocus();
return;
}
}
}
Expand Down
26 changes: 19 additions & 7 deletions lib/l10n/intl_messages.arb
Original file line number Diff line number Diff line change
@@ -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": {
"type": "text",
Expand Down Expand Up @@ -2134,12 +2134,6 @@
"placeholders_order": [],
"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": {
"type": "text",
Expand Down Expand Up @@ -3993,5 +3987,23 @@
"type": "text",
"placeholders_order": [],
"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": {}
}
}
24 changes: 18 additions & 6 deletions lib/main/localizations/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2192,12 +2192,6 @@ class AppLocalizations {
name: 'toastMessageDeleteEmailRuleSuccessfully');
}

String get toastErrorMessageWhenCreateNewRule {
return Intl.message(
'You have not filled in the information completely.',
name: 'toastErrorMessageWhenCreateNewRule');
}

String get vacationSettingExplanation {
return Intl.message(
'Sends an automated reply to incoming messages.',
Expand Down Expand Up @@ -4187,4 +4181,22 @@ class AppLocalizations {
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');
}
}

0 comments on commit 489db05

Please sign in to comment.