import React, { useMemo, useEffect, useState } from "react"; import { connect } from "react-redux"; import userImage from "./user.svg"; import positiveIcon from "./positive.svg"; import negativeIcon from "./negative.svg"; import Avatar from "../Avatar"; import moment from "jalali-moment"; import StarRating from "../StarRating"; export const Comments = ({ comments, indent }) => { const [list, setList] = useState([]); useEffect(() => { if (indent) { let indentComments = comments?.sort((i, j) => i.pid - j.pid); let result = []; indentComments?.reduce((acc, comment) => { let cmnt = { id: comment?.id, title: comment?.title, text: comment?.text, pid: comment?.pid, childs: [], }; if (comment.pid) { acc[comment.pid]?.childs?.push(cmnt); } else { result?.push(cmnt); } acc[comment?.id] = cmnt; return acc; }, []); setList(result); } }, [comments]); const Comment = ({ comment }) => { return (
{comment.userId} {comment?.userRoll || window.t("خریدار محصول")}
{moment(comment?.createdAt).locale("fa").format("YYYY/MM/DD")} {moment(comment?.createdAt).locale("fa").format("HH:mm:ss")}
 
{comment?.status === true && ( <> {window.t("برای خرید توصیه می‌کنم")} )} {comment?.status === false && ( <> {window.t("بازگشت بی چون و برای خرید توصیه نمی‌کنم")} )}

{comment?.text}

{/*
{indent && (
{comment?.childs?.map((object, index) => ( ))}
)}
); }; return (
{(indent ? list : comments)?.map((comment, index) => ( ))}
); }; const mapStateToProps = (state) => ({ comments: state.book.info?.comment, }); const mapDispatchToProps = {}; export default connect(mapStateToProps, mapDispatchToProps)(Comments);