11import React , { Component } from 'react' ;
22import { Link as RouterLink } from 'react-router-dom' ;
3- import { Formik , Form , withFormik } from 'formik' ;
3+ import { Formik , Form } from 'formik' ;
44import * as Yup from 'yup' ;
55
66import {
@@ -64,10 +64,11 @@ class SignIn extends Component {
6464 * This should send an API request to identify the user.
6565 *
6666 * @param {string } username
67+ * @param {object } form
6768 *
6869 * @return {undefined }
6970 */
70- identify = async ( username = null ) => {
71+ identify = async ( username = null , form = { } ) => {
7172 this . setState ( { loading : true } ) ;
7273
7374 try {
@@ -96,9 +97,10 @@ class SignIn extends Component {
9697 }
9798
9899 const { errors } = error . response . data ;
99- const { setErrors } = this . props ;
100100
101- setErrors ( errors ) ;
101+ if ( errors ) {
102+ form . setErrors ( errors ) ;
103+ }
102104
103105 this . setState ( { loading : false } ) ;
104106 }
@@ -109,10 +111,11 @@ class SignIn extends Component {
109111 * Reload if authenticated.
110112 *
111113 * @param {object } values
114+ * @param {object } form
112115 *
113116 * @return {undefined }
114117 */
115- signin = async values => {
118+ signin = async ( values , form = { } ) => {
116119 this . setState ( { loading : true } ) ;
117120
118121 try {
@@ -138,9 +141,10 @@ class SignIn extends Component {
138141 }
139142
140143 const { errors } = error . response . data ;
141- const { setErrors } = this . props ;
142144
143- setErrors ( errors ) ;
145+ if ( errors ) {
146+ form . setErrors ( errors ) ;
147+ }
144148
145149 this . setState ( { loading : false } ) ;
146150 }
@@ -149,21 +153,24 @@ class SignIn extends Component {
149153 /**
150154 * Event listener that is triggered when the sign in form is submitted.
151155 *
156+ * @param {object } event
157+ * @param {object } form
158+ *
152159 * @return {undefined }
153160 */
154- handleSigninSubmit = async ( values , { setSubmitting } ) => {
155- setSubmitting ( false ) ;
161+ handleSigninSubmit = async ( values , form ) => {
162+ form . setSubmitting ( false ) ;
156163
157164 try {
158165 const { identified } = this . state ;
159166
160167 if ( ! identified ) {
161- await this . identify ( values . username ) ;
168+ await this . identify ( values . username , form ) ;
162169
163170 return ;
164171 }
165172
166- await this . signin ( values ) ;
173+ await this . signin ( values , form ) ;
167174 } catch ( error ) {
168175 this . setState ( {
169176 loading : false ,
@@ -242,7 +249,7 @@ class SignIn extends Component {
242249 } ) }
243250 >
244251 { ( { values, handleChange, errors, isSubmitting } ) => (
245- < Form >
252+ < Form autoComplete = "off" >
246253 < Grid container direction = "column" >
247254 { ! identified ? (
248255 < >
@@ -395,6 +402,4 @@ const styles = theme => ({
395402 } ,
396403} ) ;
397404
398- const Styled = withStyles ( styles ) ( SignIn ) ;
399-
400- export default withFormik ( { } ) ( Styled ) ;
405+ export default withStyles ( styles ) ( SignIn ) ;
0 commit comments