From b4ae4de609d8e24bbc68aaffdbe994147376ae8e Mon Sep 17 00:00:00 2001 From: hyeonjiroh Date: Sun, 30 Mar 2025 11:11:45 +0900 Subject: [PATCH 1/9] feat: Connect comment form with comment post API --- src/components/common/modal/Modal.tsx | 2 +- src/components/common/textarea/Textarea.tsx | 2 +- .../modal/add-column/AddColumnModal.tsx | 2 +- .../modal/task-detail/CommentList.tsx | 3 + .../modal/task-detail/TaskCommentSection.tsx | 73 +++++++++++++++++++ .../modal/task-detail/TaskDetailModal.tsx | 18 +++-- src/lib/apis/commentsApi.ts | 59 +++++++++++++++ 7 files changed, 150 insertions(+), 9 deletions(-) create mode 100644 src/components/modal/task-detail/CommentList.tsx create mode 100644 src/components/modal/task-detail/TaskCommentSection.tsx create mode 100644 src/lib/apis/commentsApi.ts diff --git a/src/components/common/modal/Modal.tsx b/src/components/common/modal/Modal.tsx index 65898eb..6a6b5e4 100644 --- a/src/components/common/modal/Modal.tsx +++ b/src/components/common/modal/Modal.tsx @@ -45,7 +45,7 @@ export default function Modal({
{ containerClassName: string; labelClassName: string; textareaClassName: string; - spanClassName: string; + spanClassName?: string; } const Textarea = ({ diff --git a/src/components/modal/add-column/AddColumnModal.tsx b/src/components/modal/add-column/AddColumnModal.tsx index ce60d77..9fac3b6 100644 --- a/src/components/modal/add-column/AddColumnModal.tsx +++ b/src/components/modal/add-column/AddColumnModal.tsx @@ -52,7 +52,7 @@ export default function CreateDashboardModal() { const buttonClick = async () => { if (!dashboardId) return; - postColumn({ + await postColumn({ token: TOKEN_1, title: inputValue, dashboardId: Number(dashboardId), diff --git a/src/components/modal/task-detail/CommentList.tsx b/src/components/modal/task-detail/CommentList.tsx new file mode 100644 index 0000000..ff8ebf1 --- /dev/null +++ b/src/components/modal/task-detail/CommentList.tsx @@ -0,0 +1,3 @@ +export default function CommentList() { + return
코멘트
; +} diff --git a/src/components/modal/task-detail/TaskCommentSection.tsx b/src/components/modal/task-detail/TaskCommentSection.tsx new file mode 100644 index 0000000..3d9e064 --- /dev/null +++ b/src/components/modal/task-detail/TaskCommentSection.tsx @@ -0,0 +1,73 @@ +import { useEffect, useState } from "react"; +import { useRouter } from "next/navigation"; +import { useDashboardStore } from "@/lib/store/useDashboardStore"; +import { postComment } from "@/lib/apis/commentsApi"; +import { TOKEN_1 } from "@/lib/constants/tokens"; +import Button from "@/components/common/button/Button"; +import Textarea from "@/components/common/textarea/Textarea"; +import CommentList from "./CommentList"; + +export default function TaskCommentSection({ + cardId, + columnId, +}: { + cardId: number; + columnId: number; +}) { + const [inputValue, setInputValue] = useState(""); + const [isFormValid, setIsFormValid] = useState(false); + const { dashboardId } = useDashboardStore(); + const router = useRouter(); + + useEffect(() => { + const trimmedValue = inputValue.trim(); + setIsFormValid(trimmedValue !== ""); + }, [inputValue]); + + const handleChange = (e: React.ChangeEvent) => { + setInputValue(e.target.value); + }; + + const buttonClick = async () => { + if (!dashboardId) return; + + await postComment({ + token: TOKEN_1, + content: inputValue, + cardId: cardId, + columnId: columnId, + dashboardId: Number(dashboardId), + }); + + setInputValue(""); + router.refresh(); + }; + + if (!dashboardId) return; + + return ( +
+
+