Skip to content

Commit 948c887

Browse files
authored
Merge pull request #95 from DZaporozhan/feature/user-form-update
Feature/user-form-inputs-buttons-ui
2 parents 10478d7 + 5b4f001 commit 948c887

13 files changed

+221
-53
lines changed

src/components/Logout/Logout.styled.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import styled from 'styled-components';
2-
import { ReactComponent as SvgLogout } from './img/logout-icon.svg';
2+
import { ReactComponent as SvgLogout } from 'icons/logout-icon.svg';
33

44
export const Button = styled.button`
55
display: inline-flex;

src/components/UserData/UserData.jsx

+187-44
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ import {
2020
UserAvatar,
2121
UserInfoWrap,
2222
IconWraper,
23+
CheckIcon,
2324
} from './UserData.styled';
2425

25-
import avatar from './img/temp-avatar.jpg';
26+
import avatar from 'icons/temp-avatar.jpg';
2627
import Logout from 'components/Logout';
28+
import { useState } from 'react';
29+
// import { useRef } from 'react';
2730
// import { ReactComponent as SvgCross } from './img/svgCross.svg';
2831

2932
const nameRegExp = /^[a-zA-Zа-яА-Я]+(([' -][a-zA-Zа-яА-Я ])?[a-zA-Zа-яА-Я]*)*$/;
@@ -47,7 +50,7 @@ let schema = yup.object().shape({
4750
.required(),
4851
});
4952

50-
const initialValues = {
53+
let initialValues = {
5154
name: '',
5255
email: '',
5356
birthday: '',
@@ -56,22 +59,92 @@ const initialValues = {
5659
};
5760

5861
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+
5975
// const dispatch = useDispatch();
6076

61-
// const { imageURL, name, email, birthday, phone, city } =
77+
// const { imageURL, name, email, birthday, phone, city } = useSelector(selectUser);
6278
const { name, email, birthday, phone, city } = useSelector(selectUser);
6379

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+
// };
66120

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+
////////////////////////////
67138
// Червона консоль не працює
139+
// const user = useSelector(getUserInfo);
140+
// console.log(user);
141+
//
68142
// const {
69-
// imageURL,
70143
// userInfo: { name, email, birthday, phone, city },
71144
// } = useSelector(getUserInfo);
72145
////////////////////////////
73146

74-
// const handleSubmit = value => {
147+
// const handleSubmit = value => {`
75148
// dispatch(updateUser(value));
76149
// };
77150

@@ -101,48 +174,118 @@ const UserData = () => {
101174
</AddPhoto>
102175
</Thumb>
103176
</EditPhotoContainer>
177+
104178
<InfoContainer>
105179
<Formik
106180
initialValues={initialValues}
107181
validationSchema={schema}
108-
// onSubmit={handleSubmit}
182+
// onSubmit={handleSubmit}
109183
>
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+
)}
146289
</Formik>
147290
<Logout />
148291
</InfoContainer>

src/components/UserData/UserData.styled.jsx

+30-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Field, ErrorMessage, Form } from 'formik';
2-
import { ReactComponent as EditSvg } from './img/edit-icon.svg';
3-
import { ReactComponent as CameraSvg } from './img/camera-icon.svg';
2+
import { ReactComponent as EditSvg } from 'icons/edit-icon.svg';
3+
import { ReactComponent as CameraSvg } from 'icons/camera-icon.svg';
4+
import { ReactComponent as CheckSvg } from 'icons/check-icon.svg';
45

56
import styled from 'styled-components';
67

@@ -109,8 +110,7 @@ export const IconWraper = styled.div`
109110
`;
110111

111112
export const CameraIcon = styled(CameraSvg)`
112-
fill: ${p => p.theme.colors.accent};
113-
113+
fill: ${p => p.theme.colors.accent};
114114
`;
115115

116116
export const InfoContainer = styled.div`
@@ -178,19 +178,26 @@ export const Input = styled(Field)`
178178
padding-bottom: 3px;
179179
180180
padding-left: 18px;
181-
border: 1px solid #ffffff;
181+
border: 1px solid rgba(245, 146, 86, 0.5);
182+
183+
background-color: #fdf7f2;
182184
border-radius: 40px;
183185
outline: none;
184186
color: #111111;
185187
186188
transition: background-color 250ms linear;
187189
transition: border 250ms linear;
188190
191+
&:disabled {
192+
background-color: #ffffff;
193+
border: 1px solid #ffffff;
194+
}
195+
/*
189196
&:hover,
190197
&:focus {
191198
background-color: #fdf7f2;
192199
border: 1px solid rgba(245, 146, 86, 0.5);
193-
}
200+
} */
194201
195202
@media ${p => p.theme.device.tablet} {
196203
font-size: 18px;
@@ -237,7 +244,23 @@ export const EditIcon = styled(EditSvg)`
237244
width: 12.5px;
238245
height: 12.5px;
239246
240-
fill: rgba(17, 17, 17, 0.6);
247+
/* fill: rgba(17, 17, 17, 0.6); */
248+
249+
@media ${p => p.theme.device.tablet} {
250+
width: 20px;
251+
height: 20px;
252+
}
253+
`;
254+
255+
export const CheckIcon = styled(CheckSvg)`
256+
display: flex;
257+
justify-content: center;
258+
align-items: center;
259+
/* background-repeat: no-repeat; */
260+
width: 12.5px;
261+
height: 12.5px;
262+
263+
fill: #f59256;
241264
242265
@media ${p => p.theme.device.tablet} {
243266
width: 20px;

src/components/UserData/UserImage/UserImage.jsx

Whitespace-only changes.

src/components/UserData/UserImage/UserImage.styled.jsx

Whitespace-only changes.
-77.2 KB
Binary file not shown.

src/components/UserData/img/check-icon.svg

-1
This file was deleted.
File renamed without changes.

src/icons/check-icon.svg

+3
Loading
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)