fix(validations): Make validations and errors text more specific

pull/135/head
NaiJi ✨ 2022-10-08 16:14:20 +00:00
parent e619d6351f
commit c4f3b76414
7 changed files with 32 additions and 22 deletions

View File

@ -258,6 +258,7 @@
"could_not_create_user": "Couldn't create user",
"could_not_delete_user": "Couldn't delete user",
"could_not_add_ssh_key": "Couldn't add SSH key",
"username_rule": "Must contain only lowercase latin letters, digits and underscores, should not start with a digit",
"email_login": "Email login",
"no_ssh_notice": "Only email and SSH accounts are created for this user. Single Sign On for all services is coming soon."
},
@ -418,13 +419,13 @@
"reset_user_password": "Reset password of user"
},
"validations": {
"required": "Required.",
"invalid_format": "Invalid format.",
"root_name": "User name cannot be 'root'.",
"key_format": "Invalid key format.",
"length_not_equal": "Length is []. Should be {}.",
"length_longer": "Length is []. Should be shorter than or equal to {}.",
"user_already_exist": "This user already exists.",
"key_already_exists": "This key already exists."
"required": "Required",
"already_exist": "Already exists",
"invalid_format": "Invalid format",
"invalid_format_password": "Must not contain empty characters",
"invalid_format_ssh": "Must follow the SSH key format",
"root_name": "Cannot be 'root'",
"length_not_equal": "Length is [], should be {}",
"length_longer": "Length is [], should be shorter than or equal to {}"
}
}

View File

@ -258,6 +258,7 @@
"could_not_create_user": "Не удалось создать пользователя",
"could_not_delete_user": "Не удалось стереть пользователя",
"could_not_add_ssh_key": "Не удалось создать SSH ключить",
"username_rule": "Может содержать только маленькие латинские буквы, цифры, подчёркивания, не может начинаться с цифр",
"email_login": "Авторизация по Email",
"no_ssh_notice": "Для этого пользователя созданы только SSH и Email аккаунты. Единая авторизация для всех сервисов ещё не реализована."
},
@ -419,13 +420,13 @@
"reset_user_password": "Сбросить пароль пользователя"
},
"validations": {
"required": "Обязательное поле.",
"invalid_format": "Неверный формат.",
"root_name": "Имя пользователя не может быть 'root'.",
"key_format": "Неверный формат.",
"length_not_equal": "Длина строки []. Должно быть равно {}.",
"length_longer": "Длина строки []. Должно быть меньше либо равно {}.",
"user_already_exist": "Имя уже используется.",
"key_already_exists": "Этот ключ уже добавлен."
"required": "Обязательное поле",
"already_exist": "Уже существует",
"invalid_format": "Неверный формат",
"invalid_format_password": "Должен не содержать пустые символы",
"invalid_format_ssh": "Должен следовать формату SSH ключей",
"root_name": "Имя пользователя не может быть 'root'",
"length_not_equal": "Длина строки [], должно быть равно {}",
"length_longer": "Длина строки [], должно быть меньше либо равно {}"
}
}

View File

@ -28,7 +28,7 @@ class FieldCubitFactory {
ValidationModel(
(final String login) =>
context.read<UsersCubit>().state.isLoginRegistered(login),
'validations.user_already_exist'.tr(),
'validations.already_exist'.tr(),
),
RequiredStringValidation('validations.required'.tr()),
LengthStringLongerValidation(userMaxLength),
@ -52,7 +52,7 @@ class FieldCubitFactory {
RequiredStringValidation('validations.required'.tr()),
ValidationModel<String>(
passwordForbiddenRegExp.hasMatch,
'validations.invalid_format'.tr(),
'validations.invalid_format_password'.tr(),
),
],
);

View File

@ -14,7 +14,7 @@ class DnsProviderFormCubit extends FormCubit {
RequiredStringValidation('validations.required'.tr()),
ValidationModel<String>(
regExp.hasMatch,
'validations.key_format'.tr(),
'validations.invalid_format'.tr(),
),
LengthStringNotEqualValidation(40)
],

View File

@ -15,7 +15,7 @@ class ProviderFormCubit extends FormCubit {
RequiredStringValidation('validations.required'.tr()),
ValidationModel<String>(
regExp.hasMatch,
'validations.key_format'.tr(),
'validations.invalid_format'.tr(),
),
LengthStringNotEqualValidation(64)
],

View File

@ -21,7 +21,7 @@ class SshFormCubit extends FormCubit {
ValidationModel(
(final String newKey) =>
user.sshKeys.any((final String key) => key == newKey),
'validations.key_already_exists'.tr(),
'validations.already_exists'.tr(),
),
RequiredStringValidation('validations.required'.tr()),
ValidationModel<String>(
@ -30,7 +30,7 @@ class SshFormCubit extends FormCubit {
print(keyRegExp.hasMatch(s));
return !keyRegExp.hasMatch(s);
},
'validations.invalid_format'.tr(),
'validations.invalid_format_ssh'.tr(),
),
],
);

View File

@ -55,6 +55,14 @@ class NewUser extends StatelessWidget {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (context.read<UserFormCubit>().state.isErrorShown)
Text(
'users.username_rule'.tr(),
style: TextStyle(
color: Theme.of(context).colorScheme.error,
),
),
const SizedBox(width: 14),
IntrinsicHeight(
child: CubitFormTextField(
formFieldCubit: context.read<UserFormCubit>().login,