@@ -44,8 +44,9 @@ var _default = /*#__PURE__*/function (_Controller) {
44
44
} , {
45
45
key : "connect" ,
46
46
value : function connect ( ) {
47
- _get ( _getPrototypeOf ( _default . prototype ) , "connect" , this ) . call ( this ) ;
48
47
this . inputTarget . addEventListener ( 'input' , this . onInputChange ) ;
48
+ this . inputTarget . focus ( ) ;
49
+ _get ( _getPrototypeOf ( _default . prototype ) , "connect" , this ) . call ( this ) ;
49
50
}
50
51
} , {
51
52
key : "disconnect" ,
@@ -76,11 +77,18 @@ var _default = /*#__PURE__*/function (_Controller) {
76
77
} ( )
77
78
} , {
78
79
key : "onInputChange" ,
80
+ value : function onInputChange ( ) {
81
+ if ( this . inputTarget . value . length !== 6 ) return ;
82
+ this . submit ( ) ;
83
+ }
84
+ } , {
85
+ key : "submit" ,
79
86
value : function ( ) {
80
- var _onInputChange = _asyncToGenerator ( function * ( ) {
81
- if ( this . inputTarget . value . length !== 6 ) return ;
82
- this . inputTarget . disabled = true ;
83
- this . resendButtonTarget . disabled = true ;
87
+ var _submit = _asyncToGenerator ( function * ( ) {
88
+ if ( this . inputTarget . value . length !== 6 ) {
89
+ return alert ( _hellotext . default . business . locale . otp . invalid ) ;
90
+ }
91
+ this . disable ( ) ;
84
92
var response = yield _submissions . default . verifyOTP ( this . submissionIdValue , this . inputTarget . value ) ;
85
93
if ( response . succeeded ) {
86
94
this . dispatch ( 'verified' , {
@@ -90,15 +98,32 @@ var _default = /*#__PURE__*/function (_Controller) {
90
98
} ) ;
91
99
} else {
92
100
alert ( _hellotext . default . business . locale . otp . invalid ) ;
101
+ setTimeout ( ( ) => {
102
+ this . inputTarget . value = '' ;
103
+ this . inputTarget . focus ( ) ;
104
+ } ) ;
93
105
}
94
- this . inputTarget . disabled = false ;
95
- this . resendButtonTarget . disabled = false ;
106
+ this . enable ( ) ;
96
107
} ) ;
97
- function onInputChange ( ) {
98
- return _onInputChange . apply ( this , arguments ) ;
108
+ function submit ( ) {
109
+ return _submit . apply ( this , arguments ) ;
99
110
}
100
- return onInputChange ;
111
+ return submit ;
101
112
} ( ) // private
113
+ } , {
114
+ key : "disable" ,
115
+ value : function disable ( ) {
116
+ this . inputTarget . disabled = true ;
117
+ this . resendButtonTarget . disabled = true ;
118
+ this . submitButtonTarget . disabled = true ;
119
+ }
120
+ } , {
121
+ key : "enable" ,
122
+ value : function enable ( ) {
123
+ this . inputTarget . disabled = false ;
124
+ this . resendButtonTarget . disabled = false ;
125
+ this . submitButtonTarget . disabled = false ;
126
+ }
102
127
} , {
103
128
key : "throttled" ,
104
129
get : function get ( ) {
@@ -111,4 +136,4 @@ exports.default = _default;
111
136
_default . values = {
112
137
submissionId : String
113
138
} ;
114
- _default . targets = [ 'input' , 'resendButton' ] ;
139
+ _default . targets = [ 'input' , 'submitButton' , ' resendButton'] ;
0 commit comments