Skip to content

Commit

Permalink
feat: 설정 api patch 연동완료
Browse files Browse the repository at this point in the history
  • Loading branch information
DHowor1d committed Oct 28, 2024
1 parent 6ecf85d commit 774cc09
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/api/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import axios from 'axios';

export const updateUserInfo = async (token, userInfo) => {
try {
const response = await axios.patch('/api/member', userInfo, {
headers: {
Authorization: `Bearer ${token}`,
},
});
return response.data;
} catch (error) {
console.error('Failed to update user info', error);
throw error;
}
};
20 changes: 17 additions & 3 deletions src/components/Setting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useForm } from "react-hook-form";
import PageContainer from "./common/PageContainer";
import { useGetUserInfo } from "../hooks/useGetUserInfo";
import { getCookie } from "../api/cookie";
import { updateUserInfo } from "../api/user";

const Setting = () => {
const {data} = useGetUserInfo(getCookie('accessToken'));
Expand All @@ -21,7 +22,7 @@ const Setting = () => {
useEffect(() => {
if (data) {
setProfileImage(data.profileImage);
setName(data.name);
setName(data.nickname);
setEmail(data.email);
setDescription(data.intro);
}
Expand All @@ -43,8 +44,21 @@ const Setting = () => {
setIsEditing(true);
};

const handleSaveClick = () => {
setIsEditing(false);
const handleSaveClick = async () => {
try {
const token = getCookie('accessToken');
const userInfo = {
nickname: name,
intro: description,
};
const updatedData = await updateUserInfo(token, userInfo);
setIsEditing(false);
// 업데이트된 데이터를 상태에 반영
setName(updatedData.name);
setDescription(updatedData.intro);
} catch (error) {
console.error('Failed to save user info', error);
}
};

const handleEditTitleClick = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/MainPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const MainPage = () => {
))}
</div>
)}
<div className="w-full flex flex-row items-center justify-center my-5">
<div className="flex flex-row items-center justify-center w-full my-5">
<Pagination
count={totalPages}
page={pageNumber}
Expand Down

0 comments on commit 774cc09

Please sign in to comment.