Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class _AccountDeletionButtonState extends State<AccountDeletionButton> {
Widget build(BuildContext context) {
final theme = AppFlowyTheme.of(context);
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/user/application/password/password_bloc.dart';
import 'package:appflowy/workspace/presentation/settings/pages/account/password/error_extensions.dart';
import 'package:appflowy/workspace/presentation/settings/pages/account/password/password_suffix_icon.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
Expand Down Expand Up @@ -342,18 +343,25 @@ class _ChangePasswordDialogContentState
message = LocaleKeys
.newSettings_myAccount_password_toast_passwordUpdatedFailed
.tr();
if (error.msg.contains('Incorrect current password')) {

if (AFPasswordErrorExtension.incorrectPasswordPattern
.hasMatch(error.msg)) {
currentPasswordTextFieldKey.currentState?.syncError(
errorText: LocaleKeys
.newSettings_myAccount_password_error_currentPasswordIsIncorrect
.tr(),
errorText: AFPasswordErrorExtension.getErrorMessage(error),
);
} else if (AFPasswordErrorExtension.tooShortPasswordPattern
.hasMatch(error.msg)) {
newPasswordTextFieldKey.currentState?.syncError(
errorText: AFPasswordErrorExtension.getErrorMessage(error),
);
} else if (AFPasswordErrorExtension.tooLongPasswordPattern
.hasMatch(error.msg)) {
newPasswordTextFieldKey.currentState?.syncError(
errorText: AFPasswordErrorExtension.getErrorMessage(error),
);
} else if (error.msg
.contains('Password should be at least 6 characters.')) {
} else {
newPasswordTextFieldKey.currentState?.syncError(
errorText: LocaleKeys
.newSettings_myAccount_password_error_passwordShouldBeAtLeast6Characters
.tr(),
errorText: error.msg,
);
}
},
Expand All @@ -367,9 +375,6 @@ class _ChangePasswordDialogContentState
},
(error) {
hasError = true;
message = LocaleKeys
.newSettings_myAccount_password_toast_passwordSetupFailed
.tr();
},
);
}
Expand All @@ -379,9 +384,6 @@ class _ChangePasswordDialogContentState
showToastNotification(
message: message,
);
}

if (!hasError) {
Navigator.of(context).pop();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:easy_localization/easy_localization.dart';

class AFPasswordErrorExtension {
static final RegExp incorrectPasswordPattern =
RegExp('Incorrect current password');
static final RegExp tooShortPasswordPattern =
RegExp(r'Password should be at least (\d+) characters');
static final RegExp tooLongPasswordPattern =
RegExp(r'Password cannot be longer than (\d+) characters');

static String getErrorMessage(FlowyError error) {
final msg = error.msg;
if (incorrectPasswordPattern.hasMatch(msg)) {
return LocaleKeys
.newSettings_myAccount_password_error_currentPasswordIsIncorrect
.tr();
} else if (tooShortPasswordPattern.hasMatch(msg)) {
return LocaleKeys
.newSettings_myAccount_password_error_passwordShouldBeAtLeast6Characters
.tr(
namedArgs: {
'min': tooShortPasswordPattern.firstMatch(msg)?.group(1) ?? '6',
},
);
} else if (tooLongPasswordPattern.hasMatch(msg)) {
return LocaleKeys
.newSettings_myAccount_password_error_passwordCannotBeLongerThan72Characters
.tr(
namedArgs: {
'max': tooLongPasswordPattern.firstMatch(msg)?.group(1) ?? '72',
},
);
}

return msg;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/user/application/password/password_bloc.dart';
import 'package:appflowy/workspace/presentation/settings/pages/account/password/error_extensions.dart';
import 'package:appflowy/workspace/presentation/settings/pages/account/password/password_suffix_icon.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
Expand Down Expand Up @@ -268,7 +269,6 @@ class _SetupPasswordDialogContentState
void _onPasswordStateChanged(BuildContext context, PasswordState state) {
bool hasError = false;
String message = '';
String description = '';

final setPasswordResult = state.setupPasswordResult;

Expand All @@ -281,22 +281,31 @@ class _SetupPasswordDialogContentState
},
(error) {
hasError = true;
message = LocaleKeys
.newSettings_myAccount_password_toast_passwordSetupFailed
.tr();
description = error.msg;
if (AFPasswordErrorExtension.tooShortPasswordPattern
.hasMatch(error.msg)) {
passwordTextFieldKey.currentState?.syncError(
errorText: AFPasswordErrorExtension.getErrorMessage(error),
);
} else if (AFPasswordErrorExtension.tooLongPasswordPattern
.hasMatch(error.msg)) {
passwordTextFieldKey.currentState?.syncError(
errorText: AFPasswordErrorExtension.getErrorMessage(error),
);
} else {
passwordTextFieldKey.currentState?.syncError(
errorText: error.msg,
);
}
},
);
}

if (!state.isSubmitting && message.isNotEmpty) {
showToastNotification(
message: message,
description: description,
type: hasError ? ToastificationType.error : ToastificationType.success,
);

if (!hasError) {
showToastNotification(
message: message,
);

Navigator.of(context).pop();
}
}
Expand Down
5 changes: 3 additions & 2 deletions frontend/resources/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2721,7 +2721,8 @@
"passwordsDoNotMatch": "Passwords do not match",
"newPasswordIsSameAsCurrent": "New password is same as current password",
"currentPasswordIsIncorrect": "Current password is incorrect",
"passwordShouldBeAtLeast6Characters": "Password should be at least 6 characters"
"passwordShouldBeAtLeast6Characters": "Password should be at least {min} characters",
"passwordCannotBeLongerThan72Characters": "Password cannot be longer than {max} characters"
},
"toast": {
"passwordUpdatedSuccessfully": "Password updated successfully",
Expand Down Expand Up @@ -3371,4 +3372,4 @@
"rewrite": "Rewrite",
"insertBelow": "Insert below"
}
}
}
26 changes: 13 additions & 13 deletions frontend/rust-lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions frontend/rust-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ num_enum = "0.7.3"
# Run the script.add_workspace_members:
# scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "c7176311ca375a672bc01bec0baa101986af023f" }
client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "c7176311ca375a672bc01bec0baa101986af023f" }
workspace-template = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "c7176311ca375a672bc01bec0baa101986af023f" }
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "6ed0f4e" }
client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "6ed0f4e" }
workspace-template = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "6ed0f4e" }

[profile.dev]
opt-level = 0
Expand Down
Loading