ListingItems.js 3.66 KB
import { Empty } from "antd";
import Image from "next/image";
import { useRouter } from "next/router";
import React, { useState } from "react";
import { Button } from "react-bootstrap";
import { Loader } from "react-bootstrap-typeahead";
import { useSelector } from "react-redux";
import { cleanImage } from "../../services/imageHandling";
import WishlistComponent from "../detail/WIshlistComponent";

const ListingItems = ({ allActivitiesData, loading, gridClass }) => {
  // const [gridClass, setGridClass] = useState('col-md-3');
  const { endUser } = useSelector(state => state.endUser);
  console.log("endUser", endUser);
  const router = useRouter();
  
  return (
    <>
      {allActivitiesData && !allActivitiesData.data.length == 0 ? (
        <div className="listing-items">
          {!loading ? (
            <div className="row">
              {allActivitiesData &&
                allActivitiesData.data.map(data => {
                  return (
                    <div className={gridClass}>
                      <div className="item">
                        <div className="browse-experiences-item">
                          <div className="img-wrapper">
                            <span className="image-container">
                              <Image layout="fill" alt="" className="image img-fluid" src={cleanImage(data.attributes?.image?.data?.attributes)} />
                            </span>
                            <div className="top-rated">Top Rated</div>
                          </div>
                          <div className="info">
                            <div className="top-name">
                              <div className="title">{data?.attributes?.name}</div>
                              <div className="rating-wishlist">
                                <div className="rating">
                                  {data?.attributes?.rating}
                                  <span className="image-container">
                                    <Image layout="fill" alt="" className="image img-fluid" src="/images/icons/star.svg" />
                                  </span>
                                </div>
                                {endUser && <WishlistComponent activityId={data.id} userId={endUser.id} />}
                              </div>
                            </div>
                            <div className="discription">
                              {data.discription} <a href="">Read More</a>
                            </div>
                            <div className="price">
                              ${data?.attributes?.pricePerPerson} <span className="off">{data?.attributes?.off}% OFF</span>
                            </div>
                            <div className="detail">
                              <div className="">For 1 Night</div>
                              <div className="">Includes taxes & Fees</div>
                            </div>
                            <div className="explore-now">
                              <Button
                                onClick={() => {
                                  router.push(`/activities/${data.id}`);
                                }}
                                variant="primary"
                              >
                                Explore Now
                              </Button>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  );
                })}
            </div>
          ) : (
            <Loader />
          )}
        </div>
      ) : (
        <Empty />
      )}
    </>
  );
};

export default ListingItems;