Skip to content

Commit f247bd4

Browse files
committed
feat: 펫 추가 기능 생성
1 parent e60d8ed commit f247bd4

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/pages/Profile.jsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,26 @@ const Profile = ({ userInfo }) => {
3838
const navigate = useNavigate(); // 페이지 이동 함수
3939

4040
// 새 펫 받기 버튼 클릭 핸들러
41-
const handleGetNewPet = () => {
42-
alert("새 펫을 받는 기능은 아직 구현되지 않았습니다! 🐣");
43-
};
41+
const handleGetNewPet = async () => {
42+
try {
43+
const response = await fetch("/api/pet/new", {
44+
method: "POST",
45+
headers: {
46+
"Content-Type": "application/json",
47+
},
48+
});
49+
50+
if (!response.ok) {
51+
throw new Error("새 펫을 받을 수 없습니다.");
52+
}
53+
54+
alert("새 펫을 성공적으로 받았습니다! 🎉");
55+
window.location.reload(); // 페이지 새로고침
56+
} catch (error) {
57+
console.error("에러 발생:", error);
58+
alert("펫을 받는 데 실패했습니다. 다시 시도해주세요.");
59+
}
60+
};
4461

4562
// 프로필 정보 자동 새로고침 함수
4663
const refreshProfileData = async () => {

0 commit comments

Comments
 (0)