@@ -20,10 +20,13 @@ import {
20
20
UserAvatar ,
21
21
UserInfoWrap ,
22
22
IconWraper ,
23
+ CheckIcon ,
23
24
} from './UserData.styled' ;
24
25
25
- import avatar from './img /temp-avatar.jpg' ;
26
+ import avatar from 'icons /temp-avatar.jpg' ;
26
27
import Logout from 'components/Logout' ;
28
+ import { useState } from 'react' ;
29
+ // import { useRef } from 'react';
27
30
// import { ReactComponent as SvgCross } from './img/svgCross.svg';
28
31
29
32
const nameRegExp = / ^ [ a - z A - Z а - я А - Я ] + ( ( [ ' - ] [ a - z A - Z а - я А - Я ] ) ? [ a - z A - Z а - я А - Я ] * ) * $ / ;
@@ -47,7 +50,7 @@ let schema = yup.object().shape({
47
50
. required ( ) ,
48
51
} ) ;
49
52
50
- const initialValues = {
53
+ let initialValues = {
51
54
name : '' ,
52
55
email : '' ,
53
56
birthday : '' ,
@@ -56,22 +59,92 @@ const initialValues = {
56
59
} ;
57
60
58
61
const UserData = ( ) => {
62
+ const [ nameDisabled , setNameDisabled ] = useState ( true ) ;
63
+ const [ emailDisabled , setEmailDisabled ] = useState ( true ) ;
64
+ const [ birthdayDisabled , setBirthdayDisabled ] = useState ( true ) ;
65
+ const [ phoneDisabled , setPhoneDisabled ] = useState ( true ) ;
66
+ const [ cityDisabled , setCityDisabled ] = useState ( true ) ;
67
+
68
+ const [ iconColor , setIconColor ] = useState ( '#f59256' ) ;
69
+
70
+ const [ typeBtn , setTypeBtn ] = useState ( 'button' ) ;
71
+ const [ inputValue , setInputValue ] = useState ( ) ;
72
+
73
+ // const ref = useRef(null);
74
+
59
75
// const dispatch = useDispatch();
60
76
61
- // const { imageURL, name, email, birthday, phone, city } =
77
+ // const { imageURL, name, email, birthday, phone, city } = useSelector(selectUser);
62
78
const { name, email, birthday, phone, city } = useSelector ( selectUser ) ;
63
79
64
- // const user = useSelector(getUserInfo);
65
- // console.log(user);
80
+ initialValues = {
81
+ name,
82
+ email,
83
+ birthday,
84
+ phone,
85
+ city,
86
+ } ;
87
+
88
+ // const handleChange = e => dispatch(setInputValue(e.currentTarget.value));
89
+ const handleChange = e => {
90
+ console . log ( e . currentTarget . value ) ;
91
+ console . log ( e . currentTarget ) ;
92
+ setInputValue ( e . currentTarget . value ) ;
93
+ console . log ( inputValue ) ;
94
+ } ;
95
+
96
+ // const handleSubmit = value => {
97
+ // console.log(value);
98
+ // // console.log(actions);
99
+ // };
100
+
101
+ const handleClick = ( e , disabled , setDisabled , fieldValue ) => {
102
+ const { type } = e . currentTarget ;
103
+
104
+ if ( disabled ) {
105
+ setDisabled ( false ) ;
106
+ setIconColor ( 'rgba(17, 17, 17, 0.6)' ) ;
107
+ } else {
108
+ setDisabled ( false ) ;
109
+ setIconColor ( '#f59256' ) ;
110
+ }
111
+ // if (type === 'button') {
112
+
113
+ // }
114
+ // console.log(name);
115
+
116
+ // const handleSubmit = fieldValue => {
117
+ // console.log(fieldValue);
118
+ // // console.log(actions);
119
+ // };
66
120
121
+ setDisabled ( ! disabled ) ;
122
+ // if (disabled) {
123
+
124
+ // }
125
+
126
+ // setIsDisabled(!isDisabled);
127
+ // console.log(e.currentTarget.id);
128
+ // console.log(name);
129
+
130
+ // setTypeBtn(prevState => (prevState === 'submit' ? 'button' : 'submit'));
131
+ // console.log(typeBtn);
132
+
133
+ // if (!isDisabled || e.currentTarget.id) {
134
+ // }
135
+ } ;
136
+
137
+ ////////////////////////////
67
138
// Червона консоль не працює
139
+ // const user = useSelector(getUserInfo);
140
+ // console.log(user);
141
+ //
68
142
// const {
69
- // imageURL,
70
143
// userInfo: { name, email, birthday, phone, city },
71
144
// } = useSelector(getUserInfo);
72
145
////////////////////////////
73
146
74
- // const handleSubmit = value => {
147
+ // const handleSubmit = value => {`
75
148
// dispatch(updateUser(value));
76
149
// };
77
150
@@ -101,48 +174,118 @@ const UserData = () => {
101
174
</ AddPhoto >
102
175
</ Thumb >
103
176
</ EditPhotoContainer >
177
+
104
178
< InfoContainer >
105
179
< Formik
106
180
initialValues = { initialValues }
107
181
validationSchema = { schema }
108
- // onSubmit={handleSubmit}
182
+ // onSubmit={handleSubmit}
109
183
>
110
- < InfoForm autoComplete = "off" >
111
- < Label htmlFor = "name" > Name:</ Label >
112
- < Input type = "text" name = "name" value = { name } />
113
- < Button type = "button" >
114
- < EditIcon />
115
- </ Button >
116
- { /* <ErrorText name="name" component="div" /> */ }
117
-
118
- < Label htmlFor = "email" > Email:</ Label >
119
- < Input type = "text" name = "email" value = { email } />
120
- < Button type = "button" >
121
- < EditIcon />
122
- </ Button >
123
- { /* <ErrorText name="email" component="div" /> */ }
124
-
125
- < Label htmlFor = "birthday" > Birthday:</ Label >
126
- < Input type = "text" name = "birthday" value = { birthday } />
127
- < Button type = "button" >
128
- < EditIcon />
129
- </ Button >
130
- { /* <ErrorText name="birthday" component="div" /> */ }
131
-
132
- < Label htmlFor = "phone" > Phone:</ Label >
133
- < Input type = "tel" name = "phone" value = { phone } />
134
- < Button type = "button" >
135
- < EditIcon />
136
- </ Button >
137
- { /* <ErrorText name="phone" component="div" /> */ }
138
-
139
- < Label htmlFor = "city" > City:</ Label >
140
- < Input type = "text" name = "city" value = { city } />
141
- < Button type = "button" >
142
- < EditIcon />
143
- </ Button >
144
- { /* <ErrorText name="city" component="div" /> */ }
145
- </ InfoForm >
184
+ { ( { values } ) => (
185
+ < InfoForm autoComplete = "off" >
186
+ < Label htmlFor = "name" > Name:</ Label >
187
+ < Input
188
+ // id="name"
189
+ type = "text"
190
+ name = "name"
191
+ // value={inputValue}
192
+ // onChange={handleChange}
193
+ disabled = { nameDisabled }
194
+ // touched="true"
195
+ />
196
+ < Button
197
+ name = "name"
198
+ type = { typeBtn }
199
+ onClick = { e =>
200
+ handleClick ( e , nameDisabled , setNameDisabled , values . name )
201
+ }
202
+ >
203
+ { nameDisabled ? < EditIcon fill = { iconColor } /> : < CheckIcon /> }
204
+ </ Button >
205
+ { /* <ErrorText name="name" component="div" /> */ }
206
+
207
+ < Label htmlFor = "email" > Email:</ Label >
208
+ < Input
209
+ type = "text"
210
+ name = "email"
211
+ // value={email}
212
+ disabled = { emailDisabled }
213
+ />
214
+ < Button
215
+ name = "email"
216
+ type = { typeBtn }
217
+ onClick = { e =>
218
+ handleClick ( e , emailDisabled , setEmailDisabled , values . email )
219
+ }
220
+ >
221
+ { emailDisabled ? < EditIcon fill = { iconColor } /> : < CheckIcon /> }
222
+ </ Button >
223
+ { /* <ErrorText name="email" component="div" /> */ }
224
+
225
+ < Label htmlFor = "birthday" > Birthday:</ Label >
226
+ < Input
227
+ type = "text"
228
+ name = "birthday"
229
+ // value={birthday}
230
+ disabled = { birthdayDisabled }
231
+ />
232
+ < Button
233
+ name = "birthday"
234
+ type = { typeBtn }
235
+ onClick = { e =>
236
+ handleClick (
237
+ e ,
238
+ birthdayDisabled ,
239
+ setBirthdayDisabled ,
240
+ values . birthday
241
+ )
242
+ }
243
+ >
244
+ { birthdayDisabled ? (
245
+ < EditIcon fill = { iconColor } />
246
+ ) : (
247
+ < CheckIcon />
248
+ ) }
249
+ </ Button >
250
+ { /* <ErrorText name="birthday" component="div" /> */ }
251
+
252
+ < Label htmlFor = "phone" > Phone:</ Label >
253
+ < Input
254
+ type = "tel"
255
+ name = "phone"
256
+ // value={phone}
257
+ disabled = { phoneDisabled }
258
+ />
259
+ < Button
260
+ name = "phone"
261
+ type = { typeBtn }
262
+ onClick = { e =>
263
+ handleClick ( e , phoneDisabled , setPhoneDisabled , values . phone )
264
+ }
265
+ >
266
+ { phoneDisabled ? < EditIcon fill = { iconColor } /> : < CheckIcon /> }
267
+ </ Button >
268
+ { /* <ErrorText name="phone" component="div" /> */ }
269
+
270
+ < Label htmlFor = "city" > City:</ Label >
271
+ < Input
272
+ type = "text"
273
+ name = "city"
274
+ // value={city}
275
+ disabled = { cityDisabled }
276
+ />
277
+ < Button
278
+ name = "city"
279
+ type = { typeBtn }
280
+ onClick = { e =>
281
+ handleClick ( e , cityDisabled , setCityDisabled , values . city )
282
+ }
283
+ >
284
+ { cityDisabled ? < EditIcon fill = { iconColor } /> : < CheckIcon /> }
285
+ </ Button >
286
+ { /* <ErrorText name="city" component="div" /> */ }
287
+ </ InfoForm >
288
+ ) }
146
289
</ Formik >
147
290
< Logout />
148
291
</ InfoContainer >
0 commit comments