diff --git a/src/App.js b/src/App.js
index d27da22..0a42959 100644
--- a/src/App.js
+++ b/src/App.js
@@ -8,6 +8,7 @@ import PostEditPage from "./routes/PostEditPage";
import SignUpPage from "./routes/SignUpPage";
import PostDetailPage from "./routes/PostDetailPage";
import SignInPage from "./routes/SignInPage";
+import MyPage from "./routes/MyPage";
function App() {
return (
@@ -27,6 +28,9 @@ function App() {
} />
{/* sign up */}
} />
+ {/* MyPage */}
+ } />
+
diff --git a/src/apis/api.js b/src/apis/api.js
index 9ccc1e4..71a4255 100644
--- a/src/apis/api.js
+++ b/src/apis/api.js
@@ -30,6 +30,16 @@ export const getUser = async () => {
return response.data;
};
+export const getMyPage = async () => {
+ const response = await instanceWithToken.get("/account/mypage/");
+ if (response.status === 200) {
+ console.log("GET USER SUCCESS");
+ } else {
+ console.log("[ERROR] error while updating comment");
+ }
+ return response.data;
+};
+
// Post 관련 API들
export const getPosts = async () => {
const response = await instance.get("/post/");
@@ -61,6 +71,15 @@ export const updatePost = async (id, data, navigate) => {
}
};
+export const updateMyInfo = async (data) => {
+ const response = await instanceWithToken.patch(`/account/info/`, data);
+ if (response.status === 201) {
+ console.log("POST UPDATE SUCCESS");
+ } else {
+ console.log("[ERROR] error while updating post");
+ }
+};
+
//과제!!
export const deletePost = async (id, navigate) => {
const response = await instanceWithToken.delete(`post/${id}/`)
diff --git a/src/components/Comment/index.jsx b/src/components/Comment/index.jsx
index e69de29..4960023 100644
--- a/src/components/Comment/index.jsx
+++ b/src/components/Comment/index.jsx
@@ -0,0 +1,66 @@
+import { useEffect, useState } from "react";
+import CommentElement from "./CommentElement";
+import { createComment, getComments, deleteComment } from "../../apis/api";
+
+
+const Comment = ({ postId }) => {
+ const [commentList, setCommentList] = useState([]); // state for comments
+ const [newContent, setNewContent] = useState(""); // state for new comment
+
+ useEffect(() => {
+ const getCommentsAPI = async () => {
+ const comments = await getComments(postId);
+ setCommentList(comments);
+ };
+ getCommentsAPI();
+ }, [postId]);
+
+ const handleCommentSubmit = (e) => {
+ e.preventDefault();
+ setNewContent("");
+ createComment({ post: postId, content: newContent });
+ };
+
+ // 과제!!
+ const handleCommentDelete = async (commentId) => {
+ const confirmDelete = window.confirm("정말로 댓글을 삭제하시겠습니까?");
+ if (confirmDelete) {
+ await deleteComment(commentId);
+ window.location.reload();
+ }
+ };
+
+ return (
+
+
Comments
+ {commentList.map((comment) => {
+ return (
+
+
+
+ );
+ })}
+ {/* comment form component */}
+
+
+ );
+};
+
+export default Comment;
\ No newline at end of file
diff --git a/src/components/EditInput/index.jsx b/src/components/EditInput/index.jsx
new file mode 100644
index 0000000..29bfac7
--- /dev/null
+++ b/src/components/EditInput/index.jsx
@@ -0,0 +1,139 @@
+import { Link } from "react-router-dom";
+import { useEffect, useState } from "react";
+import { updateMyInfo } from "../../apis/api";
+
+export const MyPageInput = ({ content }) => {
+ const [isEmailEdit, setIsEmailEdit] = useState(false);
+ const [isUsernameEdit, setIsUsernameEdit] = useState(false);
+ const [isCollegeEdit, setIsCollegeEdit] = useState(false);
+ const [isMajorEdit, setIsMajorEdit] = useState(false);
+ const [formData, setFormData] = useState(content);
+
+ const handleChange = (e) => {
+
+ if (e.target.id === "email" || e.target.id === "username")
+ {
+ setFormData({ ...formData, [`user`]: {...formData.user, [e.target.id]: e.target.value} });
+ }
+ else setFormData({ ...formData, [e.target.id]: e.target.value });
+ };
+
+ const onSubmit = async (e) => {
+ e.preventDefault();
+ await updateMyInfo(formData);
+ setIsEmailEdit(false);
+ setIsUsernameEdit(false);
+ setIsCollegeEdit(false);
+ setIsMajorEdit(false);
+ };
+
+ const onEmailEditClick = async (e) => {
+ setIsEmailEdit(true);
+ };
+
+ const onUsernameEditClick = async (e) => {
+ setIsUsernameEdit(true);
+ };
+
+ const onCollegeEditClick = async (e) => {
+ setIsCollegeEdit(true);
+ };
+
+ const onMajorEditClick = async (e) => {
+ setIsMajorEdit(true);
+ };
+
+
+ const onCancelClick = async (e) => {
+ setFormData(content);
+ };
+
+ return (
+ <>
+ {formData && (
+
+ )}
+ >
+ );
+};
diff --git a/src/components/Header/index.jsx b/src/components/Header/index.jsx
index 72f7e1e..9f171cf 100644
--- a/src/components/Header/index.jsx
+++ b/src/components/Header/index.jsx
@@ -1,19 +1,27 @@
-import { useEffect, useState } from "react";
+import { useEffect, useState, } from "react";
import lion from "../../assets/images/lion.jpeg";
-import { Link } from "react-router-dom";
+import { Link, useParams } from "react-router-dom";
import { getCookie, removeCookie } from "../../utils/cookie";
+
+
const Header = () => {
const [isUser, setIsUser] = useState("");
+
useEffect(() => {
const user = getCookie("access_token") ? true : false;
setIsUser(user);
}, []);
+
+
const handleLogout = () => {
removeCookie("access_token");
window.location.href = "/"; // 새로고침 - 로그아웃 되었다는 것을 인지시켜주기 위해
};
+
+
+
return (