From 63189611deb14fa1ec66ef345afef852daa1fd24 Mon Sep 17 00:00:00 2001 From: Lukasz Mroz Date: Thu, 11 Jul 2024 16:52:56 +0200 Subject: [PATCH 1/6] feat: add handleSwitchEdit function --- frontend/src/components/DataTable/DataTable.jsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/DataTable/DataTable.jsx b/frontend/src/components/DataTable/DataTable.jsx index f7860a927..8c02cbeb9 100644 --- a/frontend/src/components/DataTable/DataTable.jsx +++ b/frontend/src/components/DataTable/DataTable.jsx @@ -84,6 +84,16 @@ export default function DataTable({ config, extra = [] }) { panel.open(); collapsedBox.open(); } + function handleSwitchEdit(record, key) { + const newRecord = { + ...record, + [key]: !record[key] + } + dispatch(crud.update({ entity, id: newRecord._id, jsonData: newRecord })) + .then(() => { + dispatch(crud.list({ entity })); + }); + } function handleDelete(record) { dispatch(crud.currentAction({ actionType: 'delete', data: record })); modal.open(); @@ -99,7 +109,7 @@ export default function DataTable({ config, extra = [] }) { let dispatchColumns = []; if (fields) { - dispatchColumns = [...dataForTable({ fields, translate, moneyFormatter, dateFormat })]; + dispatchColumns = [...dataForTable({ fields, translate, moneyFormatter, dateFormat, handleSwitchEdit })]; } else { dispatchColumns = [...dataTableColumns]; } From f169b84182137c2fc772d675963df035693fbebd Mon Sep 17 00:00:00 2001 From: Lukasz Mroz Date: Thu, 11 Jul 2024 16:53:24 +0200 Subject: [PATCH 2/6] feat: update switch logic --- frontend/src/utils/dataStructure.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/utils/dataStructure.jsx b/frontend/src/utils/dataStructure.jsx index fb2b32426..cdcf16b3a 100644 --- a/frontend/src/utils/dataStructure.jsx +++ b/frontend/src/utils/dataStructure.jsx @@ -20,7 +20,7 @@ export const dataForRead = ({ fields, translate }) => { return columns; }; -export function dataForTable({ fields, translate, moneyFormatter, dateFormat }) { +export function dataForTable({ fields, translate, moneyFormatter, dateFormat, handleSwitchEdit }) { let columns = []; Object.keys(fields).forEach((key) => { @@ -43,6 +43,7 @@ export function dataForTable({ fields, translate, moneyFormatter, dateFormat }) checked={record[key]} checkedChildren={} unCheckedChildren={} + onChange={() => handleSwitchEdit(record, key)} /> ), }, From 16cfd4880839c00c717deb09a551d35496b4f2c3 Mon Sep 17 00:00:00 2001 From: Lukasz Mroz Date: Mon, 15 Jul 2024 19:52:17 +0200 Subject: [PATCH 3/6] feat: add switchUpdate in DataTable --- frontend/src/components/DataTable/DataTable.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/DataTable/DataTable.jsx b/frontend/src/components/DataTable/DataTable.jsx index 8c02cbeb9..a73216718 100644 --- a/frontend/src/components/DataTable/DataTable.jsx +++ b/frontend/src/components/DataTable/DataTable.jsx @@ -89,7 +89,7 @@ export default function DataTable({ config, extra = [] }) { ...record, [key]: !record[key] } - dispatch(crud.update({ entity, id: newRecord._id, jsonData: newRecord })) + dispatch(crud.update({ entity, id: newRecord._id, jsonData: newRecord, switchUpdate: true })) .then(() => { dispatch(crud.list({ entity })); }); From 5ca1549c46944311aa0d9162c9d4bcd0ccf93070 Mon Sep 17 00:00:00 2001 From: Lukasz Mroz Date: Mon, 15 Jul 2024 19:52:54 +0200 Subject: [PATCH 4/6] feat: add switchUpdate action logic --- frontend/src/redux/crud/actions.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/frontend/src/redux/crud/actions.js b/frontend/src/redux/crud/actions.js index 31132f835..798da861e 100644 --- a/frontend/src/redux/crud/actions.js +++ b/frontend/src/redux/crud/actions.js @@ -132,7 +132,7 @@ export const crud = { } }, update: - ({ entity, id, jsonData, withUpload = false }) => + ({ entity, id, jsonData, withUpload = false, switchUpdate = false }) => async (dispatch) => { dispatch({ type: actionTypes.REQUEST_LOADING, @@ -145,15 +145,17 @@ export const crud = { if (withUpload) { data = await request.updateAndUpload({ entity, id, jsonData }); } else { - data = await request.update({ entity, id, jsonData }); + data = await request.update({ entity, id, jsonData, switchUpdate }); } if (data.success === true) { - dispatch({ - type: actionTypes.REQUEST_SUCCESS, - keyState: 'update', - payload: data.result, - }); + if(!switchUpdate) { + dispatch({ + type: actionTypes.REQUEST_SUCCESS, + keyState: 'update', + payload: data.result, + }); + } dispatch({ type: actionTypes.CURRENT_ITEM, payload: data.result, From 863490ef4de5e190b4dc01bc20001c759f764a3d Mon Sep 17 00:00:00 2001 From: Lukasz Mroz Date: Mon, 15 Jul 2024 19:53:06 +0200 Subject: [PATCH 5/6] feat: add switchUpdate request logic --- frontend/src/request/request.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/frontend/src/request/request.js b/frontend/src/request/request.js index febf19028..7a399ac08 100644 --- a/frontend/src/request/request.js +++ b/frontend/src/request/request.js @@ -48,13 +48,15 @@ const request = { return errorHandler(error); } }, - update: async ({ entity, id, jsonData }) => { + update: async ({ entity, id, jsonData, switchUpdate }) => { try { const response = await axios.patch(entity + '/update/' + id, jsonData); - successHandler(response, { - notifyOnSuccess: true, - notifyOnFailed: true, - }); + if(!switchUpdate) { + successHandler(response, { + notifyOnSuccess: true, + notifyOnFailed: true, + }); + } return response.data; } catch (error) { return errorHandler(error); From f64bf7216dc509d3f12cc1697b17ec4776126e2d Mon Sep 17 00:00:00 2001 From: Lukasz Mroz Date: Tue, 16 Jul 2024 19:29:58 +0200 Subject: [PATCH 6/6] feat: sort product categories by name --- frontend/src/components/DataTable/DataTable.jsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/DataTable/DataTable.jsx b/frontend/src/components/DataTable/DataTable.jsx index a73216718..e577c4448 100644 --- a/frontend/src/components/DataTable/DataTable.jsx +++ b/frontend/src/components/DataTable/DataTable.jsx @@ -159,7 +159,12 @@ export default function DataTable({ config, extra = [] }) { const { result: listResult, isLoading: listIsLoading } = useSelector(selectListItems); - const { pagination, items: dataSource } = listResult; + const sortedItems = [...listResult.items].sort((a, b) => a.name.localeCompare(b.name)); + + const { pagination, items: dataSource } = { + ...listResult, + items: sortedItems, + }; const dispatch = useDispatch();