GuestReviews.js
6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import Image from "next/image";
import { useRouter } from "next/router";
import React, { useState } from "react";
import { Button, Modal } from "react-bootstrap";
import { useSelector } from "react-redux";
import StarRatings from "react-star-ratings";
import { postReviewEndUser } from "../../redux/actions/reviewsAction";
import { dateFormatFn } from "../../services/imageHandling";
const GuestReviews = ({ activityById }) => {
const [rating, setRating] = useState(0);
const [comments, setcomments] = useState();
const [readMoreText, setreadMoreText] = useState();
const [showModal, setshowModal] = useState(false);
const { endUser } = useSelector(state => state.endUser);
const { reviews } = useSelector(state => state.reviews);
const router = useRouter();
console.log("reviews", reviews);
const handleRatingChange = newRating => {
setRating(newRating);
};
return (
<>
<section className="guest-reviews-session">
<div className="container">
<div className="row">
<div className="col-md-12">
<div className="row">
<div className="col-12">
<div className="head-btn">
<div className="head01">
<div className="title">Guest reviews</div>
</div>
{/* <a href="" className="view-all-reviews-btn">
View All Reviews
</a> */}
</div>
</div>
</div>
<div className="row">
<div className="col-12">
<div className="product-reviews">
<span className="rating">8.8</span>
<span>Fabulous</span>
<span className="review">{` ${reviews.length} reviews`}</span>
</div>
</div>
</div>
<div className="row">
{reviews &&
reviews.map(data => {
return (
<div className="col-md-6">
<div className="guest-reviews-detail">
<div className="head">
<div className="name">{data.attributes.endUser.data.attributes.name}</div>
<div className="month">{dateFormatFn(data.attributes.createdAt)}</div>
</div>
<StarRatings
className="col-3 mx-2"
rating={data.attributes.rating}
starRatedColor="yellow" // Set the rated color to yellow
starHoverColor="yellow" // Set the hover color to yellow
changeRating={() => {}}
numberOfStars={5}
name="rating"
starDimension="20px" // Set star width and height
/>
<div className="review-content">
"{data.attributes.comments.length > 80 ? `${data.attributes.comments.slice(0, 80)}...` : data.attributes.comments}
{data.attributes.comments.length > 80 && (
<a
onClick={() => {
setreadMoreText(data);
setshowModal(true);
}}
>
Read More
</a>
)}
</div>
{/* View All */}
</div>
</div>
);
})}
</div>
{endUser && (
<div className="row">
<div className="head01">
<div className="title">Post a review:</div>
</div>
<div>
<label className=" mb-3 ">Rating: </label>{" "}
<StarRatings
className="col-3 mx-2"
rating={rating}
starRatedColor="yellow" // Set the rated color to yellow
starHoverColor="yellow" // Set the hover color to yellow
changeRating={handleRatingChange}
numberOfStars={5}
name="rating"
starDimension="20px" // Set star width and height
/>
</div>
<textarea
// style={{ width: "50%" }}
rows={4}
className="p-2 mx-2 col-md-6"
placeholder="Comments"
name="comments"
value={comments}
onChange={e => {
e.preventDefault();
// console.log(e.target.value);4
setcomments(e.target.value);
// setrejectionReasonText(e.target.value);
}}
/>
<div className="view-all-btn my-3">
<Button
disabled={rating == 0 || comments == ""}
variant="primary"
onClick={async e => {
e.preventDefault();
const res = await postReviewEndUser({ endUserId: endUser.id, activityId: router.query.id, comments, rating });
console.log("res", res);
setRating(0);
setcomments("");
}}
>
Submit
</Button>
</div>
</div>
)}
</div>
</div>
</div>
{readMoreText && (
<Modal
centered
show={showModal}
onHide={() => {
setshowModal();
setreadMoreText(null);
}}
>
<Modal.Header closeButton>Review from {readMoreText.attributes.endUser.data.attributes.name}</Modal.Header>
<Modal.Body>
<div>{readMoreText.attributes.comments}</div>
</Modal.Body>
</Modal>
)}
</section>
</>
);
};
export default GuestReviews;