index.js 2.92 KB
import React, { useEffect, useState } from "react";
import Layout from "../../../components/layout/Layout";
import Sidebar from "../../../components/layout/AdminDashboardSidebar";
import ActivityListing from "../../../components/admin/ActivityListing";
import ActivityListingRBAC from "../../../components/vendor/ActivityListingRBAC";
import { wrapper } from "../../../redux/store";
import { loadUser } from "../../../redux/actions/userActions";
import { getAllCategories, getAllSubCategories } from "../../../redux/actions/categoriesAction";
import { useDispatch } from "react-redux";
import { getActivitiesForAdmin } from "../../../redux/actions/activityAction";
import ActivityDetailsModal from "../../../components/admin/ActivityDetailsModal";
import { GenericLayout } from "../../../components/layout/Generics/GenericLayout";

export default function ActivityListingPage() {
  const [activityDetailInfo, setactivityDetailInfo] = useState();
  const [showActivityDetailsModal, setShowActivityDetailsModal] = useState(false);

  const handleCloseActivityDetails = () => {
    setShowActivityDetailsModal(false);
  };

  const dispatch = useDispatch();
  useEffect(() => {
    dispatch(getActivitiesForAdmin({ pageNumber: 1 }));
  }, []);

  const [tableCurrentPage, settableCurrentPage] = useState(1);
  const [tableItemsPerPage, settableItemsPerPage] = useState(10);
  const [filterValue, setfilterValue] = useState();

  const onChange = (pagination, filters, sorter, extra, searchText) => {
    console.log("params", pagination, filters, sorter, extra);
    settableCurrentPage(pagination.current);
    settableItemsPerPage(pagination.pageSize);
    dispatch(getActivitiesForAdmin({ pageNumber: pagination.current, pageSize: pagination.pageSize, vendorName: filterValue }));
  };

  return (
    <GenericLayout>
      {/* <Layout> */}
      {/* <div className="sidebarContainer"> */}
      {/* <Sidebar /> */}
      {/* <div className="content"> */}
      {/* <ActivityListing /> */}
      <ActivityListingRBAC
        setfilterValue={setfilterValue}
        setactivityDetailInfo={setactivityDetailInfo}
        setShowActivityDetailsModal={setShowActivityDetailsModal}
        onChange={onChange}
        tableCurrentPage={tableCurrentPage}
        tableItemsPerPage={tableItemsPerPage}
      />
      {showActivityDetailsModal && <ActivityDetailsModal show={showActivityDetailsModal} handleClose={handleCloseActivityDetails} activityDetailInfo={activityDetailInfo} />}
      {/* </div> */}
      {/* </div> */}
      {/* </Layout> */}
    </GenericLayout>
  );
}

/** For server side rendering */
export const getServerSideProps = wrapper.getServerSideProps(store => async ({ req, query }) => {
  await store.dispatch(loadUser());
  // await store.dispatch(getActivitiesByVendor());
  await store.dispatch(getAllCategories());
  await store.dispatch(getAllSubCategories());
  // get the locations data.
  // await store.dispatch(getVendorDetails())

  return {
    props: {}
  };
});