- {content}
+
+ {content.split('. ').map((sentence, index) => (
+
+ {sentence}
+
+ ))}
- {
- setIsModalOpen(false);
- }}
- className="text-sm">
+
취소
diff --git a/src/components/common/nav/InputComment.tsx b/src/components/common/nav/InputComment.tsx
index 76fbba1f..eb21cbf6 100644
--- a/src/components/common/nav/InputComment.tsx
+++ b/src/components/common/nav/InputComment.tsx
@@ -2,10 +2,16 @@ import { KeyboardEvent, ChangeEvent } from 'react';
import { postComments } from '@api/comments';
import { useParams } from 'react-router-dom';
import { commentState } from '@recoil/review';
-import { useRecoilState, useRecoilValue } from 'recoil';
+import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
import { putComments } from '@api/comments';
import { isModifyingCommentState, targetCommentIdState } from '@recoil/review';
import { useMutation, useQueryClient } from '@tanstack/react-query';
+import { getItem } from '@utils/localStorageFun';
+import {
+ isModalOpenState,
+ modalChildrenState,
+ alertTypeState,
+} from '@recoil/modal';
interface InputCommentProps {
classNameName?: string;
@@ -30,6 +36,9 @@ export const InputComment: React.FC = () => {
);
const targetCommentId = useRecoilValue(targetCommentIdState);
const queryClient = useQueryClient();
+ const setIsModalOpen = useSetRecoilState(isModalOpenState);
+ const setModalChildren = useSetRecoilState(modalChildrenState);
+ const setAlertType = useSetRecoilState(alertTypeState);
const { mutate: postReviewMutate } = useMutation({
mutationFn: ({ comment, reviewId }: PostCommentMutationParams) =>
@@ -64,13 +73,20 @@ export const InputComment: React.FC = () => {
};
const handleSubmit = async () => {
- if (isModifyingComment) {
- await editReviewMutate({ comment, targetCommentId });
- setIsModifyingComment(false);
+ const token = getItem('accessToken');
+ if (token) {
+ if (isModifyingComment) {
+ await editReviewMutate({ comment, targetCommentId });
+ setIsModifyingComment(false);
+ } else {
+ await postReviewMutate({ comment, reviewId });
+ }
+ setComment('');
} else {
- await postReviewMutate({ comment, reviewId });
+ setModalChildren('MyAlert');
+ setAlertType('LoginComment');
+ setIsModalOpen(true);
}
- setComment('');
};
const handleKeyPress = (event: KeyboardEvent) => {
if (event.key === 'Enter') {
diff --git a/src/recoil/modal.ts b/src/recoil/modal.ts
index eecef4b1..a687f33b 100644
--- a/src/recoil/modal.ts
+++ b/src/recoil/modal.ts
@@ -14,3 +14,8 @@ export const modalChildrenState = atom({
key: 'modalChildrenState',
default: '',
});
+
+export const alertTypeState = atom({
+ key: 'alertTypeState',
+ default: '',
+});