Skip to content

Commit 9c5ca0f

Browse files
committed
refactor: edit페이지 리펙토링
1 parent 7323820 commit 9c5ca0f

File tree

3 files changed

+11
-29
lines changed

3 files changed

+11
-29
lines changed

src/pages/editprofile/components/CurrentPasswordInput.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { InputField } from '@/components/input';
22

33
interface CurrentPasswordInputPros {
4-
setValidity: (val: boolean) => void;
4+
onChange: (val: string) => void;
55
}
66

7-
function CurrentPasswordInput({ setValidity }: CurrentPasswordInputPros) {
7+
function CurrentPasswordInput({ onChange }: CurrentPasswordInputPros) {
88
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
9-
setValidity(e.target.value.length > 0);
9+
onChange(e.target.value);
1010
};
1111
return (
1212
<InputField
1313
type="password"
1414
id="current-password"
15-
name="current-password"
1615
onChange={handleChange}
1716
label="현재 비밀번호"
1817
placeholder="현재 비밀번호을 입력해 주세요"

src/pages/editprofile/components/PasswordEditForm.tsx

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,9 @@ function PasswordEditForm() {
1111
const navigate = useNavigate();
1212
const { openModal, closeModal } = useModalStore(); // 모달 관리
1313

14-
const [validity, setValidity] = useState({
15-
currentPassword: false,
16-
password: false,
17-
});
18-
19-
const buttonEnabled = Object.values(validity).every(Boolean);
20-
21-
// validity 업데이트 함수
22-
const updateValidity = (key: 'currentPassword' | 'password', value: boolean) => {
23-
setValidity((prev) => {
24-
if (prev[key] === value) return prev; // 값이 동일하면 변경 X
25-
return { ...prev, [key]: value };
26-
});
27-
};
28-
14+
const [currentPassword, setCurrentPassword] = useState('');
15+
const [password, setPassword] = useState('');
16+
const isButtonEnabled = currentPassword !== '' && password !== '';
2917
// 현재 비밀번호 확인 useMutation
3018
const {
3119
mutateAsync: checkCurrentPassword,
@@ -60,9 +48,6 @@ function PasswordEditForm() {
6048

6149
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
6250
e.preventDefault();
63-
const formData = new FormData(e.currentTarget);
64-
const currentPassword = formData.get('current-password') as string;
65-
const password = formData.get('password') as string;
6651
// 현재 비밀번호 확인
6752
try {
6853
await checkCurrentPassword(currentPassword);
@@ -103,9 +88,9 @@ function PasswordEditForm() {
10388
return (
10489
<form className="flex flex-col justify-between h-full p-5" onSubmit={handleSubmit}>
10590
<div className="flex flex-col">
106-
<CurrentPasswordInput setValidity={(value) => updateValidity('currentPassword', value)} />
91+
<CurrentPasswordInput onChange={setCurrentPassword} />
10792
<PasswordGroupSection
108-
setValidity={(value) => updateValidity('password', value)}
93+
onChange={setPassword}
10994
passwordLabel="새 비밀번호"
11095
confirmLabel="새 비밀번호 확인"
11196
passwordPlaceholder="새 비밀번호를 입력해 주세요"
@@ -116,7 +101,7 @@ function PasswordEditForm() {
116101
isLoading={isCheckingPassword || isChangingPassword}
117102
isSuccess={isSuccess}
118103
isError={isCheckPasswordError || isChangePasswordError}
119-
disabled={!buttonEnabled}
104+
disabled={!isButtonEnabled}
120105
type="submit"
121106
text="저장하기"
122107
/>

src/pages/editprofile/components/ProfileEditForm.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function ProfileEditForm() {
3636

3737
const [isMusicSelect, setIsMusicSelect] = useState(false);
3838
const [nickname, setNickname] = useState(''); // 닉네임
39-
const [isNicknameValid, setIsNicknameValid] = useState(false); // 닉네임 유효성
39+
const [isNicknameValid] = useState(false); // 닉네임 유효성
4040

4141
const prevProfileMusic = useRef<ProfileMusic | null>(null);
4242
const prevNickname = useRef<string>('');
@@ -51,8 +51,6 @@ function ProfileEditForm() {
5151
staleTime: 5 * 60 * 1000,
5252
});
5353

54-
// // console.log(userData);
55-
5654
const { mutate, isPending, isSuccess, isError } = useMutation({
5755
mutationFn: patchEditProfile,
5856
onSuccess: (data) => {
@@ -182,7 +180,7 @@ function ProfileEditForm() {
182180
rightElement="button" // 오른쪽 요소 타입
183181
/>
184182
</div>
185-
<NicknameInput initialText={nickname} setValidity={(val) => setIsNicknameValid(val)} />
183+
<NicknameInput initialText={nickname} onChange={setNickname} />
186184
</div>
187185
<Button
188186
type="submit"

0 commit comments

Comments
 (0)