Skip to content

Commit 1ec4a45

Browse files
authored
refactor: 내정보 페이지 개선 (#198)
* fix: 사용자 페이지 팔로우 버튼 디버깅 * refactor: 사용자페이지 최적화 * chore: MyInfo div에 onClick에 navigate 추가 * refactor: MyInfoEdit 디바운스 제거 후 코드정리 * chore: 충돌 해결
1 parent 022cc48 commit 1ec4a45

2 files changed

Lines changed: 36 additions & 40 deletions

File tree

src/pages/MyInfoEditPage/index.jsx

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,62 @@ import { Text, PageWrapper, Input, Modal } from 'components';
44
import { useNavigate } from 'react-router-dom';
55
import { useState } from 'react';
66
import theme from 'styles/theme';
7-
import useDebounce from 'hooks/useDebounce';
87

98
const MyInfoEditPage = () => {
109
const { onChangePassword } = useUserContext();
1110
const navigate = useNavigate();
1211

1312
const [password, setPassword] = useState('');
14-
const [confirm, setConfirm] = useState('');
1513
const [passwordInvalid, setPasswordInvalid] = useState(false);
1614
const [confirmInvalid, setConfirmInvalid] = useState(false);
1715
const [errors, setErrors] = useState({});
1816
const [isModal, setIsModal] = useState(false);
19-
const [value, setValue] = useState('');
2017

2118
const onClose = () => {
2219
setIsModal(false);
2320
};
2421

2522
const regex = /\S{8,10}/;
2623

27-
const validate = useDebounce(
28-
() => {
29-
const newErrors = {};
30-
if (password && !regex.test(password)) {
31-
newErrors.password = '! 8-10자 사이로 공백없이 입력해주세요';
32-
setPasswordInvalid(true);
24+
const validate = (e) => {
25+
const { value, name } = e.target;
26+
27+
const newErrors = {};
28+
if (name === 'password') {
29+
if (value.length > 10) {
30+
e.target.value = value.slice(0, 10);
3331
}
34-
if (password.length > 10) {
32+
if (!regex.test(value)) {
3533
newErrors.password = '! 8-10자 사이로 공백없이 입력해주세요';
36-
setPassword(password.slice(0, 10));
3734
setPasswordInvalid(true);
3835
}
39-
if (confirm && password !== confirm) {
36+
setPassword(e.target.value);
37+
}
38+
if (name === 'confirm') {
39+
if (value.length > 10) {
40+
e.target.value = value.slice(0, 10);
41+
}
42+
if (password !== e.target.value) {
4043
newErrors.confirm = '! 비밀번호와 일치하지 않습니다.';
4144
setConfirmInvalid(true);
4245
}
43-
if (confirm.length > 10) {
44-
setConfirm(confirm.slice(0, 10));
45-
}
46-
setErrors(newErrors);
47-
!newErrors.password && setPasswordInvalid(false);
48-
!newErrors.confirm && setConfirmInvalid(false);
49-
},
50-
200,
51-
[password, confirm],
52-
);
46+
}
47+
48+
setErrors(newErrors);
49+
!newErrors.password && setPasswordInvalid(false);
50+
!newErrors.confirm && setConfirmInvalid(false);
51+
};
5352

5453
const handleSubmit = (e) => {
5554
e.preventDefault();
56-
if (password && confirm && !passwordInvalid && !confirmInvalid) {
55+
if (password && !passwordInvalid && !confirmInvalid) {
5756
onChangePassword(password);
5857
setIsModal(true);
5958
}
6059
};
6160
return (
6261
<PageWrapper header prev complete onComplete={handleSubmit}>
63-
<UserContainter>
62+
<UserContainer>
6463
<UserInfo>
6564
<Text
6665
style={{
@@ -74,18 +73,14 @@ const MyInfoEditPage = () => {
7473
>
7574
비밀번호를 설정해주세요
7675
</Text>
77-
<UserEditForm onSubmit={handleSubmit}>
76+
<UserEditForm>
7877
<Input
7978
label="변경할 비밀번호"
8079
style={{ marginTop: 5 }}
8180
type="password"
8281
name="password"
8382
inValid={passwordInvalid}
84-
value={password}
85-
onChange={(e) => {
86-
setPassword(e.target.value);
87-
validate();
88-
}}
83+
onChange={validate}
8984
></Input>
9085
{errors.password ? (
9186
<ErrorText>{errors.password}</ErrorText>
@@ -100,11 +95,7 @@ const MyInfoEditPage = () => {
10095
type="password"
10196
name="confirm"
10297
inValid={confirmInvalid}
103-
value={confirm}
104-
onChange={(e) => {
105-
setConfirm(e.target.value);
106-
validate();
107-
}}
98+
onChange={validate}
10899
></Input>
109100
{errors.confirm && <ErrorText>{errors.confirm}</ErrorText>}
110101
</UserEditForm>
@@ -122,14 +113,14 @@ const MyInfoEditPage = () => {
122113
</Modal.Button>
123114
</Modal>
124115
)}
125-
</UserContainter>
116+
</UserContainer>
126117
</PageWrapper>
127118
);
128119
};
129120

130121
export default MyInfoEditPage;
131122

132-
const UserContainter = styled.div`
123+
const UserContainer = styled.div`
133124
width: 100%;
134125
height: 100%;
135126
position: relative;

src/pages/MyInfoPage/UserDetails.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { Text, Icon, Modal } from 'components';
44
import { LOGOUT, KEY } from 'utils/constants/icons/names';
55
import { useUserContext } from 'contexts/UserContext';
66
import theme from 'styles/theme';
7-
import { navigate } from '@storybook/addon-links';
7+
import { useNavigate } from 'react-router-dom';
88

99
const UserDetails = () => {
10+
const navigate = useNavigate();
1011
const { currentUser, onLogout } = useUserContext();
1112
const [isLogoutModal, setIsLogoutModal] = useState(false);
1213

@@ -30,7 +31,11 @@ const UserDetails = () => {
3031
{currentUser.email}
3132
</Text>
3233
</UserDetail>
33-
<UserDetail>
34+
<UserDetail
35+
onClick={() => {
36+
navigate('/user/myInfo/edit');
37+
}}
38+
>
3439
<Icon.Link
3540
name={KEY}
3641
size={24}
@@ -45,7 +50,7 @@ const UserDetails = () => {
4550
</Text>
4651
</Icon.Link>
4752
</UserDetail>
48-
<UserDetail>
53+
<UserDetail onClick={() => setIsLogoutModal(true)}>
4954
<Icon.Button
5055
name={LOGOUT}
5156
size={24}

0 commit comments

Comments
 (0)