Skip to content

Commit

Permalink
Merge pull request #161 from FinalDoubleTen/FE-85--feat/OurTripPrefer
Browse files Browse the repository at this point in the history
Refactor: 로그인 판별 localstorage에서 api response로 변경
  • Loading branch information
seungjun222 authored Jan 13, 2024
2 parents 5af7a8c + 37e4c61 commit ceb7ce4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
19 changes: 11 additions & 8 deletions src/components/DetailSectionTop/DetailToursButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
26 changes: 15 additions & 11 deletions src/components/common/nav/InputComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,22 +79,26 @@ export const InputComment: React.FC<InputCommentProps> = () => {
};

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<HTMLInputElement>) => {
if (event.key === 'Enter') {
handleSubmit();
Expand Down

0 comments on commit ceb7ce4

Please sign in to comment.