From 15cc421525d26264c00baa5744b54b57425d5900 Mon Sep 17 00:00:00 2001 From: Dat PHAM HOANG Date: Fri, 6 May 2022 17:36:14 +0700 Subject: [PATCH] TF-518 Handle missing field in login form --- .../presentation/utils/responsive_utils.dart | 2 +- .../login/presentation/base_login_view.dart | 19 ++++++---- .../login/presentation/login_controller.dart | 8 +++-- .../login/presentation/login_view.dart | 1 - .../login/presentation/login_view_web.dart | 36 +++++++++---------- .../login/presentation/state/login_state.dart | 14 +++++++- .../widgets/login_text_input_builder.dart | 36 ------------------- lib/main/localizations/app_localizations.dart | 15 ++++++++ 8 files changed, 65 insertions(+), 66 deletions(-) diff --git a/core/lib/presentation/utils/responsive_utils.dart b/core/lib/presentation/utils/responsive_utils.dart index e1724650a..fb188d877 100644 --- a/core/lib/presentation/utils/responsive_utils.dart +++ b/core/lib/presentation/utils/responsive_utils.dart @@ -55,6 +55,6 @@ class ResponsiveUtils { double getWidthLoginButton() => _loginButtonWidth; bool isHeightShortest(BuildContext context) { - return MediaQuery.of(context).size.shortestSide < 600; + return MediaQuery.of(context).size.shortestSide < heightShortest; } } \ No newline at end of file diff --git a/lib/features/login/presentation/base_login_view.dart b/lib/features/login/presentation/base_login_view.dart index 3b2a7faa3..d03ab12f3 100644 --- a/lib/features/login/presentation/base_login_view.dart +++ b/lib/features/login/presentation/base_login_view.dart @@ -6,7 +6,6 @@ import 'package:core/presentation/views/text/text_field_builder.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:tmail_ui_user/features/login/domain/state/authentication_user_state.dart'; import 'package:tmail_ui_user/features/login/presentation/login_controller.dart'; import 'package:tmail_ui_user/features/login/presentation/login_form_type.dart'; import 'package:tmail_ui_user/features/login/presentation/state/login_state.dart'; @@ -29,9 +28,17 @@ abstract class BaseLoginView extends GetWidget { child: CenterTextBuilder() .key(const Key('login_message')) .text(loginState.viewState.fold( - (failure) => failure is AuthenticationUserFailure - ? AppLocalizations.of(context).unknown_error_login_message - : AppLocalizations.of(context).loginInputUrlMessage, + (failure) { + if (failure is LoginMissUrlAction) { + return AppLocalizations.of(context).requiredUrl; + } else if (failure is LoginMissUsernameAction) { + return AppLocalizations.of(context).requiredEmail; + } else if (failure is LoginMissPasswordAction) { + return AppLocalizations.of(context).requiredPassword; + } else { + return AppLocalizations.of(context).unknown_error_login_message; + } + }, (success) { if (loginController.loginFormType.value == LoginFormType.credentialForm || kIsWeb) { return AppLocalizations.of(context).loginInputCredentialMessage; @@ -42,9 +49,7 @@ abstract class BaseLoginView extends GetWidget { fontSize: 15, fontWeight: FontWeight.w400, color: loginState.viewState.fold( - (failure) => failure is AuthenticationUserFailure - ? AppColor.textFieldErrorBorderColor - : AppColor.colorNameEmail, + (failure) => AppColor.textFieldErrorBorderColor, (success) => AppColor.colorNameEmail))) .build() ) diff --git a/lib/features/login/presentation/login_controller.dart b/lib/features/login/presentation/login_controller.dart index 3caba72c5..67e1b7160 100644 --- a/lib/features/login/presentation/login_controller.dart +++ b/lib/features/login/presentation/login_controller.dart @@ -65,8 +65,12 @@ class LoginController extends GetxController { final password = _parsePassword(_passwordText); if (baseUri != null && userName != null && password != null) { _loginAction(baseUri, userName, password); - } else { - loginState.value = LoginState(Left(LoginMissPropertiesAction())); + } else if (baseUri == null) { + loginState.value = LoginState(Left(LoginMissUrlAction())); + } else if (userName == null) { + loginState.value = LoginState(Left(LoginMissUsernameAction())); + } else if (password == null) { + loginState.value = LoginState(Left(LoginMissPasswordAction())); } } diff --git a/lib/features/login/presentation/login_view.dart b/lib/features/login/presentation/login_view.dart index 0c360f46b..840519cc2 100644 --- a/lib/features/login/presentation/login_view.dart +++ b/lib/features/login/presentation/login_view.dart @@ -17,7 +17,6 @@ class LoginView extends BaseLoginView { @override Widget build(BuildContext context) { return Scaffold( - resizeToAvoidBottomInset: true, backgroundColor: AppColor.primaryLightColor, body: GestureDetector( onTap: () => FocusScope.of(context).unfocus(), diff --git a/lib/features/login/presentation/login_view_web.dart b/lib/features/login/presentation/login_view_web.dart index d71eb9325..b218ca877 100644 --- a/lib/features/login/presentation/login_view_web.dart +++ b/lib/features/login/presentation/login_view_web.dart @@ -100,32 +100,32 @@ class LoginView extends BaseLoginView { Padding( padding: const EdgeInsets.only(top: 16), child: (SloganBuilder(arrangedByHorizontal: true, ) - ..setLogoSVG(imagePaths.icEncrypted) - ..setSizeLogo(48.0) - ..setPadding(const EdgeInsets.only(left: 12)) - ..setSloganText(AppLocalizations.of(context).encryptedMailbox) - ..setSloganTextStyle(const TextStyle(fontSize: 24, fontWeight: FontWeight.w400, color: AppColor.colorNameEmail))) - .build() + ..setLogoSVG(imagePaths.icEncrypted) + ..setSizeLogo(48.0) + ..setPadding(const EdgeInsets.only(left: 12)) + ..setSloganText(AppLocalizations.of(context).encryptedMailbox) + ..setSloganTextStyle(const TextStyle(fontSize: 24, fontWeight: FontWeight.w400, color: AppColor.colorNameEmail))) + .build() ), Padding( padding: const EdgeInsets.only(top: 16), child: (SloganBuilder(arrangedByHorizontal: true, ) - ..setLogoSVG(imagePaths.icTeam) - ..setSizeLogo(48.0) - ..setPadding(const EdgeInsets.only(left: 12)) - ..setSloganText(AppLocalizations.of(context).manageEmailAsATeam) - ..setSloganTextStyle(const TextStyle(fontSize: 24, fontWeight: FontWeight.w400, color: AppColor.colorNameEmail))) - .build() + ..setLogoSVG(imagePaths.icTeam) + ..setSizeLogo(48.0) + ..setPadding(const EdgeInsets.only(left: 12)) + ..setSloganText(AppLocalizations.of(context).manageEmailAsATeam) + ..setSloganTextStyle(const TextStyle(fontSize: 24, fontWeight: FontWeight.w400, color: AppColor.colorNameEmail))) + .build() ), Padding( padding: const EdgeInsets.only(top: 16), child: (SloganBuilder(arrangedByHorizontal: true, ) - ..setLogoSVG(imagePaths.icIntegration) - ..setSizeLogo(48.0) - ..setPadding(const EdgeInsets.only(left: 12)) - ..setSloganText(AppLocalizations.of(context).multipleIntegrations) - ..setSloganTextStyle(const TextStyle(fontSize: 24, fontWeight: FontWeight.w400, color: AppColor.colorNameEmail))) - .build() + ..setLogoSVG(imagePaths.icIntegration) + ..setSizeLogo(48.0) + ..setPadding(const EdgeInsets.only(left: 12)) + ..setSloganText(AppLocalizations.of(context).multipleIntegrations) + ..setSloganTextStyle(const TextStyle(fontSize: 24, fontWeight: FontWeight.w400, color: AppColor.colorNameEmail))) + .build() ), Padding( padding: const EdgeInsets.only(top: 44), diff --git a/lib/features/login/presentation/state/login_state.dart b/lib/features/login/presentation/state/login_state.dart index 57474b060..6876f7a73 100644 --- a/lib/features/login/presentation/state/login_state.dart +++ b/lib/features/login/presentation/state/login_state.dart @@ -26,7 +26,19 @@ class LoginInitAction extends ViewState { } @immutable -class LoginMissPropertiesAction extends Failure { +class LoginMissUrlAction extends Failure { + @override + List get props => []; +} + +@immutable +class LoginMissUsernameAction extends Failure { + @override + List get props => []; +} + +@immutable +class LoginMissPasswordAction extends Failure { @override List get props => []; } \ No newline at end of file diff --git a/lib/features/login/presentation/widgets/login_text_input_builder.dart b/lib/features/login/presentation/widgets/login_text_input_builder.dart index 7ae6605f9..a722d9aa3 100644 --- a/lib/features/login/presentation/widgets/login_text_input_builder.dart +++ b/lib/features/login/presentation/widgets/login_text_input_builder.dart @@ -1,39 +1,3 @@ -// LinShare is an open source filesharing software, part of the LinPKI software -// suite, developed by Linagora. -// -// Copyright (C) 2020 LINAGORA -// -// This program is free software: you can redistribute it and/or modify it under the -// terms of the GNU Affero General Public License as published by the Free Software -// Foundation, either version 3 of the License, or (at your option) any later version, -// provided you comply with the Additional Terms applicable for LinShare software by -// Linagora pursuant to Section 7 of the GNU Affero General Public License, -// subsections (b), (c), and (e), pursuant to which you must notably (i) retain the -// display in the interface of the “LinShare™” trademark/logo, the "Libre & Free" mention, -// the words “You are using the Free and Open Source version of LinShare™, powered by -// Linagora © 2009–2020. Contribute to Linshare R&D by subscribing to an Enterprise -// offer!”. You must also retain the latter notice in all asynchronous messages such as -// e-mails sent with the Program, (ii) retain all hypertext links between LinShare and -// http://www.linshare.org, between linagora.com and Linagora, and (iii) refrain from -// infringing Linagora intellectual property rights over its trademarks and commercial -// brands. Other Additional Terms apply, see -//