From 2f0c163777e18cc19f19c1a31e951d5d427e6a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=96=B4=EC=8A=B9=EC=A4=80?= Date: Sun, 14 Jan 2024 07:20:50 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=ED=8C=90=EB=B3=84=20localstorage=EC=97=90=EC=84=9C=20api=20res?= =?UTF-8?q?ponse=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DetailSectionTop/DetailToursButtons.tsx | 19 ++++++++------ src/components/common/nav/InputComment.tsx | 26 +++++++++++-------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/components/DetailSectionTop/DetailToursButtons.tsx b/src/components/DetailSectionTop/DetailToursButtons.tsx index 85a44d0c..8c9e01a6 100644 --- a/src/components/DetailSectionTop/DetailToursButtons.tsx +++ b/src/components/DetailSectionTop/DetailToursButtons.tsx @@ -8,7 +8,7 @@ import { import { isModifyingReviewState } from '@recoil/review'; import { useNavigate, useParams } from 'react-router-dom'; import { useSetRecoilState } from 'recoil'; -import { getItem } from '@utils/localStorageFun'; +import { getMember } from '@api/member'; interface reviewProps { reviewData: any; @@ -24,13 +24,16 @@ export default function DetailTourButtons({ reviewData }: reviewProps) { const setModalChildren = useSetRecoilState(modalChildrenState); const setAlertType = useSetRecoilState(alertTypeState); - const handlePostingReivew = () => { - const token = getItem('accessToken'); - if (token) { - navigate(`/reviewPosting/${tourItemId}`, { - state: { title, contentTypeId }, - }); - } else { + const handlePostingReivew = async () => { + try { + const res = await getMember(); + if (res.data.status === 200) { + navigate(`/reviewPosting/${tourItemId}`, { + state: { title, contentTypeId }, + }); + } + } catch (err) { + console.error(err); setModalChildren('MyAlert'); setAlertType('LoginReview'); setIsModifyingReview(false); diff --git a/src/components/common/nav/InputComment.tsx b/src/components/common/nav/InputComment.tsx index eb1ddd52..b186b9d4 100644 --- a/src/components/common/nav/InputComment.tsx +++ b/src/components/common/nav/InputComment.tsx @@ -10,12 +10,12 @@ import { // inputFocusState, } from '@recoil/review'; import { useMutation, useQueryClient } from '@tanstack/react-query'; -import { getItem } from '@utils/localStorageFun'; import { isModalOpenState, modalChildrenState, alertTypeState, } from '@recoil/modal'; +import { getMember } from '@api/member'; interface InputCommentProps { classNameName?: string; @@ -79,22 +79,26 @@ export const InputComment: React.FC = () => { }; const handleSubmit = async () => { - const token = getItem('accessToken'); - if (token) { - if (isModifyingComment) { - await editReviewMutate({ comment, targetCommentId }); - setIsModifyingComment(false); - // setInputFocus(false); - } else { - await postReviewMutate({ comment, reviewId }); + try { + const res = await getMember(); + if (res.data.status === 200) { + if (isModifyingComment) { + await editReviewMutate({ comment, targetCommentId }); + setIsModifyingComment(false); + // setInputFocus(false); + } else { + await postReviewMutate({ comment, reviewId }); + } + setComment(''); } - setComment(''); - } else { + } catch (err) { + console.error(err); setModalChildren('MyAlert'); setAlertType('LoginComment'); setIsModalOpen(true); } }; + const handleKeyPress = (event: KeyboardEvent) => { if (event.key === 'Enter') { handleSubmit();