11/* eslint-disable jsx-a11y/label-has-associated-control */
2- import React , { useState , useEffect } from 'react' ;
2+ import React , { useEffect } from 'react' ;
33import { useDispatch , useSelector , shallowEqual } from 'react-redux' ;
44import PropTypes from 'prop-types' ;
55import { Link } from 'react-router-dom' ;
@@ -11,10 +11,10 @@ import { validateEmail } from 'utils';
1111import './UserForm.scss' ;
1212import DatePicker from '../DatePicker' ;
1313
14- const UserForm = ( { isEditing, isProfile, userData , action } ) => {
14+ const UserForm = ( { isEditing, isProfile, user , setUser , action } ) => {
1515 const { loading } = useSelector (
16- state => ( {
17- loading : state . users . loading
16+ ( state ) => ( {
17+ loading : state . users . loading ,
1818 } ) ,
1919 shallowEqual
2020 ) ;
@@ -25,16 +25,14 @@ const UserForm = ({ isEditing, isProfile, userData, action }) => {
2525 return ( ) => dispatch ( usersCleanUp ( ) ) ;
2626 } , [ dispatch ] ) ;
2727
28- const [ user , setUser ] = useState ( userData ) ;
29-
3028 const onChangeHandler = useChangeHandler ( setUser ) ;
3129
32- const onFileChangedHandler = event => {
30+ const onFileChangedHandler = ( event ) => {
3331 const file = event . target . files [ 0 ] ;
34- setUser ( prevState => ( { ...prevState , file, logoUrl : null } ) ) ;
32+ setUser ( ( prevState ) => ( { ...prevState , file, logoUrl : null } ) ) ;
3533 } ;
3634
37- const onSubmitHandler = event => {
35+ const onSubmitHandler = ( event ) => {
3836 event . preventDefault ( ) ;
3937 dispatch (
4038 action ( { ...user , createdAt : user . createdAt , isEditing, isProfile } )
@@ -43,7 +41,7 @@ const UserForm = ({ isEditing, isProfile, userData, action }) => {
4341
4442 let emailInput = {
4543 modifier : null ,
46- message : { modifier : null , content : null }
44+ message : { modifier : null , content : null } ,
4745 } ;
4846
4947 const invalidEmail = user . email && ! validateEmail ( user . email ) ;
@@ -55,8 +53,8 @@ const UserForm = ({ isEditing, isProfile, userData, action }) => {
5553 modifier : 'is-danger' ,
5654 message : {
5755 modifier : 'is-danger' ,
58- content : invalidEmailMessage
59- }
56+ content : invalidEmailMessage ,
57+ } ,
6058 } ;
6159 }
6260
@@ -270,8 +268,9 @@ const UserForm = ({ isEditing, isProfile, userData, action }) => {
270268 < div className = "control" >
271269 < button
272270 type = "submit"
273- className = { `button is-primary ${ loading &&
274- 'is-loading' } `}
271+ className = { `button is-primary ${
272+ loading && 'is-loading'
273+ } `}
275274 disabled = { ! canSubmit }
276275 >
277276 < span > { useFormatMessage ( 'UserForm.submit' ) } </ span >
@@ -383,7 +382,7 @@ const UserForm = ({ isEditing, isProfile, userData, action }) => {
383382 weekday : 'short' ,
384383 year : 'numeric' ,
385384 month : 'short' ,
386- day : 'numeric'
385+ day : 'numeric' ,
387386 } ) }
388387 </ p >
389388 </ div >
@@ -404,9 +403,9 @@ UserForm.propTypes = {
404403 name : PropTypes . string . isRequired ,
405404 location : PropTypes . string ,
406405 logoUrl : PropTypes . string ,
407- createdAt : PropTypes . string . isRequired
406+ createdAt : PropTypes . string . isRequired ,
408407 } ) ,
409- action : PropTypes . func . isRequired
408+ action : PropTypes . func . isRequired ,
410409} ;
411410
412411export default UserForm ;
0 commit comments