@@ -2,88 +2,90 @@ import { ConfigurationContext } from "../context/configuration.js";
22import { errorTextTimeout , getPlaceholder , useTitle } from "../utils/utils.js" ;
33
44export default function GetCode ( ) {
5- const submitButtonText = i18next . t ( "button.get-code" ) ;
5+ const submitButtonText = i18next . t ( "button.get-code" ) ;
66
7- const configuration = React . useContext ( ConfigurationContext ) ;
7+ const configuration = React . useContext ( ConfigurationContext ) ;
88
9- const [ buttonText , setButtonText ] = React . useState ( submitButtonText ) ;
10- const [ hasError , setHasError ] = React . useState ( false ) ;
11- const [ submitting , setSubmitting ] = React . useState ( false ) ;
9+ const [ errorMessage , setErrorMessage ] = React . useState ( "" ) ;
10+ // hasError removed
11+ const [ submitting , setSubmitting ] = React . useState ( false ) ;
1212
13- React . useEffect ( ( ) => useTitle ( configuration [ "content.app-name" ] , i18next . t ( "title.verify-your-identity" ) ) , [ ] ) ;
13+ React . useEffect ( ( ) => useTitle ( configuration [ "content.app-name" ] , i18next . t ( "title.verify-your-identity" ) ) , [ ] ) ;
1414
15- const onSubmitError = ( props ) => {
16- if ( hasError ) {
17- return ;
18- }
19- setHasError ( true ) ;
20- setButtonText ( props . errorText ) ;
21- setTimeout ( ( ) => {
22- setButtonText ( submitButtonText ) ;
23- setHasError ( false ) ;
24- } , errorTextTimeout ) ;
25- } ;
15+ const onSubmitError = ( props ) => {
16+
17+ setErrorMessage ( props . errorText ) ;
18+ } ;
2619
27- function getCode ( event ) {
28- event . preventDefault ( ) ;
29- const email = document . getElementById ( "email" ) . value ;
30- setSubmitting ( true ) ;
31- $ . get ( "/user/code" , {
32- email,
33- } )
34- . done ( function ( response ) {
35- const urlParams = new URLSearchParams ( window . location . search ) ;
36- urlParams . set ( 'target' , response . data . target ) ;
37- window . location = `/reset-password?${ urlParams . toString ( ) } ` ;
38- } )
39- . fail ( function ( response ) {
40- if ( response . responseJSON . additionalInfo && response . status === 400 ) {
41- return onFieldError ( { response } ) ;
42- }
43- onSubmitError ( { errorText : i18next . t ( "error.invalid-login" ) } ) ;
44- } )
45- . always ( function ( ) {
46- setSubmitting ( false ) ;
47- } ) ;
48- }
20+ function getCode ( event ) {
21+ event . preventDefault ( ) ;
22+ setErrorMessage ( "" ) ;
23+
24+ const email = document . getElementById ( "email" ) . value ;
25+ setSubmitting ( true ) ;
26+ $ . get ( "/user/code" , {
27+ email,
28+ } )
29+ . done ( function ( response ) {
30+ const urlParams = new URLSearchParams ( window . location . search ) ;
31+ urlParams . set ( "target" , response . data . target ) ;
32+ window . location = `/reset-password?${ urlParams . toString ( ) } ` ;
33+ } )
34+ . fail ( function ( response ) {
35+ if ( response . responseJSON . additionalInfo && response . status === 400 ) {
36+ return onFieldError ( { response } ) ;
37+ }
38+ onSubmitError ( { errorText : i18next . t ( "error.invalid-login" ) } ) ;
39+ } )
40+ . always ( function ( ) {
41+ setSubmitting ( false ) ;
42+ } ) ;
43+ }
4944
50- if ( ! configuration [ "privilege.can-reset-password" ] ) {
51- return null ;
52- }
45+ if ( ! configuration [ "privilege.can-reset-password" ] ) {
46+ return null ;
47+ }
5348
54- return (
55- < form className = { `form ${ configuration [ "form.animate-entrance" ] && "animate-jelly" } ` } onSubmit = { getCode } >
56- < div className = "noselect" >
57- < h3 >
58- { i18next . t ( "heading.verify-your-identity" ) }
59- </ h3 >
60- < p className = "app-tagline" > { i18next . t ( "message.recover-instructions" ) } </ p >
61- </ div >
62- < div className = "form-group first last" >
63- < label className = "noselect" htmlFor = "email" > { i18next . t ( "field.label.email" ) } </ label >
64- < input
65- type = "email"
66- className = "form-control"
67- aria-label = "Email"
68- aria-required = "true"
69- placeholder = { getPlaceholder ( i18next . t ( "field.placeholder.email" ) , configuration ) }
70- minLength = "8"
71- autoComplete = "off"
72- autoCorrect = "off"
73- autoCapitalize = "off"
74- spellCheck = "false"
75- id = "email"
76- required
77- />
78- </ div >
79- < div className = "page-links" >
80- < span className = "page-link" >
81- < a href = { "/login" + window . location . search } className = "page-link" aria-label = "Login" >
82- { i18next . t ( "link.login-minimal" ) }
83- </ a >
84- </ span >
85- </ div >
86- < input type = "submit" disabled = { submitting } className = { "button" + ( hasError ? " shake" : "" ) } value = { buttonText } />
87- </ form >
88- ) ;
49+ return (
50+ < form className = "form" onSubmit = { getCode } >
51+ < div className = "noselect" >
52+ < h3 > { i18next . t ( "heading.verify-your-identity" ) } </ h3 >
53+ < p className = "app-tagline" > { i18next . t ( "message.recover-instructions" ) } </ p >
54+ </ div >
55+ < div className = "form-group first last" >
56+ < label className = "noselect" htmlFor = "email" >
57+ { i18next . t ( "field.label.email" ) }
58+ </ label >
59+ < input
60+ type = "email"
61+ className = "form-control"
62+ aria-label = "Email"
63+ aria-required = "true"
64+ placeholder = { getPlaceholder ( i18next . t ( "field.placeholder.email" ) , configuration ) }
65+ minLength = "8"
66+ autoComplete = "off"
67+ autoCorrect = "off"
68+ autoCapitalize = "off"
69+ spellCheck = "false"
70+ id = "email"
71+ required
72+ />
73+ </ div >
74+ < div className = "page-links" >
75+ < span className = "page-link" >
76+ < a href = { "/login" + window . location . search } className = "page-link" aria-label = "Login" >
77+ { i18next . t ( "link.login-minimal" ) }
78+ </ a >
79+ </ span >
80+ </ div >
81+ < input
82+ type = "submit"
83+ disabled = { submitting }
84+ className = "button"
85+ value = { submitButtonText }
86+ />
87+ < div className = "form-error-message" > { errorMessage } </ div >
88+ </ form >
89+ ) ;
8990}
91+
0 commit comments