|
|
@ -7,12 +7,12 @@ import Avatar from "../Avatar"; |
|
|
|
import moment from "jalali-moment"; |
|
|
|
import moment from "jalali-moment"; |
|
|
|
import StarRating from "../StarRating"; |
|
|
|
import StarRating from "../StarRating"; |
|
|
|
|
|
|
|
|
|
|
|
export const Comments = ({ comments }) => { |
|
|
|
export const Comments = ({ comments, indent }) => { |
|
|
|
const [list, setList] = useState([]); |
|
|
|
const [list, setList] = useState([]); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if (indent) { |
|
|
|
let indentComments = comments?.sort((i, j) => i.pid - j.pid); |
|
|
|
let indentComments = comments?.sort((i, j) => i.pid - j.pid); |
|
|
|
|
|
|
|
|
|
|
|
let result = []; |
|
|
|
let result = []; |
|
|
|
indentComments?.reduce((acc, comment) => { |
|
|
|
indentComments?.reduce((acc, comment) => { |
|
|
|
let cmnt = { |
|
|
|
let cmnt = { |
|
|
@ -33,6 +33,7 @@ export const Comments = ({ comments }) => { |
|
|
|
return acc; |
|
|
|
return acc; |
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
setList(result); |
|
|
|
setList(result); |
|
|
|
|
|
|
|
} |
|
|
|
}, [comments]); |
|
|
|
}, [comments]); |
|
|
|
|
|
|
|
|
|
|
|
const Comment = ({ comment }) => { |
|
|
|
const Comment = ({ comment }) => { |
|
|
@ -42,27 +43,19 @@ export const Comments = ({ comments }) => { |
|
|
|
<div className="flex flex-row items-end"> |
|
|
|
<div className="flex flex-row items-end"> |
|
|
|
<Avatar source={comment?.userImage} size={60} rounded={true} /> |
|
|
|
<Avatar source={comment?.userImage} size={60} rounded={true} /> |
|
|
|
<div className="flex flex-col"> |
|
|
|
<div className="flex flex-col"> |
|
|
|
<strong className="text-lg mr-2">{comment.id}</strong> |
|
|
|
<div className="flex items-center"> |
|
|
|
{/* {comment.pid && ( |
|
|
|
<strong className="text-base mr-2">{comment.userId}</strong> |
|
|
|
<strong className="text-lg mr-2"> |
|
|
|
<span className="text-tiny text-greenBA mr-3"> |
|
|
|
{"در پاسخ به" + |
|
|
|
{comment?.userRoll || "خریدار محصول"} |
|
|
|
" " + |
|
|
|
</span> |
|
|
|
comments.filter( |
|
|
|
<div className="flex flex-row items-center mr-10 font-semibold"> |
|
|
|
(commentt) => commentt.id === comment.pid |
|
|
|
<StarRating /> |
|
|
|
)[0].id} |
|
|
|
</div> |
|
|
|
</strong> |
|
|
|
</div> |
|
|
|
)} */} |
|
|
|
<div |
|
|
|
{/* <div |
|
|
|
|
|
|
|
className="flex flex-row divide-x divide-gray-300 mt-4 divided items-center" |
|
|
|
className="flex flex-row divide-x divide-gray-300 mt-4 divided items-center" |
|
|
|
style={{ direction: "ltr" }} |
|
|
|
style={{ direction: "ltr" }} |
|
|
|
> |
|
|
|
></div> |
|
|
|
<span className="px-2 text-xs text-gray-500"> |
|
|
|
|
|
|
|
{comment?.product?.color} |
|
|
|
|
|
|
|
</span> |
|
|
|
|
|
|
|
<span className="px-2 text-xs text-gray-500"> |
|
|
|
|
|
|
|
{comment?.product?.name} |
|
|
|
|
|
|
|
</span> |
|
|
|
|
|
|
|
</div> */} |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div |
|
|
|
<div |
|
|
@ -77,14 +70,12 @@ export const Comments = ({ comments }) => { |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</header> |
|
|
|
</header> |
|
|
|
<div className="flex flex-row py-4"> |
|
|
|
<div className="flex flex-row"> |
|
|
|
<div style={{ width: 60 }} className="min-h-full"></div> |
|
|
|
<div style={{ width: 60 }} className="min-h-full"></div> |
|
|
|
<div className="flex flex-1 flex-col px-3"> |
|
|
|
<div className="flex flex-1 flex-col px-3"> |
|
|
|
<header className="w-full flex flex-row justify-between items-center"> |
|
|
|
<header className="w-full flex flex-row justify-between items-center"> |
|
|
|
{/* <div className="flex flex-row items-center"> |
|
|
|
<div> </div> |
|
|
|
<StarRating /> |
|
|
|
<div className="flex flex-row items-center"> |
|
|
|
</div> */} |
|
|
|
|
|
|
|
{/* <div className="flex flex-row items-center"> |
|
|
|
|
|
|
|
{comment?.status === true && ( |
|
|
|
{comment?.status === true && ( |
|
|
|
<> |
|
|
|
<> |
|
|
|
<img src={positiveIcon} alt="" className="w-6 ml-2" /> |
|
|
|
<img src={positiveIcon} alt="" className="w-6 ml-2" /> |
|
|
@ -101,7 +92,7 @@ export const Comments = ({ comments }) => { |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</> |
|
|
|
</> |
|
|
|
)} |
|
|
|
)} |
|
|
|
</div> */} |
|
|
|
</div> |
|
|
|
</header> |
|
|
|
</header> |
|
|
|
<p className="text-gray-500 h-auto leading-7 mt-2"> |
|
|
|
<p className="text-gray-500 h-auto leading-7 mt-2"> |
|
|
|
{comment?.text} |
|
|
|
{comment?.text} |
|
|
@ -111,18 +102,20 @@ export const Comments = ({ comments }) => { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
{indent && ( |
|
|
|
<div className="flex pr-12"> |
|
|
|
<div className="flex pr-12"> |
|
|
|
{comment?.childs?.map((object, index) => ( |
|
|
|
{comment?.childs?.map((object, index) => ( |
|
|
|
<Comment comment={object} key={index} /> |
|
|
|
<Comment comment={object} key={index} /> |
|
|
|
))} |
|
|
|
))} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
)} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="w-full flex flex-col"> |
|
|
|
<div className="w-full flex flex-col divide-y divide-solid divide-gray-200"> |
|
|
|
{list?.map((comment, index) => ( |
|
|
|
{(indent ? list : comments)?.map((comment, index) => ( |
|
|
|
<Comment comment={comment} key={index} /> |
|
|
|
<Comment comment={comment} key={index} /> |
|
|
|
))} |
|
|
|
))} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|