diff --git a/src/App.js b/src/App.js
index d27da22..48cd61b 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 (
@@ -25,8 +26,10 @@ function App() {
} />
{/* sign up */}
} />
- {/* sign up */}
+ {/* sign in */}
} />
+ {/* my page */}
+ } />
diff --git a/src/apis/api.js b/src/apis/api.js
index 19a91e6..e8df08c 100644
--- a/src/apis/api.js
+++ b/src/apis/api.js
@@ -18,6 +18,16 @@ export const signUp = async (data) => {
return response;
};
+export const updateAccount = async (data) => {
+ const response = await instanceWithToken.patch(`/account/info/`, data);
+ if (response.status === 200) {
+ console.log("ACCOUNT UPDATE SUCCESS");
+ window.location.reload();
+ } else {
+ console.log("[ERROR] error while updating account");
+ }
+};
+
// GetUser API
// Edit, Delete 권한을 확인하거나, 프로필 페이지를 만들 때 사용하겠죠?
export const getUser = async () => {
@@ -61,27 +71,31 @@ export const updatePost = async (id, data, navigate) => {
}
};
-//과제!!
-export const deletePost = async (postId) => {
- const response = await instanceWithToken.delete(`/post/${postId}/`);
- if (response.status === 204) {
- console.log("DELETE SUCCESS");
- } else {
- console.log("[ERROR] error while deleting post");
+export const deletePost = async (id, navigate) => {
+ if (window.confirm("글을 삭제하시겠어요? 정말요?")) {
+ const response = await instanceWithToken.delete(`post/${id}/`);
+ if (response.status === 204) {
+ console.log("POST DELETE SUCCESS");
+ navigate("/");
+ } else {
+ console.log("[ERROR] error while deleting post");
+ }
}
};
+
//과제!!
-export const likePost = async (postId) => {
- const response = await instanceWithToken.post(`/post/${postId}/like/`);
+export const likePost = async (id) => {
+ const response = await instanceWithToken.post(`/post/${id}/like/`);
if (response.status === 200) {
console.log("POST LIKE SUCCESS");
+ window.location.reload();
} else {
- console.log("[ERROR] error while liking post");
+ console.log("[ERROR] error while creating like");
}
+
return response.data;
};
-
// Tag 관련 API들
export const getTags = async () => {
const response = await instance.get("/tag/");
@@ -125,11 +139,14 @@ export const updateComment = async (id, data) => {
};
//과제!!
-export const deleteComment = async (id) => {
- const response = await instanceWithToken.delete(`/comment/${id}/`);
- if (response.status === 204) {
- console.log("COMMENT DELETE SUCCESS");
- } else {
- console.log("[ERROR] error while deleting comment");
+ const isConfirmed = window.confirm("댓글을 삭제하시겠어요? 진짜요?");
+ if (isConfirmed) {
+ const response = await instanceWithToken.delete(`/comment/${id}/`);
+ if (response.status === 204) {
+ console.log("DELETE COMMENT SUCCESS");
+ window.location.reload();
+ } else {
+ console.log("[ERROR] error while deleting comment");
+ }
}
-};
\ No newline at end of file
+};
diff --git a/src/apis/axios.js b/src/apis/axios.js
index 4f7a53d..6912ccc 100644
--- a/src/apis/axios.js
+++ b/src/apis/axios.js
@@ -1,10 +1,10 @@
import axios from "axios";
import { getCookie } from "../utils/cookie";
-axios.defaults.baseURL = 'http://localhost:8000/api';
+axios.defaults.baseURL = "http://localhost:8000/api";
axios.defaults.withCredentials = true;
-axios.defaults.headers.post['Content-Type'] = 'application/json';
-axios.defaults.headers.common['X-CSRFToken'] = getCookie('csrftoken');
+axios.defaults.headers.post["Content-Type"] = "application/json";
+axios.defaults.headers.common["X-CSRFToken"] = getCookie("csrftoken");
// 누구나 접근 가능한 API들
export const instance = axios.create();
@@ -15,7 +15,7 @@ export const instanceWithToken = axios.create();
instanceWithToken.interceptors.request.use(
// 요청을 보내기전 수행할 일
(config) => {
- const accessToken = getCookie('access_token');
+ const accessToken = getCookie("access_token");
if (!accessToken) {
// token 없으면 리턴
@@ -37,7 +37,7 @@ instanceWithToken.interceptors.request.use(
instanceWithToken.interceptors.response.use(
(response) => {
- // 서버 응답 데이터를 프론트에 넘겨주기 전 수행할 일
+ // 서버 응답 데이터를 프론트에 넘겨주기 전 수행할 일
console.log("Interceptor Response!!");
return response;
},
diff --git a/src/components/Comment/CommentElement.jsx b/src/components/Comment/CommentElement.jsx
index 06c89e6..e45836a 100644
--- a/src/components/Comment/CommentElement.jsx
+++ b/src/components/Comment/CommentElement.jsx
@@ -48,6 +48,7 @@ const CommentElement = (props) => {
{year}.{month}.{day}
+
{user?.id === comment.author ? (
{isEdit ? (
diff --git a/src/components/Comment/index.jsx b/src/components/Comment/index.jsx
index 7320324..f788f01 100644
--- a/src/components/Comment/index.jsx
+++ b/src/components/Comment/index.jsx
@@ -17,17 +17,14 @@ const Comment = ({ postId }) => {
const handleCommentSubmit = (e) => {
e.preventDefault();
- setNewContent("");
createComment({ post: postId, content: newContent });
+ setNewContent("");
};
- // 과제!!
- const handleCommentDelete = async (commentId) => {
- const confirmDelete = window.confirm("정말로 댓글을 삭제하시겠습니까?");
- if (confirmDelete) {
- await deleteComment(commentId);
- window.location.reload();
- }
+
+ const handleCommentDelete = (comment_id) => {
+ console.log("delete");
+ deleteComment(comment_id);
};
return (
diff --git a/src/components/Form/index.jsx b/src/components/Form/index.jsx
index 1a2d250..023c8f1 100644
--- a/src/components/Form/index.jsx
+++ b/src/components/Form/index.jsx
@@ -1,4 +1,5 @@
-import { useState } from "react";
+import { useEffect, useState } from "react";
+import { getUser, updateAccount } from "../../apis/api";
export const SignUpForm = ({ formData, setFormData, handleSignUpSubmit }) => {
const handleFormData = (e) => {
@@ -261,3 +262,224 @@ export const PostForm = ({ onSubmit, tags, formData, setFormData }) => {
);
};
+
+export const MyPageForm = ({ formData, setFormData, handleUpdateAccount }) => {
+ const handleFormData = (e) => {
+ const { id, value } = e.target;
+
+ setFormData({ ...formData, [id]: value });
+ };
+
+ const [isEmailEdit, setIsEmailEdit] = useState(false);
+ const [isUsernameEdit, setIsUsernameEdit] = useState(false);
+ const [isCollegeEdit, setIsCollegeEdit] = useState(false);
+ const [isMajorEdit, setIsMajorEdit] = useState(false);
+
+ return (
+ <>
+
+
+
+
+
+
+
+ >
+ );
+};
diff --git a/src/components/Header/index.jsx b/src/components/Header/index.jsx
index 72f7e1e..e5e6183 100644
--- a/src/components/Header/index.jsx
+++ b/src/components/Header/index.jsx
@@ -14,6 +14,7 @@ const Header = () => {
removeCookie("access_token");
window.location.href = "/"; // 새로고침 - 로그아웃 되었다는 것을 인지시켜주기 위해
};
+
return (