AdminOrdersSearchPageContainer.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { connect } from "react-redux";
  2. import { useEffect } from "react";
  3. import { useSearchParams } from "react-router-dom";
  4. import { actionFeedOrdersFind } from "../../../../reducers";
  5. import { InfScroll } from "../../../common/InfScroll";
  6. import { AdminOrdersPage } from "../../AdminOrdersPage";
  7. import { actionOrdersSearchPage } from "../../../../actions/actionOrdersSearchPage";
  8. const AdminOrdersSearchPageContainer = ({ feed, orders, promiseStatus, onLoad, onUnmount, onScroll }) => {
  9. const [searchParams] = useSearchParams();
  10. const orderBy = searchParams.get("orderBy") || "_id";
  11. const text = searchParams.get("text") || "";
  12. const status = searchParams.get("status") || 0;
  13. useEffect(() => {
  14. onLoad({ orderBy, text });
  15. return () => {
  16. onUnmount();
  17. };
  18. }, [orderBy, text, status]);
  19. return (
  20. <InfScroll
  21. items={orders}
  22. component={AdminOrdersPage}
  23. promiseStatus={promiseStatus}
  24. onScroll={() => onScroll({ feed, orderBy })}
  25. orderBy={orderBy}
  26. />
  27. );
  28. };
  29. export const CAdminOrdersSearchPageContainer = connect(
  30. (state) => ({
  31. orders: state.promise?.feedOrdersFind?.payload || [],
  32. feed: state.feed?.payload || [],
  33. promiseStatus: state.promise?.feedOrdersFind?.status || null,
  34. }),
  35. {
  36. onUnmount: () => ({ type: "ORDERS_SEARCH_PAGE_CLEAR" }),
  37. onLoad: ({ orderBy, text, status }) => actionOrdersSearchPage({ orderBy, text, status }),
  38. onScroll: ({ feed, orderBy, text, status }) => actionFeedOrdersFind({ text, skip: feed?.length || 0, orderBy, status }),
  39. }
  40. )(AdminOrdersSearchPageContainer);