Browse Source

before dispatch refuctoring

ilya_shyian 1 year ago
parent
commit
745a50d2e4

+ 7 - 0
src/actions/actionCategoryDeleteFull.js

@@ -0,0 +1,7 @@
+import { gql } from "../helpers";
+
+import { actionPromise } from "../reducers";
+
+export const actionCategoryDelete =
+    ({ category, promiseName = "categoryDelete" } = {}) =>
+    async (dispatch, getState) => {};

+ 4 - 3
src/components/admin/AdminCategoryPage/CategoryForm.js

@@ -49,7 +49,7 @@ const CategoryForm = ({
             category?._id && (categoryToSave._id = category?._id);
             categoryToSave.name = formik.values.name;
             inputGoods && (categoryToSave.goods = inputGoods);
-            inputParent && (categoryToSave.parent = inputParent);
+            inputParent && (categoryToSave.parent = inputParent._id ? inputParent : null);
 
             categoryToSave.subcategories = inputSubcategories;
             onSaveClick && onSaveClick();
@@ -128,14 +128,15 @@ const CategoryForm = ({
         parentList = [...[{ _id: null, name: "null" }], ...parentList];
 
         setParentList(parentList);
-    }, [inputSubcategories]);
+    }, [inputSubcategories, initialCatList]);
 
     useEffect(() => {
         let subCatList = initialCatList.filter(
             ({ _id }) => _id !== category?.parent?._id && _id !== category?._id && inputParent?._id !== _id
         );
+
         setSubCatList(subCatList);
-    }, [inputParent]);
+    }, [inputParent, initialCatList]);
 
     useEffect(() => {
         return () => {

+ 6 - 4
src/components/admin/AdminLayoutPage/index.js

@@ -359,6 +359,11 @@ const AdminOrderPageContainer = () => {
 const AdminUsersSearchPageContainer = () => {
     const dispatch = useDispatch();
     const users = useSelector((state) => state.promise?.feedUsersFind?.payload || []);
+    const {
+        feed,
+        promise: { feedUsersFind },
+    } = useSelector((state) => state);
+
     const [searchParams] = useSearchParams();
     const orderBy = searchParams.get("orderBy") || "_id";
     const text = searchParams.get("text") || "";
@@ -384,12 +389,9 @@ const AdminUsersSearchPageContainer = () => {
             }
         };
         return () => {
-            dispatch(actionFeedClear());
-            dispatch(actionPromiseClear("feedUsersFind"));
-            dispatch(actionPromiseClear("userUpsert"));
             window.onscroll = null;
         };
-    }, []);
+    }, [feed, feedUsersFind]);
 
     useEffect(() => {
         if (users?.length) store.dispatch(actionFeedAdd(users));

+ 1 - 1
src/helpers/index.js

@@ -4,7 +4,7 @@ import { getGQL } from "./GraphQL";
 import { statusNumber, statusOptions } from "./orderStatus";
 import { aclList } from "./aclList";
 
-export const backendURL = "http://188.72.209.29/api";
+export const backendURL = "";
 export const gql = getGQL(backendURL + "/graphql/");
 
 export const mediaURL = "";

+ 1 - 1
src/reducers/feedReducer.js

@@ -69,7 +69,7 @@ const actionFeedOrdersFind =
 const actionFeedUsersFind =
     ({ skip = 0, text = "", orderBy = "_id" }) =>
     async (dispatch, getState) => {
-        await dispatch(actionUsersFind({ skip, promiseName: "feedUsersFind", text, limit: 7, orderBy }));
+        await dispatch(actionUsersFind({ skip, promiseName: "feedUsersFind", text, limit: 3, orderBy }));
     };
 
 const actionFeedUsers =