feat: updatePassword, updateInfo 기능 연결

This commit is contained in:
정기영 2024-08-05 10:18:29 +09:00
parent ef4e56c860
commit 9727b55e0d
5 changed files with 29 additions and 6 deletions

View File

@ -1,11 +1,15 @@
import styles from './InfoEditForm.module.css';
import { useState } from 'react';
export default function InfoEditForm() {
export default function InfoEditForm({ onSubmit }) {
const [username, setUsername] = useState('');
const [useremail, setUseremail] = useState('');
return (
<form className={styles.infoEditForm}>
<form
onSubmit={(e) => onSubmit(e, username, useremail)}
className={styles.infoEditForm}
>
<p className={styles.textHeading}>이름 변경</p>
<div className={styles.inputBox}>
<label

View File

@ -2,6 +2,7 @@ import { useState, useRef } from 'react';
import styles from './PasswordChangeForm.module.css';
export default function PasswordChangeForm({ onSubmit, onPwError = false }) {
// TODO: onPwError( )
const [errorConfirmMessage, setErrorConfirmMessage] = useState(false);
const [errorSameMessage, setErrorSameMessage] = useState(false);
const currentPasswordRef = useRef('');

View File

@ -55,15 +55,23 @@ export function useAuth() {
.catch((e) => console.log(e));
};
const updateInfo = (name, email) => {
const infoBody = {
name,
email,
};
return instance.put(`${API_URL}/user/updateinfo`, infoBody);
};
const updatePassword = (currentPw, newPw, newPwCheck) => {
const passwordBody = {
currentPassword: currentPw,
newPassword: newPw,
newPasswordCheckL: newPwCheck,
newPasswordCheck: newPwCheck,
};
console.log(passwordBody);
return instance.put(`${API_URL}/user/updatepassword`, passwordBody);
};
return { login, logout, userRegister, updatePassword };
return { login, logout, userRegister, updateInfo, updatePassword };
}

View File

@ -1,5 +1,15 @@
import { InfoEditForm } from '../../components/InfoEditForm';
import { useAuth } from '../../hooks/api/useAuth';
export default function MyInfoChangePage() {
return <InfoEditForm />;
const { updateInfo } = useAuth();
const handleSubmit = async (e, username, useremail) => {
e.preventDefault();
await updateInfo(username, useremail)
.then((res) => console.log(res))
.catch((err) => console.log(err));
};
return <InfoEditForm onSubmit={handleSubmit} />;
}

View File

@ -12,7 +12,7 @@ const instance = axios.create({
instance.interceptors.request.use((config) => {
const accessToken = useBoundStore.getState().token;
console.log(accessToken);
if (accessToken) {
config.headers.Authorization = `${accessToken}`;
}