1+ import HashSpinner from "@/components/common/HashSpinner" ;
12import ReportIcon from "@/components/common/icons/ReportIcon" ;
23import CommentDeleteModalContainer from "@/containers/informations/detail/comment/CommentDeleteModalContainer" ;
3- import { InformationCommentResponseDto } from "@/types/InformationDto " ;
4+ import { InformationCommentResponseDto } from "@/types/InformationCommentDto " ;
45import Image from "next/image" ;
6+ import { Dispatch , FormEvent , SetStateAction } from "react" ;
57
68interface CommentItemProps {
79 data : InformationCommentResponseDto ;
810 modalVisible : boolean ;
11+ editable : boolean ;
12+ comment : string ;
13+ loading : boolean ;
14+ userId : number ;
915 openModal : ( ) => void ;
1016 closeModal : ( ) => void ;
17+ setEditable : Dispatch < SetStateAction < boolean > > ;
18+ setComment : ( value : string ) => void ;
19+ onSubmit : ( e : FormEvent < HTMLFormElement > ) => Promise < void > ;
1120}
1221
1322const CommentItem = ( {
1423 data,
1524 modalVisible,
25+ editable,
26+ comment,
27+ loading,
28+ userId,
1629 openModal,
1730 closeModal,
31+ setEditable,
32+ setComment,
33+ onSubmit,
1834} : CommentItemProps ) => {
1935 return (
2036 < div className = "flex flex-col gap-[0.625rem] border-b border-b-gray3" >
@@ -24,40 +40,86 @@ const CommentItem = ({
2440 closeModal = { closeModal }
2541 />
2642 ) }
43+ < HashSpinner loading = { loading } />
2744 < div className = "flex flex-row items-center justify-between" >
2845 < div className = "flex flex-row items-center gap-3" >
2946 < Image
3047 className = "rounded-full border-[0.03125rem] border-[#B8EDD9] bg-lightGreen"
31- src = { data . userImage }
48+ src = { data . userProfile }
3249 alt = "userImage"
3350 width = { 54 }
3451 height = { 54 }
3552 />
3653 < div className = "flex flex-col gap-1" >
37- < p className = "text-xs font-semibold text-black" > { data . nickname } </ p >
54+ < p className = "text-xs font-semibold text-black" >
55+ { data . userNickname }
56+ </ p >
3857 < p className = "text-xs text-gray1" >
39- { `${ new Date ( data . createdDate ) . toLocaleDateString ( "ko-KR" ) } ` }
58+ { `${ new Date ( data . updatedAt ) . toLocaleDateString ( "ko-KR" ) } ` }
4059 </ p >
4160 </ div >
4261 </ div >
4362 < button
44- className = "stroke-gray1 hover:stroke-main"
45- onClick = { ( ) => openModal ( ) }
63+ className = "invisible stroke-gray1 hover:stroke-main"
64+ onClick = { ( ) => alert ( "TODO: 구현 예정" ) }
4665 >
4766 < ReportIcon className = "mb-[0.5625rem] cursor-pointer stroke-inherit" />
4867 </ button >
4968 </ div >
50- < div >
51- < p className = "h-[4.375rem] break-words pl-[4.125rem] text-[0.9375rem] text-black" >
52- { data . content }
53- </ p >
54- < div className = "h-8 w-full" >
55- < div className = "flex flex-row items-center justify-end gap-4 text-sm text-gray1" >
56- < button className = "hover:text-main" > 수정</ button >
57- < button className = "hover:text-main" > 삭제</ button >
69+ { editable ? (
70+ < form className = "pl-[4.125rem]" onSubmit = { onSubmit } >
71+ < div className = "relative h-[4.375rem]" >
72+ < input
73+ className = { `${ comment . length === 0 ? "border-red-500" : "border-gray3 hover:border-main focus:border-main" } h-[2.75rem] w-full rounded-3xl border px-6 text-sm text-black outline-none` }
74+ type = "text"
75+ placeholder = "자유롭게 소통을 해보세요."
76+ value = { comment }
77+ maxLength = { 200 }
78+ autoComplete = "off"
79+ onChange = { ( e ) => setComment ( e . target . value ) }
80+ />
81+ { comment . length === 0 && (
82+ < p className = "absolute bottom-1 left-4 mt-1 text-xs text-red-500" >
83+ 댓글을 입력해 주세요.
84+ </ p >
85+ ) }
86+ </ div >
87+ < div className = "flex h-8 w-full flex-row items-start justify-end gap-4 text-sm text-gray1" >
88+ < button className = "hover:text-main" type = "submit" >
89+ 수정
90+ </ button >
91+ < button
92+ className = "hover:text-main"
93+ type = "button"
94+ onClick = { ( ) => setEditable ( false ) }
95+ >
96+ 취소
97+ </ button >
5898 </ div >
99+ </ form >
100+ ) : (
101+ < div >
102+ < p className = "min-h-[4.375rem] break-words pl-[4.125rem] text-[0.9375rem] text-black" >
103+ { data . content }
104+ </ p >
105+ { userId === data . userId && (
106+ < div className = "flex h-8 w-full flex-row items-start justify-end gap-4 text-sm text-gray1" >
107+ < button
108+ className = "hover:text-main"
109+ onClick = { ( ) => {
110+ setComment ( data . content ) ;
111+ setEditable ( true ) ;
112+ } }
113+ >
114+ 수정
115+ </ button >
116+ < button className = "hover:text-main" onClick = { ( ) => openModal ( ) } >
117+ 삭제
118+ </ button >
119+ </ div >
120+ ) }
59121 </ div >
60- </ div >
122+ ) }
61123 </ div >
62124 ) ;
63125} ;
0 commit comments