From 79064360d5927ff9f4e13b4e6b42b7425c4f2186 Mon Sep 17 00:00:00 2001 From: nalsae Date: Tue, 12 Dec 2023 15:54:07 +0900 Subject: [PATCH] =?UTF-8?q?[FE]=20=E2=9C=A8=20Feat=20:=20=EB=B0=A9?= =?UTF-8?q?=EB=AA=85=EB=A1=9D=20=EA=B4=80=EB=A0=A8=20=ED=95=98=EC=9C=84=20?= =?UTF-8?q?=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=20=EC=9E=84=EC=8B=9C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20(#352)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/garden/Comment.tsx | 110 ++++++++++++++++++ client/src/components/garden/CommentForm.tsx | 64 ++++++++++ .../components/garden/CommentProfileImage.tsx | 19 +++ 3 files changed, 193 insertions(+) create mode 100644 client/src/components/garden/Comment.tsx create mode 100644 client/src/components/garden/CommentForm.tsx create mode 100644 client/src/components/garden/CommentProfileImage.tsx diff --git a/client/src/components/garden/Comment.tsx b/client/src/components/garden/Comment.tsx new file mode 100644 index 00000000..c97b5ff3 --- /dev/null +++ b/client/src/components/garden/Comment.tsx @@ -0,0 +1,110 @@ +'use client'; + +import { useParams } from 'next/navigation'; +import { useForm } from 'react-hook-form'; + +import usePostStore from '@/stores/postStore'; +import useUserStore from '@/stores/userStore'; + +import useEditCommentMutation from '@/hooks/mutation/useEditCommentMutation'; + +import { PostProfile, DateAndControlSection } from '@/components/post'; +import CommonButton from '../common/CommonButton'; + +import { GuestbookDataInfo } from '@/types/data'; +import { CommentInputValue } from '@/types/common'; + +import { COMMENT } from '@/constants/contents'; + +interface CommentProps { + comment: GuestbookDataInfo | null; + guestbookId: number | null; +} + +export default function Comment({ comment, guestbookId }: CommentProps) { + if (!comment || !guestbookId) return null; + + const { id } = useParams(); + + const { editMode, targetId, setEditMode } = usePostStore(); + const { userId } = useUserStore(); + + const { mutate: editComment } = useEditCommentMutation({ + guestbookId, + targetId, + }); + + const { + register, + handleSubmit, + formState: { isSubmitting }, + } = useForm({ + defaultValues: { + comment: comment.content, + }, + }); + + const isEdit = editMode && String(comment.commentId) === targetId; + + const isOwner = userId === String(comment.accountId); + + const submitCommentForm = (data: CommentInputValue) => { + editComment(data); + setEditMode(false); + }; + + return ( +
  • +
    + + +
    +
    + {isEdit ? ( +
    + + {isEdit && ( +
    + + 수정 + + setEditMode(false)} + disabled={isSubmitting}> + 취소 + +
    + )} +
    + ) : ( +

    + {comment.content} +

    + )} +
    +
  • + ); +} diff --git a/client/src/components/garden/CommentForm.tsx b/client/src/components/garden/CommentForm.tsx new file mode 100644 index 00000000..bf4c998e --- /dev/null +++ b/client/src/components/garden/CommentForm.tsx @@ -0,0 +1,64 @@ +'use client'; + +import { useForm } from 'react-hook-form'; +import { motion } from 'framer-motion'; +import { ErrorMessage } from '@hookform/error-message'; + +import useAddGuestbookMutation from '@/hooks/mutation/useAddGuestbookMutation'; + +import CommentProfileImage from './CommentProfileImage'; + +import { CommentInputValue } from '@/types/common'; + +import { COMMENT } from '@/constants/contents'; + +export default function CommentForm() { + const { + register, + handleSubmit, + reset, + formState: { errors, isSubmitting }, + } = useForm(); + const { mutate: addGuestbook } = useAddGuestbookMutation(); + + const submitCommentForm = (data: CommentInputValue) => { + addGuestbook(data); + reset(); + }; + + return ( +
    + + + ( +
    + {message} +
    + )} + /> + + 등록 + + + ); +} diff --git a/client/src/components/garden/CommentProfileImage.tsx b/client/src/components/garden/CommentProfileImage.tsx new file mode 100644 index 00000000..53ba1d70 --- /dev/null +++ b/client/src/components/garden/CommentProfileImage.tsx @@ -0,0 +1,19 @@ +import Image from 'next/image'; + +import useUserStore from '@/stores/userStore'; + +export default function CommentProfileImage() { + const { profileImageUrl } = useUserStore(); + return ( +
    + profile_img +
    + ); +}