File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -246,6 +246,36 @@ const LoginForm = (props: PropsForm) => {
246246npm start
247247```
248248
249+ - And let's add an alert (Excercise and a notification) when the user clicks and the form all the fields are valid.
250+
251+ _ ./src/pages/loginPage.tsx_
252+
253+ ``` diff
254+ const onLogin = () => {
255+ + loginFormValidation.validateForm(loginInfo)
256+ + .then((formValidationResult) => {
257+ + if(formValidationResult.succeeded) {
258+ if (isValidLogin(loginInfo)) {
259+ props.history.push("/pageB");
260+ } else {
261+ setShowLoginFailedMsg(true);
262+ }
263+ + } else {
264+ + alert('error, review the fields');
265+ + const updatedLoginFormErrors = {
266+ + ...loginFormErrors,
267+ + ...formValidationResult.fieldErrors,
268+ + }
269+ + setLoginFormErrors(updatedLoginFormErrors);
270+ + }
271+
272+
273+ + });
274+ };
275+ ```
276+
277+ > Excercise, refactor this method following single abstraction level principle and single resposibility principle.
278+
249279# About Basefactor + Lemoncode
250280
251281We are an innovating team of Javascript experts, passionate about turning your ideas into robust products.
Original file line number Diff line number Diff line change @@ -40,11 +40,22 @@ const LoginPageInner = (props: Props) => {
4040 const { classes } = props ;
4141
4242 const onLogin = ( ) => {
43- if ( isValidLogin ( loginInfo ) ) {
44- props . history . push ( "/pageB" ) ;
45- } else {
46- setShowLoginFailedMsg ( true ) ;
47- }
43+ loginFormValidation . validateForm ( loginInfo ) . then ( formValidationResult => {
44+ if ( formValidationResult . succeeded ) {
45+ if ( isValidLogin ( loginInfo ) ) {
46+ props . history . push ( "/pageB" ) ;
47+ } else {
48+ setShowLoginFailedMsg ( true ) ;
49+ }
50+ } else {
51+ alert ( "error, review the fields" ) ;
52+ const updatedLoginFormErrors = {
53+ ...loginFormErrors ,
54+ ...formValidationResult . fieldErrors
55+ } ;
56+ setLoginFormErrors ( updatedLoginFormErrors ) ;
57+ }
58+ } ) ;
4859 } ;
4960
5061 const onUpdateLoginField = ( name , value ) => {
You can’t perform that action at this time.
0 commit comments