Blame view

components/admin/ReviewsListing.js 4.05 KB
.  
jaymehta committed
1 2 3 4 5 6 7 8 9
import { Empty } from "antd";
import React, { useEffect, useState } from "react";
import { Accordion, Button, Modal } from "react-bootstrap";
import { Loader } from "react-bootstrap-typeahead";
import { FaAngleLeft } from "react-icons/fa";
import { useDispatch, useSelector } from "react-redux";
import { toast } from "react-toastify";
// import { getActivitiesByFilters } from "../../redux/actions/activityAction";
import { deleteReview, getReviewsAction } from "../../redux/actions/reviewsAction";
.  
jaymehta committed
10

.  
jaymehta committed
11
const ReviewsListing = ({ activityId, setshowReviews, isVendor }) => {
.  
jaymehta committed
12 13 14 15 16 17 18 19
  const dispatch = useDispatch();
  useEffect(() => {
    dispatch(getReviewsAction({ activityId }));
  }, []);
  const [showModal, setshowModal] = useState(false);
  const [reviewId, setreviewId] = useState();
  const { reviews, loading } = useSelector(state => state.reviews);
  console.log("reviews", reviews, loading);
.  
jaymehta committed
20
  return (
.  
jaymehta committed
21 22 23 24
    <div className="review-details">
      <div className="col-12 col-lg-12">
        <div className="d-flex align-items-center justify-content-between">
          <div className="backDiv">
.  
jaymehta committed
25 26 27 28 29 30 31
            <span
              className="backArrow"
              onClick={() => {
                setshowReviews(false);
              }}
            >
              <FaAngleLeft />
.  
jaymehta committed
32 33 34 35 36 37 38 39
            </span>
            <span>Reviews: </span>
          </div>
        </div>
      </div>
      <div className="container  mt-5">
        {reviews && !reviews.length > 0 && <Empty />}
        {!loading ? (
Ravindra Kanojiya committed
40
          <Accordion className="accordion-filter accordion-01" defaultActiveKey="0" flush>
.  
jaymehta committed
41 42 43 44 45 46 47 48 49 50 51 52
            {reviews &&
              reviews.map(item => {
                return (
                  <Accordion.Item key={item.id} eventKey={item.id}>
                    <Accordion.Header>
                      <div>
                        <span>{`${item.attributes.comments.slice(0, 80).trim()}...`}</span> <span className="">{`by ${item.attributes.endUser.data.attributes.email}`}</span>
                      </div>
                    </Accordion.Header>
                    <Accordion.Body>
                      <div className="m-1">Rating: {item.attributes.rating}</div>
                      <div className="m-1">Review: {item.attributes.comments}</div>
.  
jaymehta committed
53 54 55 56 57 58 59 60 61 62 63 64 65
                      {!isVendor && (
                        <div>
                          <Button
                            className="btnAdd btnReject m-0"
                            onClick={() => {
                              setshowModal(true);
                              setreviewId(item.id);
                            }}
                          >
                            Delete review
                          </Button>
                        </div>
                      )}
.  
jaymehta committed
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
                    </Accordion.Body>
                  </Accordion.Item>
                );
              })}
          </Accordion>
        ) : (
          <Loader />
        )}
        <Modal
          show={showModal}
          onHide={() => {
            setshowModal(false);
            setreviewId();
          }}
          centered
        >
          <Modal.Header closeButton>Are you sure you want to delete this review?</Modal.Header>
          <Modal.Body>
            <div className="row">
              <Button
                className="btnAdd btnApprove m-0"
                onClick={async () => {
                  const res = await deleteReview({ reviewId });
                  dispatch(getReviewsAction({ activityId }));
                  // dispatch(getActivitiesByFilters({}));
                  toast.success("Review deleted");
                  setshowModal(false);
                  // console.log(res);
                }}
              >
                Yes
              </Button>
              <Button
                className="btnAdd btnReject m-0"
                onClick={() => {
                  setshowModal(false);
                  setreviewId();
                }}
              >
                Cancel
              </Button>
            </div>
          </Modal.Body>
        </Modal>
      </div>
.  
jaymehta committed
111 112 113 114 115
    </div>
  );
};

export default ReviewsListing;