Skip to content

Commit 2dc1d60

Browse files
committed
Feat. 좋아요 눌렀을 때 로그인 안했으면 '로그인이 필요합니다.' 문구 출력하도록 기능 추가
1 parent 1c9769c commit 2dc1d60

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/pages/article_page/components/comment/components/comment_item/CommentItem.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import dayjs from "dayjs";
22
import { useState } from "react";
33
import { useParams } from "react-router-dom";
4+
import { toast } from "react-toastify";
45

56
import DeleteIcon from "assets/images/icons/DeleteIcon";
67
import EditIcon from "assets/images/icons/EditIcon";
@@ -13,13 +14,16 @@ import useUnLikeComment from "apis/comment_apis/useUnLikeComment";
1314
import BaseButton from "components/buttons/base_button/BaseButton";
1415
import TextButton from "components/buttons/text_button/TextButton";
1516

17+
import useIsLogin from "hooks/useIsLogin";
18+
1619
import Reply from "../../../reply/Reply";
1720
import classes from "./CommentItem.module.scss";
1821
import EditComment from "./edit_comment/EditComment";
1922

2023
const CommentItem = ({ commentItem }: { commentItem: CommentItemType }) => {
2124
const articleId = useParams().articleId;
2225

26+
const { isLogin } = useIsLogin();
2327
const { mutate: deleteMutate } = useDeleteComment();
2428
const { mutate: likeMutate } = useLikeComment();
2529
const { mutate: unLikeMutate } = useUnLikeComment();
@@ -31,6 +35,10 @@ const CommentItem = ({ commentItem }: { commentItem: CommentItemType }) => {
3135
const [isReplyOpen, setIsReplyOpen] = useState(false);
3236

3337
const handleLikeClick = () => {
38+
if (!isLogin) {
39+
toast.error("로그인이 필요합니다.");
40+
return;
41+
}
3442
if (!isMeLike) {
3543
likeMutate({
3644
articleId: Number(articleId),

src/pages/article_page/components/reply/components/reply_input/ReplyInput.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import useAddReply from "apis/comment_apis/useAddReply";
99
import TextButton from "components/buttons/text_button/TextButton";
1010
import BaseTextarea from "components/inputs/base_textarea/BaseTextarea";
1111

12+
import useIsLogin from "hooks/useIsLogin";
13+
1214
import classes from "./ReplyInput.module.scss";
1315

1416
const ReplyInput = ({ commentId }: { commentId: number }) => {
@@ -22,6 +24,7 @@ const ReplyInput = ({ commentId }: { commentId: number }) => {
2224
});
2325

2426
const { mutate } = useAddReply();
27+
const { isLogin } = useIsLogin();
2528

2629
const onError = (e: FieldErrors) => {
2730
if (e?.content?.message && typeof e?.content?.message === "string") {
@@ -48,7 +51,16 @@ const ReplyInput = ({ commentId }: { commentId: number }) => {
4851
<FormProvider {...methods}>
4952
<form
5053
className={classes.input_wrap}
51-
onSubmit={methods.handleSubmit(onSubmit, onError)}
54+
onSubmit={(e: React.FormEvent) => {
55+
e.preventDefault();
56+
57+
if (!isLogin) {
58+
toast.error("로그인이 필요합니다.");
59+
return;
60+
}
61+
62+
methods.handleSubmit(onSubmit, onError);
63+
}}
5264
>
5365
<ReplyIcon />
5466
<div className={classes.input_right}>

src/pages/article_page/components/reply/components/reply_item/ReplyItem.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import dayjs from "dayjs";
22
import { useState } from "react";
33
import { useParams } from "react-router-dom";
4+
import { toast } from "react-toastify";
45

56
import DeleteIcon from "assets/images/icons/DeleteIcon";
67
import EditIcon from "assets/images/icons/EditIcon";
@@ -13,6 +14,8 @@ import useUnLikeReply from "apis/comment_apis/useUnLikeReply";
1314

1415
import BaseButton from "components/buttons/base_button/BaseButton";
1516

17+
import useIsLogin from "hooks/useIsLogin";
18+
1619
import classes from "./ReplyItem.module.scss";
1720
import EditReply from "./edit_reply/EditReply";
1821

@@ -25,6 +28,8 @@ const ReplyItem = ({
2528
}) => {
2629
const articleId = useParams().articleId;
2730

31+
const { isLogin } = useIsLogin();
32+
2833
const [isEditMode, setIsEditMode] = useState(false);
2934

3035
const { mutate: deleteMutate } = useDeleteReply();
@@ -44,6 +49,10 @@ const ReplyItem = ({
4449
};
4550

4651
const handleLikeClick = () => {
52+
if (!isLogin) {
53+
toast.error("로그인이 필요합니다.");
54+
return;
55+
}
4756
if (replyItem.like.isUserLike) {
4857
unlikeMutate({
4958
articleId: Number(articleId),

src/pages/my_page/profile_page/components/password_update_modal/PasswordUpdateModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { motion } from "framer-motion";
2-
import { FormProvider, useForm, useFormContext } from "react-hook-form";
2+
import { FormProvider, useForm } from "react-hook-form";
33
import { toast } from "react-toastify";
44

55
import useUpdatePassword from "apis/profile_apis/useUpdatePassword";

0 commit comments

Comments
 (0)