From ef8e88fa98672ce4d7fe5e20245db8aa1f6769af Mon Sep 17 00:00:00 2001 From: zereight Date: Thu, 22 Jul 2021 21:03:46 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EB=8C=93=EA=B8=80=20=EB=AA=A8?= =?UTF-8?q?=EB=93=88=20=EA=B4=80=EB=A6=AC=EC=9E=90=20=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reply-module/src/components/molecules/Comment/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/reply-module/src/components/molecules/Comment/index.tsx b/frontend/reply-module/src/components/molecules/Comment/index.tsx index 40fe94d59..7e85f6be3 100644 --- a/frontend/reply-module/src/components/molecules/Comment/index.tsx +++ b/frontend/reply-module/src/components/molecules/Comment/index.tsx @@ -48,6 +48,8 @@ const Comment = ({ user, comment, align = "left", shouldShowOption, iAmAdmin, th const isEditable = (iAmAdmin && thisCommentIsMine) || !iAmAdmin; + const isEditable = (iAmAdmin && thisCommentIsMine) || !iAmAdmin; + const confirmGuestPassword = async () => { try { await editComment({ From 5a002f8f51304bd7c19fd76fdd8dac62ebb9f7ce Mon Sep 17 00:00:00 2001 From: zereight Date: Thu, 22 Jul 2021 21:41:21 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=EB=B9=84=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=9C=A0=EC=A0=80=EC=9D=98=20=EB=B9=84=EB=B0=80?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EA=B2=80=EC=A6=9D=EC=9D=84=20=EB=B3=84?= =?UTF-8?q?=EB=8F=84=EC=9D=98=20api=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=9C?= =?UTF-8?q?=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/molecules/Comment/index.tsx | 44 +++++++++++-------- frontend/reply-module/src/constants/api.ts | 3 ++ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/frontend/reply-module/src/components/molecules/Comment/index.tsx b/frontend/reply-module/src/components/molecules/Comment/index.tsx index 7e85f6be3..9053beb74 100644 --- a/frontend/reply-module/src/components/molecules/Comment/index.tsx +++ b/frontend/reply-module/src/components/molecules/Comment/index.tsx @@ -1,22 +1,24 @@ import { FormEvent, useEffect, useState } from "react"; +import { QUERY } from "../../../constants/api"; import { useDeleteComment, useEditComment, useInput } from "../../../hooks"; import { Comment as CommentType } from "../../../types"; +import { DeleteCommentRequestParameter } from "../../../types/comment"; +import { User } from "../../../types/user"; +import { postScrollHeightToParentWindow } from "../../../utils/iframePostMessage"; +import { request } from "../../../utils/request"; import { getTimeDifference } from "../../../utils/time"; import Avatar from "../../atoms/Avatar"; import CommentTextBox from "../../atoms/CommentTextBox"; import { - Container, - CommentWrapper, - CommentTextBoxWrapper, - Time, + Button, CommentOption, + CommentTextBoxWrapper, + CommentWrapper, + Container, PasswordForm, PasswordInput, - Button + Time } from "./styles"; -import { User } from "../../../types/user"; -import { DeleteCommentRequestParameter } from "../../../types/comment"; -import { postScrollHeightToParentWindow } from "../../../utils/iframePostMessage"; export interface Props { user: User | undefined; @@ -46,22 +48,26 @@ const Comment = ({ user, comment, align = "left", shouldShowOption, iAmAdmin, th setPassword(""); }; - const isEditable = (iAmAdmin && thisCommentIsMine) || !iAmAdmin; + const canIControl = (iAmAdmin && thisCommentIsMine) || !iAmAdmin; const isEditable = (iAmAdmin && thisCommentIsMine) || !iAmAdmin; const confirmGuestPassword = async () => { try { - await editComment({ - id: comment.id, - content: comment.content, - guestUserId: comment.user.id, - guestUserPassword: password - }); + const response = await request.get( + QUERY.CHECK_GUEST_PASSWORD({ + guestUserId: comment.user.id, + guestUserPassword: password + }) + ); - clear(); + if (response.status >= 400) { + throw new Error(response.data.message); + } + + const { isCorrectPassword } = response.data; - return true; + return isCorrectPassword; } catch (error) { console.error(error.message); setPasswordSubmitted(true); @@ -110,7 +116,7 @@ const Comment = ({ user, comment, align = "left", shouldShowOption, iAmAdmin, th } submitPasswordCallback(); - clear(); + setShouldShowPasswordInput(false); }; const submitEditedComment = async (content: CommentType["content"]) => { @@ -155,7 +161,7 @@ const Comment = ({ user, comment, align = "left", shouldShowOption, iAmAdmin, th {shouldShowOption && !submitType && ( - + )} diff --git a/frontend/reply-module/src/constants/api.ts b/frontend/reply-module/src/constants/api.ts index fa68d88a4..67e4974c6 100644 --- a/frontend/reply-module/src/constants/api.ts +++ b/frontend/reply-module/src/constants/api.ts @@ -1,9 +1,12 @@ +import { GuestUserInfo } from "../types/comment"; const BASE_URL = "https://darass.o-r.kr"; const QUERY = { LOGIN: "/api/v1/login/oauth?oauthAccessToken=", COMMENT: "/api/v1/comments", GET_ALL_COMMENTS: (url: string, projectKey: string) => `/api/v1/comments?url=${url}&projectKey=${projectKey}`, GET_PROJECT: (projectKey: string) => `/api/v1/projects/user-id?secretKey=${projectKey}`, + CHECK_GUEST_PASSWORD: ({ guestUserId, guestUserPassword }: GuestUserInfo) => + `/api/v1/users/check-password?guestUserId=${guestUserId}&guestUserPassword=${guestUserPassword}`, USER: "/api/v1/users" };