From 968730a91b265ad4f49421ceb90458641d1368ef Mon Sep 17 00:00:00 2001 From: abhishek-p-s Date: Sat, 13 Jan 2024 15:08:16 +0530 Subject: [PATCH 1/2] [#906] administration cascade bug debuging --- .../filters/AdministrationDropdown.js | 19 +++++++----- .../pages/mobile-assignment/AddAssignment.jsx | 30 ++++++++++--------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/frontend/src/components/filters/AdministrationDropdown.js b/frontend/src/components/filters/AdministrationDropdown.js index c220e2a54..08c1440cf 100644 --- a/frontend/src/components/filters/AdministrationDropdown.js +++ b/frontend/src/components/filters/AdministrationDropdown.js @@ -25,9 +25,9 @@ const AdministrationDropdown = ({ const lowestLevel = maxLevel ? levels.find((l) => l?.id === maxLevel) : levels - .slice() - .sort((a, b) => a.level - b.level) - .slice(-1)?.[0]; + .slice() + .sort((a, b) => a.level - b.level) + .slice(-1)?.[0]; const fetchUserAdmin = useCallback(async () => { if (user && !persist) { @@ -53,13 +53,16 @@ const AdministrationDropdown = ({ return; } const { data: selectedAdm } = await api.get(`administration/${e}`); + const admItems = Array.isArray(selectedAdm) ? selectedAdm : [selectedAdm]; store.update((s) => { s.administration.length = index + 1; - s.administration = s.administration.concat(selectedAdm); + s.administration = s.administration.concat(admItems); }); if (onChange) { - const _values = allowMultiple && Array.isArray(e) ? e : null; - onChange(_values); + // console.log(allowMultiple, "allowMultiple"); + // const _values = allowMultiple && Array.isArray(e) ? e : [e]; + console.log(e, "_values"); + onChange(e); } }; @@ -94,8 +97,8 @@ const AdministrationDropdown = ({ const selectValues = selectMode === "multiple" ? administration - ?.slice(regionIdx + 1, administration.length) - ?.map((a) => a?.id) + ?.slice(regionIdx + 1, administration.length) + ?.map((a) => a?.id) : administration[regionIdx + 1]?.id || null; return (
diff --git a/frontend/src/pages/mobile-assignment/AddAssignment.jsx b/frontend/src/pages/mobile-assignment/AddAssignment.jsx index 2967a7dcc..bdf5d3ad9 100644 --- a/frontend/src/pages/mobile-assignment/AddAssignment.jsx +++ b/frontend/src/pages/mobile-assignment/AddAssignment.jsx @@ -29,6 +29,7 @@ const AddAssignment = () => { const [loading, setLoading] = useState(false); const [preload, setPreload] = useState(true); const [level, setLevel] = useState(userAdmLevel); + const [selectedAdministrations, setSelectedAdministrations] = useState([]); const lowestLevel = levels .slice() @@ -55,7 +56,7 @@ const AddAssignment = () => { const text = useMemo(() => { return uiText[activeLang]; }, [activeLang]); - + console.log(selectedAdm, "selectedAdm in ass assignment page"); const pageTitle = id ? text.mobileEditText : text.mobileAddText; const descriptionData = (

{id ? text.mobilePanelEditDesc : text.mobilePanelAddDesc}

@@ -129,20 +130,21 @@ const AddAssignment = () => { const payload = { name: values.name, administrations: - values.administrations || selectedAdm.map((a) => a?.id), + selectedAdministrations || selectedAdm.map((a) => a?.id), forms: values.forms, }; - if (id) { - await api.put(`/mobile-assignments/${id}`, payload); - } else { - await api.post("/mobile-assignments", payload); - } - notify({ - type: "success", - message: id ? text.mobileSuccessUpdated : text.mobileSuccessAdded, - }); - setLoading(false); - navigate("/control-center/mobile-assignment"); + console.log(payload, "payload"); + // if (id) { + // await api.put(`/mobile-assignments/${id}`, payload); + // } else { + // await api.post("/mobile-assignments", payload); + // } + // notify({ + // type: "success", + // message: id ? text.mobileSuccessUpdated : text.mobileSuccessAdded, + // }); + // setLoading(false); + // navigate("/control-center/mobile-assignment"); } catch { setSubmitting(false); } @@ -265,7 +267,7 @@ const AddAssignment = () => { maxLevel={level} onChange={(values) => { if (values) { - form.setFieldsValue({ administrations: values }); + setSelectedAdministrations(values); } }} persist={id ? true : false} From 165078e3761f08fdd9c01f8afa1198aaba754551 Mon Sep 17 00:00:00 2001 From: abhishek-p-s Date: Mon, 15 Jan 2024 11:05:23 +0530 Subject: [PATCH 2/2] [#906] multiple select dropdown fixed --- .../filters/AdministrationDropdown.js | 31 ++++++++++++------- .../pages/mobile-assignment/AddAssignment.jsx | 24 +++++++------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/frontend/src/components/filters/AdministrationDropdown.js b/frontend/src/components/filters/AdministrationDropdown.js index 08c1440cf..72279152d 100644 --- a/frontend/src/components/filters/AdministrationDropdown.js +++ b/frontend/src/components/filters/AdministrationDropdown.js @@ -25,9 +25,9 @@ const AdministrationDropdown = ({ const lowestLevel = maxLevel ? levels.find((l) => l?.id === maxLevel) : levels - .slice() - .sort((a, b) => a.level - b.level) - .slice(-1)?.[0]; + .slice() + .sort((a, b) => a.level - b.level) + .slice(-1)?.[0]; const fetchUserAdmin = useCallback(async () => { if (user && !persist) { @@ -52,17 +52,26 @@ const AdministrationDropdown = ({ if (!e) { return; } - const { data: selectedAdm } = await api.get(`administration/${e}`); - const admItems = Array.isArray(selectedAdm) ? selectedAdm : [selectedAdm]; + let admItems = null; + if (Array.isArray(e)) { + const multiadministration = await Promise.all( + e.map(async (ID) => { + const apiResponse = await api.get(`administration/${ID}`); + return apiResponse.data; + }) + ); + admItems = multiadministration; + } else { + const { data: selectedAdm } = await api.get(`administration/${e}`); + admItems = [selectedAdm]; + } store.update((s) => { s.administration.length = index + 1; s.administration = s.administration.concat(admItems); }); if (onChange) { - // console.log(allowMultiple, "allowMultiple"); - // const _values = allowMultiple && Array.isArray(e) ? e : [e]; - console.log(e, "_values"); - onChange(e); + const _values = allowMultiple && Array.isArray(e) ? e : [e]; + onChange(_values); } }; @@ -97,8 +106,8 @@ const AdministrationDropdown = ({ const selectValues = selectMode === "multiple" ? administration - ?.slice(regionIdx + 1, administration.length) - ?.map((a) => a?.id) + ?.slice(regionIdx + 1, administration.length) + ?.map((a) => a?.id) : administration[regionIdx + 1]?.id || null; return (
diff --git a/frontend/src/pages/mobile-assignment/AddAssignment.jsx b/frontend/src/pages/mobile-assignment/AddAssignment.jsx index bdf5d3ad9..5735b63bb 100644 --- a/frontend/src/pages/mobile-assignment/AddAssignment.jsx +++ b/frontend/src/pages/mobile-assignment/AddAssignment.jsx @@ -56,7 +56,6 @@ const AddAssignment = () => { const text = useMemo(() => { return uiText[activeLang]; }, [activeLang]); - console.log(selectedAdm, "selectedAdm in ass assignment page"); const pageTitle = id ? text.mobileEditText : text.mobileAddText; const descriptionData = (

{id ? text.mobilePanelEditDesc : text.mobilePanelAddDesc}

@@ -133,18 +132,17 @@ const AddAssignment = () => { selectedAdministrations || selectedAdm.map((a) => a?.id), forms: values.forms, }; - console.log(payload, "payload"); - // if (id) { - // await api.put(`/mobile-assignments/${id}`, payload); - // } else { - // await api.post("/mobile-assignments", payload); - // } - // notify({ - // type: "success", - // message: id ? text.mobileSuccessUpdated : text.mobileSuccessAdded, - // }); - // setLoading(false); - // navigate("/control-center/mobile-assignment"); + if (id) { + await api.put(`/mobile-assignments/${id}`, payload); + } else { + await api.post("/mobile-assignments", payload); + } + notify({ + type: "success", + message: id ? text.mobileSuccessUpdated : text.mobileSuccessAdded, + }); + setLoading(false); + navigate("/control-center/mobile-assignment"); } catch { setSubmitting(false); }