1- import React from 'react' ;
1+ import React , { useEffect , useState } from 'react' ;
22import { useTranslation } from 'react-i18next' ;
33import { Form , Field } from 'react-final-form' ;
44import { useDispatch } from 'react-redux' ;
@@ -7,8 +7,23 @@ import { validateLogin } from '../../../utils/reduxFormUtils';
77import { validateAndLoginUser } from '../actions' ;
88
99function LoginForm ( ) {
10+ const [ contentPresent , setContentPresent ] = useState ( false ) ;
1011 const { t } = useTranslation ( ) ;
1112
13+ useEffect ( ( ) => {
14+ const checkEmailElement = ( ) => {
15+ if (
16+ document . getElementById ( 'email' ) &&
17+ document . getElementById ( 'password' )
18+ ) {
19+ setContentPresent ( true ) ;
20+ } else {
21+ setContentPresent ( false ) ;
22+ }
23+ } ;
24+ checkEmailElement ( ) ;
25+ } , [ ] ) ;
26+
1227 const dispatch = useDispatch ( ) ;
1328 function onSubmit ( formProps ) {
1429 return dispatch ( validateAndLoginUser ( formProps ) ) ;
@@ -71,7 +86,10 @@ function LoginForm() {
7186 { submitError && ! modifiedSinceLastSubmit && (
7287 < span className = "form-error" > { submitError } </ span >
7388 ) }
74- < Button type = "submit" disabled = { submitting || pristine } >
89+ < Button
90+ type = "submit"
91+ disabled = { ( submitting || pristine ) && ! contentPresent }
92+ >
7593 { t ( 'LoginForm.Submit' ) }
7694 </ Button >
7795 </ form >
0 commit comments