From 74ae4d8665aa034aec49672f36837f8085f1eed1 Mon Sep 17 00:00:00 2001 From: Salah Eddine Lalami Date: Wed, 21 Jul 2021 15:43:51 +0100 Subject: [PATCH] delete & search features fixed --- backend/controllers/crudController/crudMethods.js | 5 +---- frontend/src/components/DeleteModal/index.jsx | 1 + frontend/src/components/RecentTable/index.jsx | 7 +++++-- frontend/src/config/serverApiConfig.js | 1 + frontend/src/modules/CrudModule/index.jsx | 4 +--- frontend/src/pages/Customer.jsx | 2 +- frontend/src/pages/Product.jsx | 2 +- frontend/src/redux/crud/reducer.js | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/backend/controllers/crudController/crudMethods.js b/backend/controllers/crudController/crudMethods.js index 80401e6..08291ad 100644 --- a/backend/controllers/crudController/crudMethods.js +++ b/backend/controllers/crudController/crudMethods.js @@ -221,10 +221,7 @@ exports.search = async (Model, req, res) => { } try { - let results = await Model.find(fields) - .where("removed", false) - .sort({ name: "asc" }) - .limit(10); + let results = await Model.find(fields).sort({ name: "asc" }).limit(10); if (results.length >= 1) { return res.status(200).json({ diff --git a/frontend/src/components/DeleteModal/index.jsx b/frontend/src/components/DeleteModal/index.jsx index a449df7..ab414d4 100644 --- a/frontend/src/components/DeleteModal/index.jsx +++ b/frontend/src/components/DeleteModal/index.jsx @@ -25,6 +25,7 @@ export default function DeleteModal({ config }) { if (isSuccess) { modal.close(); dispatch(crud.list(entity)); + dispatch(crud.resetAction(entity)); } if (current) { let labels = entityDisplayLabels diff --git a/frontend/src/components/RecentTable/index.jsx b/frontend/src/components/RecentTable/index.jsx index 8d1a94a..59a31c7 100644 --- a/frontend/src/components/RecentTable/index.jsx +++ b/frontend/src/components/RecentTable/index.jsx @@ -48,13 +48,16 @@ export default function RecentTable({ ...props }) { return request.list(entity); }; const { result, isLoading, isSuccess } = useFetch(asyncList); - + const firstFiveItems = () => { + if (isSuccess && result) return result.slice(0, 5); + return []; + }; return ( <> item._id} - dataSource={isSuccess && result} + dataSource={isSuccess && firstFiveItems()} pagination={false} loading={isLoading} /> diff --git a/frontend/src/config/serverApiConfig.js b/frontend/src/config/serverApiConfig.js index d9a6f8b..3a07f73 100644 --- a/frontend/src/config/serverApiConfig.js +++ b/frontend/src/config/serverApiConfig.js @@ -1,2 +1,3 @@ export const API_BASE_URL = "https://antd-admin-mern.idurar.net/api/"; +// export const API_BASE_URL = "http://localhost:8888/api/"; export const ACCESS_TOKEN_NAME = "x-auth-token"; diff --git a/frontend/src/modules/CrudModule/index.jsx b/frontend/src/modules/CrudModule/index.jsx index 2fe13ff..65293a2 100644 --- a/frontend/src/modules/CrudModule/index.jsx +++ b/frontend/src/modules/CrudModule/index.jsx @@ -57,7 +57,7 @@ function FixHeaderPanel({ config }) { ); } -function CrudModule({ config, createForm, updateForm }) { +export default function CrudModule({ config, createForm, updateForm }) { const dispatch = useDispatch(); useLayoutEffect(() => { @@ -80,5 +80,3 @@ function CrudModule({ config, createForm, updateForm }) { ); } - -export default CrudModule; diff --git a/frontend/src/pages/Customer.jsx b/frontend/src/pages/Customer.jsx index f1c38e1..0d4c64a 100644 --- a/frontend/src/pages/Customer.jsx +++ b/frontend/src/pages/Customer.jsx @@ -6,7 +6,7 @@ import CustomerForm from "@/forms/CustomerForm"; function Customer() { const entity = "client"; const searchConfig = { - displayLabels: ["company"], + displayLabels: ["company", "surname", "name"], searchFields: "company,surname,name", outputValue: "_id", }; diff --git a/frontend/src/pages/Product.jsx b/frontend/src/pages/Product.jsx index d0d551d..d330c41 100644 --- a/frontend/src/pages/Product.jsx +++ b/frontend/src/pages/Product.jsx @@ -7,7 +7,7 @@ function Product() { const entity = "product"; const searchConfig = { displayLabels: ["productName"], - searchFields: "productName,surname,name", + searchFields: "productName", outputValue: "_id", }; diff --git a/frontend/src/redux/crud/reducer.js b/frontend/src/redux/crud/reducer.js index 6b816bc..b65833f 100644 --- a/frontend/src/redux/crud/reducer.js +++ b/frontend/src/redux/crud/reducer.js @@ -73,7 +73,7 @@ const crudReducer = (state = INITIAL_STATE, action) => { return { ...state, [keyState]: { - ...state[keyState], + ...INITIAL_KEY_STATE, current: payload, }, };