123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- import { Box } from "@mui/material";
- import { useEffect } from "react";
- import { connect, useDispatch } from "react-redux";
- import { Navigate, Route, Routes, useParams, useSearchParams } from "react-router-dom";
- import { actionPromiseClear, actionFeedCats, actionFeedGoodsFind, actionFeedOrdersFind, actionFeedCatsFind } from "../../../reducers";
- import { actionFeedAdd, actionFeedGoods, actionFeedOrders, actionFeedUsers, actionFeedUsersFind } from "../../../reducers/feedReducer";
- import { CAdminGoodPage } from "../AdminGoodPage";
- import { AdminGoodsPage } from "../AdminGoodsPage";
- import { AdminCategoriesPage } from "../AdminCategoriesPage";
- import { CAdminCategoryPage } from "../AdminCategoryPage";
- import { AdminOrdersPage } from "../AdminOrdersPage";
- import { CAdminOrderPage } from "../AdminOrderPage";
- import { actionCatAll } from "../../../actions/actionCatAll";
- import { CAdminCategoryTree } from "../AdminCategoryTree";
- import { AdminUsersPage } from "../AdminUsersPage";
- import { CAdminUserPage } from "../AdminUserPage.js";
- import { actionAdminCategoryPage } from "../../../actions/actionAdminCategoryPage";
- import { actionAdminCategoryPageClear } from "../../../actions/actionAdminCategoryPageClear";
- import { actionAdminCategoriesPage } from "../../../actions/actionAdminCategoriesPage";
- import { actionAdminCategoriesPageClear } from "../../../actions/actionAdminCategoriesPageClear";
- import { actionAdminCategoriesSearchPageClear } from "../../../actions/actionAdminCategoriesSearchPageClear";
- import { actionAdminCategoriesSearchPage } from "../../../actions/actionAdminCategoriesSearchPage";
- import { actionAdminGoodsPageClear } from "../../../actions/actionAdminGoodsPageClear";
- import { actionAdminGoodsPage } from "../../../actions/actionAdminGoodsPage";
- import { actionAdminGoodPage } from "../../../actions/actionAdminGoodPage";
- import { actionAdminGoodPageClear } from "../../../actions/actionAdminGoodPageClear";
- import { actionAdminGoodsSearchPageClear } from "../../../actions/actionAdminGoodsSearchPageClear";
- import { actionAdminGoodsSearchPage } from "../../../actions/actionAdminGoodsSearchPage";
- import { actionAdminOrdersPageClear } from "../../../actions/actionAdminOrdersPageClear";
- import { actionAdminOrdersPage } from "../../../actions/actionAdminOrdersPage";
- import { actionAdminOrdersSearchPageClear } from "../../../actions/actionAdminOrdersSearchPageClear";
- import { actionAdminOrderPage } from "../../../actions/actionAdminOrderPage";
- import { actionAdminOrderPageClear } from "../../../actions/actionAdminOrderPageClear";
- import { actionAdminUsersSearchPageClear } from "../../../actions/actionAdminUsersSearchPageClear";
- import { actionAdminUsersSearchPage } from "../../../actions/actionAdminUsersSearchPage";
- import { actionAdminUsersPageClear } from "../../../actions/actionAdminUsersPageClear";
- import { actionAdminUsersPage } from "../../../actions/actionAdminUsersPage";
- import { actionAdminUserPageClear } from "../../../actions/actionAdminUserPageClear";
- import { actionAdminUserPage } from "../../../actions/actionAdminUserPage";
- import { InfScroll } from "../../common/InfScroll";
- const AdminCategoryTreePageContainer = ({ onLoad, onUnmount }) => {
- useEffect(() => {
- onLoad();
- return () => {
- onUnmount();
- };
- }, []);
- return <CAdminCategoryTree />;
- };
- const CAdminCategoryTreePageContainer = connect(null, {
- onUnmount: () => actionCatAll(),
- onLoad: () => actionPromiseClear("catAll"),
- })(AdminCategoryTreePageContainer);
- const AdminCategoryPageContainer = ({ onUnmount, onLoad }) => {
- const params = useParams();
- useEffect(() => {
- return () => {
- onUnmount();
- };
- }, []);
- useEffect(() => {
- onLoad(params._id);
- }, [params._id]);
- return <CAdminCategoryPage />;
- };
- const CAdminCategoryPageContainer = connect(null, {
- onUnmount: () => actionAdminCategoryPageClear(),
- onLoad: (_id) => actionAdminCategoryPage({ _id }),
- })(AdminCategoryPageContainer);
- const AdminCategoriesPageContainer = ({ feed, cats, promiseStatus, onLoad, onUnmount, onScroll }) => {
- const dispatch = useDispatch();
- const [searchParams] = useSearchParams();
- const orderBy = searchParams.get("orderBy") || "_id";
- useEffect(() => {
- onLoad({ orderBy });
- return () => {
- onUnmount();
- };
- }, [orderBy]);
- useEffect(() => {
- window.onscroll = (e) => {
- if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 200) {
- if (promiseStatus !== "PENDING") {
- onScroll({ feed, orderBy });
- }
- }
- };
- return () => {
- window.onscroll = null;
- };
- }, [feed, promiseStatus]);
- useEffect(() => {
- if (cats.length) dispatch(actionFeedAdd(cats));
- }, [cats]);
- return <AdminCategoriesPage orderBy={orderBy} />;
- };
- const CAdminCategoriesPageContainer = connect(
- (state) => ({
- cats: state.promise?.feedCatAll?.payload || [],
- feed: state.feed?.payload || [],
- promiseStatus: state.promise?.feedCatAll?.status || null,
- }),
- {
- onUnmount: () => actionAdminCategoriesPageClear(),
- onLoad: ({ orderBy }) => actionAdminCategoriesPage({ orderBy }),
- onScroll: ({ feed, orderBy }) => actionFeedCats({ skip: feed?.length || 0, orderBy }),
- }
- )(AdminCategoriesPageContainer);
- const AdminCategoriesSearchPageContainer = ({ feed, cats, promiseStatus, onLoad, onUnmount, onScroll }) => {
- const dispatch = useDispatch();
- const [searchParams] = useSearchParams();
- const orderBy = searchParams.get("orderBy") || "_id";
- const text = searchParams.get("text") || "";
- useEffect(() => {
- onLoad({ orderBy, text });
- return () => {
- onUnmount();
- };
- }, [orderBy, text]);
- useEffect(() => {
- window.onscroll = (e) => {
- if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 200) {
- if (promiseStatus !== "PENDING") {
- onScroll({ feed, orderBy, text });
- }
- }
- };
- return () => {
- window.onscroll = null;
- };
- }, [promiseStatus, feed, text]);
- useEffect(() => {
- if (cats?.length) dispatch(actionFeedAdd(cats));
- }, [cats]);
- return <AdminCategoriesPage orderBy={orderBy} />;
- };
- const CAdminCategoriesSearchPageContainer = connect(
- (state) => ({
- cats: state.promise?.feedCatsFind?.payload || [],
- feed: state.feed?.payload || [],
- promiseStatus: state.promise?.feedCatsFind?.status || null,
- }),
- {
- onUnmount: () => actionAdminCategoriesSearchPageClear(),
- onLoad: ({ orderBy, text }) => actionAdminCategoriesSearchPage({ orderBy, text }),
- onScroll: ({ feed, orderBy, text }) => actionFeedCatsFind({ text, skip: feed?.length || 0, orderBy }),
- }
- )(AdminCategoriesSearchPageContainer);
- const AdminGoodPageContainer = ({ onUnmount, onLoad }) => {
- const params = useParams();
- useEffect(() => {
- onLoad(params._id);
- return () => {
- onUnmount();
- };
- }, []);
- return <CAdminGoodPage />;
- };
- const CAdminGoodPageContainer = connect(null, {
- onUnmount: () => actionAdminGoodPageClear(),
- onLoad: (_id) => actionAdminGoodPage({ _id }),
- })(AdminGoodPageContainer);
- const AdminGoodsPageContainer = ({ feed, goods, promiseStatus, onLoad, onUnmount, onScroll }) => {
- const [searchParams] = useSearchParams();
- const orderBy = searchParams.get("orderBy") || "_id";
- useEffect(() => {
- onLoad({ orderBy });
- return () => {
- onUnmount();
- };
- }, [orderBy]);
- return (
- <InfScroll
- items={goods}
- component={AdminGoodsPage}
- promiseStatus={promiseStatus}
- onScroll={() => onScroll({ feed, orderBy })}
- orderBy={orderBy}
- />
- );
- };
- const CAdminGoodsPageContainer = connect(
- (state) => ({
- goods: state.promise?.feedGoodsAll?.payload || [],
- feed: state.feed?.payload || [],
- promiseStatus: state.promise?.feedGoodsAll?.status || null,
- }),
- {
- onUnmount: () => actionAdminGoodsPageClear(),
- onLoad: ({ orderBy }) => actionAdminGoodsPage({ orderBy }),
- onScroll: ({ feed, orderBy }) => actionFeedGoods({ skip: feed?.length || 0, orderBy }),
- }
- )(AdminGoodsPageContainer);
- const AdminGoodsSearchPageContainer = ({ feed, goods, promiseStatus, onLoad, onUnmount, onScroll }) => {
- const dispatch = useDispatch();
- const [searchParams] = useSearchParams();
- const orderBy = searchParams.get("orderBy") || "_id";
- const text = searchParams.get("text") || "";
- useEffect(() => {
- onLoad({ orderBy, text });
- return () => {
- onUnmount();
- };
- }, [orderBy, text]);
- useEffect(() => {
- window.onscroll = (e) => {
- if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 200) {
- if (promiseStatus !== "PENDING") {
- onScroll({ feed, orderBy, text });
- }
- }
- };
- return () => {
- window.onscroll = null;
- };
- }, [promiseStatus, feed, text]);
- useEffect(() => {
- if (goods?.length) dispatch(actionFeedAdd(goods));
- }, [goods]);
- return <AdminGoodsPage orderBy={orderBy} />;
- };
- const CAdminGoodsSearchPageContainer = connect(
- (state) => ({
- goods: state.promise?.feedGoodsFind?.payload || [],
- feed: state.feed?.payload || [],
- promiseStatus: state.promise?.feedGoodsFind?.status || null,
- }),
- {
- onUnmount: () => actionAdminGoodsSearchPageClear(),
- onLoad: ({ orderBy, text }) => actionAdminGoodsSearchPage({ orderBy, text }),
- onScroll: ({ feed, orderBy, text }) => actionFeedGoodsFind({ text, skip: feed?.length || 0, orderBy }),
- }
- )(AdminGoodsSearchPageContainer);
- const AdminOrdersPageContainer = ({ feed, orders, promiseStatus, onLoad, onUnmount, onScroll }) => {
- const dispatch = useDispatch();
- const [searchParams] = useSearchParams();
- const orderBy = searchParams.get("orderBy") || "_id";
- const status = searchParams.get("status") || 0;
- useEffect(() => {
- onLoad({ orderBy, status });
- return () => {
- onUnmount();
- };
- }, [orderBy, status]);
- useEffect(() => {
- window.onscroll = (e) => {
- if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 200) {
- if (promiseStatus !== "PENDING") {
- onScroll({ feed, orderBy, status });
- }
- }
- };
- return () => {
- window.onscroll = null;
- };
- }, [promiseStatus, feed, status]);
- useEffect(() => {
- if (orders?.length) dispatch(actionFeedAdd(orders));
- }, [orders]);
- return <AdminOrdersPage orderBy={orderBy} />;
- };
- const CAdminOrdersPageContainer = connect(
- (state) => ({
- orders: state.promise?.feedOrdersAll?.payload || [],
- feed: state.feed?.payload || [],
- promiseStatus: state.promise?.feedOrdersAll?.status || null,
- }),
- {
- onUnmount: () => actionAdminOrdersPageClear(),
- onLoad: ({ orderBy, status }) => actionAdminOrdersPage({ orderBy, status }),
- onScroll: ({ feed, orderBy, status }) => actionFeedOrders({ skip: feed?.length || 0, orderBy, status }),
- }
- )(AdminOrdersPageContainer);
- const AdminOrdersSearchPageContainer = ({ feed, orders, promiseStatus, onLoad, onUnmount, onScroll }) => {
- const dispatch = useDispatch();
- const [searchParams] = useSearchParams();
- const orderBy = searchParams.get("orderBy") || "_id";
- const text = searchParams.get("text") || "";
- const status = searchParams.get("status") || 0;
- useEffect(() => {
- onLoad({ orderBy, text });
- return () => {
- onUnmount();
- };
- }, [orderBy, text, status]);
- useEffect(() => {
- window.onscroll = (e) => {
- if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 200) {
- if (promiseStatus !== "PENDING") {
- onScroll({ feed, orderBy, text, status });
- }
- }
- };
- return () => {
- window.onscroll = null;
- };
- }, [promiseStatus, feed, text, status]);
- useEffect(() => {
- if (orders?.length) dispatch(actionFeedAdd(orders));
- }, [orders]);
- return <AdminOrdersPage orderBy={orderBy} />;
- };
- const CAdminOrdersSearchPageContainer = connect(
- (state) => ({
- orders: state.promise?.feedOrdersFind?.payload || [],
- feed: state.feed?.payload || [],
- promiseStatus: state.promise?.feedOrdersFind?.status || null,
- }),
- {
- onUnmount: () => actionAdminOrdersSearchPageClear(),
- onLoad: ({ orderBy, text, status }) => actionAdminOrdersSearchPageClear({ orderBy, text, status }),
- onScroll: ({ feed, orderBy, text, status }) => actionFeedOrdersFind({ text, skip: feed?.length || 0, orderBy, status }),
- }
- )(AdminOrdersSearchPageContainer);
- const AdminOrderPageContainer = ({ onLoad, onUnmount }) => {
- const params = useParams();
- useEffect(() => {
- return () => {
- onUnmount();
- };
- }, []);
- useEffect(() => {
- onLoad(params._id);
- }, [params._id]);
- return <CAdminOrderPage />;
- };
- const CAdminOrderPageContainer = connect(null, {
- onUnmount: () => actionAdminOrderPageClear(),
- onLoad: (_id) => actionAdminOrderPage({ _id }),
- })(AdminOrderPageContainer);
- const AdminUsersSearchPageContainer = ({ feed, users, promiseStatus, onLoad, onUnmount, onScroll }) => {
- const dispatch = useDispatch();
- const [searchParams] = useSearchParams();
- const orderBy = searchParams.get("orderBy") || "_id";
- const text = searchParams.get("text") || "";
- useEffect(() => {
- onLoad({ orderBy, text });
- return () => {
- onUnmount();
- };
- }, [orderBy, text]);
- useEffect(() => {
- window.onscroll = (e) => {
- if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 200) {
- if (promiseStatus !== "PENDING") {
- onScroll({ feed, orderBy, text });
- }
- }
- };
- return () => {
- window.onscroll = null;
- };
- }, [promiseStatus, feed, text]);
- useEffect(() => {
- if (users?.length) dispatch(actionFeedAdd(users));
- }, [users]);
- return <AdminUsersPage orderBy={orderBy} />;
- };
- const CAdminUsersSearchPageContainer = connect(
- (state) => ({
- users: state.promise?.feedUsersFind?.payload || [],
- feed: state.feed?.payload || [],
- promiseStatus: state.promise?.feedUsersFind?.status || null,
- }),
- {
- onUnmount: () => actionAdminUsersSearchPageClear(),
- onLoad: ({ orderBy, text }) => actionAdminUsersSearchPage({ orderBy, text }),
- onScroll: ({ feed, orderBy, text }) => actionFeedUsersFind({ text, skip: feed?.length || 0, orderBy }),
- }
- )(AdminUsersSearchPageContainer);
- const AdminUsersPageContainer = ({ feed, users, promiseStatus, onLoad, onUnmount, onScroll }) => {
- const dispatch = useDispatch();
- const [searchParams] = useSearchParams();
- const orderBy = searchParams.get("orderBy") || "_id";
- useEffect(() => {
- onLoad({ orderBy });
- return () => {
- onUnmount();
- };
- }, [orderBy]);
- useEffect(() => {
- window.onscroll = (e) => {
- if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 200) {
- if (promiseStatus !== "PENDING") {
- onScroll({ feed, orderBy });
- }
- }
- };
- return () => {
- window.onscroll = null;
- };
- }, [promiseStatus, feed]);
- useEffect(() => {
- if (users?.length) dispatch(actionFeedAdd(users));
- }, [users]);
- return <AdminUsersPage orderBy={orderBy} />;
- };
- const CAdminUsersPageContainer = connect(
- (state) => ({
- users: state.promise?.feedUsersAll?.payload || [],
- feed: state.feed?.payload || [],
- promiseStatus: state.promise?.feedUsersAll?.status || null,
- }),
- {
- onUnmount: () => actionAdminUsersPageClear(),
- onLoad: ({ orderBy }) => actionAdminUsersPage({ orderBy }),
- onScroll: ({ feed, orderBy }) => actionFeedUsers({ skip: feed?.length || 0, orderBy }),
- }
- )(AdminUsersPageContainer);
- const AdminUserPageContainer = ({ onLoad, onUnmount }) => {
- const params = useParams();
- useEffect(() => {
- return () => {
- onUnmount();
- };
- }, []);
- useEffect(() => {
- onLoad(params._id);
- }, [params._id]);
- return <CAdminUserPage />;
- };
- const CAdminUserPageContainer = connect(null, {
- onUnmount: () => actionAdminUserPageClear(),
- onLoad: (_id) => actionAdminUserPage({ _id }),
- })(AdminUserPageContainer);
- const AdminLayoutPage = () => {
- return (
- <Box className="AdminLayoutPage">
- <Routes>
- <Route path="/" element={<Navigate to={"/admin/goods/"} />} />
- <Route path="/tree/" element={<CAdminCategoryTreePageContainer />} />
- <Route path="/goods/" element={<CAdminGoodsPageContainer />} />
- <Route path="/goods/search" element={<CAdminGoodsSearchPageContainer />} />
- <Route path="/good/" element={<CAdminGoodPageContainer />} />
- <Route path="/good/:_id" element={<CAdminGoodPageContainer />} />
- <Route path="/categories/" element={<CAdminCategoriesPageContainer />} />
- <Route path="/categories/search" element={<CAdminCategoriesSearchPageContainer />} />
- <Route path="/category/" element={<CAdminCategoryPageContainer />} />
- <Route path="/category/:_id" element={<CAdminCategoryPageContainer />} />
- <Route path="/orders/" element={<CAdminOrdersPageContainer />} />
- <Route path="/orders/search" element={<CAdminOrdersSearchPageContainer />} />
- <Route path="/order/" element={<CAdminOrderPageContainer />} />
- <Route path="/order/:_id" element={<CAdminOrderPageContainer />} />
- <Route path="/users/search" element={<CAdminUsersSearchPageContainer />} />
- <Route path="/users/" element={<CAdminUsersPageContainer />} />
- <Route path="/user/" element={<CAdminUserPageContainer />} />
- <Route path="/user/:_id" element={<CAdminUserPageContainer />} />
- <Route path="*" element={<Navigate to="/404" />} />
- </Routes>
- </Box>
- );
- };
- export { AdminLayoutPage };
|