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();