From 4ec9b5140b99a4067a29d993b1c61d683325ebbd Mon Sep 17 00:00:00 2001 From: abhishek Date: Tue, 30 Jan 2024 18:41:05 +0530 Subject: [PATCH 1/5] [#1099] select all village added for mobile user adding --- .../filters/AdministrationDropdown.js | 29 ++++++++++++++++++- .../pages/mobile-assignment/AddAssignment.jsx | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/filters/AdministrationDropdown.js b/frontend/src/components/filters/AdministrationDropdown.js index 7e6754aec..0c2977eda 100644 --- a/frontend/src/components/filters/AdministrationDropdown.js +++ b/frontend/src/components/filters/AdministrationDropdown.js @@ -1,6 +1,6 @@ import React, { useEffect } from "react"; import "./style.scss"; -import { Select, Space } from "antd"; +import { Select, Space, Checkbox, Row, Col } from "antd"; import PropTypes from "prop-types"; import { store, api } from "../../lib"; import { useCallback } from "react"; @@ -16,6 +16,7 @@ const AdministrationDropdown = ({ currentId = null, onChange, limitLevel = false, + isSelectAllVillage = false, ...props }) => { const { user, administration, levels } = store.useState((state) => state); @@ -73,6 +74,23 @@ const AdministrationDropdown = ({ } }; + const handleSelectAllVillage = (e) => { + if (e.target.checked) { + let admItems = null; + const multiadministration = administration?.find( + (admLevel) => admLevel.level === lowestLevel.level - 1 + )?.children; + admItems = multiadministration; + store.update((s) => { + s.administration = s.administration.concat(admItems); + }); + } else { + store.update((s) => { + s.administration = s.administration.slice(0, 2); + }); + } + }; + const handleClear = (index) => { store.update((s) => { s.administration.length = index + 1; @@ -151,6 +169,15 @@ const AdministrationDropdown = ({ ); } })} + {isSelectAllVillage && maxLevel === 5 && ( + + + + Select all village + + + + )} ); } diff --git a/frontend/src/pages/mobile-assignment/AddAssignment.jsx b/frontend/src/pages/mobile-assignment/AddAssignment.jsx index 36c532119..b352b4384 100644 --- a/frontend/src/pages/mobile-assignment/AddAssignment.jsx +++ b/frontend/src/pages/mobile-assignment/AddAssignment.jsx @@ -284,6 +284,7 @@ const AddAssignment = () => { }} persist={id ? true : false} allowMultiple + isSelectAllVillage={true} /> From 7799fd863992f365686b0905f2d30cee29ff1d7c Mon Sep 17 00:00:00 2001 From: abhishek Date: Tue, 30 Jan 2024 22:55:05 +0530 Subject: [PATCH 2/5] [#1099] submit issue fixed --- .../src/components/filters/AdministrationDropdown.js | 9 ++++++++- frontend/src/pages/mobile-assignment/AddAssignment.jsx | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/filters/AdministrationDropdown.js b/frontend/src/components/filters/AdministrationDropdown.js index 0c2977eda..830d3bd02 100644 --- a/frontend/src/components/filters/AdministrationDropdown.js +++ b/frontend/src/components/filters/AdministrationDropdown.js @@ -84,10 +84,17 @@ const AdministrationDropdown = ({ store.update((s) => { s.administration = s.administration.concat(admItems); }); + if (onChange) { + const _values = admItems.map((item) => item.id); + onChange(_values); + } } else { store.update((s) => { - s.administration = s.administration.slice(0, 2); + s.administration = s.administration.slice(0, 1); }); + if (onChange) { + onChange(administration.slice(0, 1).map((adm) => adm.id)); + } } }; diff --git a/frontend/src/pages/mobile-assignment/AddAssignment.jsx b/frontend/src/pages/mobile-assignment/AddAssignment.jsx index b352b4384..7ca2a0aed 100644 --- a/frontend/src/pages/mobile-assignment/AddAssignment.jsx +++ b/frontend/src/pages/mobile-assignment/AddAssignment.jsx @@ -155,6 +155,7 @@ const AddAssignment = () => { const fetchData = useCallback(async () => { if (id && preload && editAssignment?.id && selectedAdm) { + console.log(editAssignment, selectedAdm, "editAssignment"); setPreload(false); form.setFieldsValue({ ...editAssignment, From d642d2a0430acefcceca2f144ab2ce6afb333163 Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 31 Jan 2024 09:24:18 +0530 Subject: [PATCH 3/5] [#1099] user submit issue resolved --- frontend/src/components/filters/AdministrationDropdown.js | 8 ++++++-- frontend/src/pages/mobile-assignment/AddAssignment.jsx | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/filters/AdministrationDropdown.js b/frontend/src/components/filters/AdministrationDropdown.js index 830d3bd02..6a0b1499f 100644 --- a/frontend/src/components/filters/AdministrationDropdown.js +++ b/frontend/src/components/filters/AdministrationDropdown.js @@ -90,10 +90,14 @@ const AdministrationDropdown = ({ } } else { store.update((s) => { - s.administration = s.administration.slice(0, 1); + s.administration = s.administration.filter( + (data) => data.level <= lowestLevel.level - 1 + ); }); if (onChange) { - onChange(administration.slice(0, 1).map((adm) => adm.id)); + onChange( + administration.filter((data) => data.level <= lowestLevel.level - 1) + ); } } }; diff --git a/frontend/src/pages/mobile-assignment/AddAssignment.jsx b/frontend/src/pages/mobile-assignment/AddAssignment.jsx index 7ca2a0aed..b352b4384 100644 --- a/frontend/src/pages/mobile-assignment/AddAssignment.jsx +++ b/frontend/src/pages/mobile-assignment/AddAssignment.jsx @@ -155,7 +155,6 @@ const AddAssignment = () => { const fetchData = useCallback(async () => { if (id && preload && editAssignment?.id && selectedAdm) { - console.log(editAssignment, selectedAdm, "editAssignment"); setPreload(false); form.setFieldsValue({ ...editAssignment, From 83144c07b87be0e1e10011a6ab452d0c61c4ff06 Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 31 Jan 2024 12:47:21 +0530 Subject: [PATCH 4/5] [#1091] checkbox checked when already selected all village --- frontend/src/components/filters/AdministrationDropdown.js | 4 ++++ frontend/src/pages/mobile-assignment/AddAssignment.jsx | 1 + 2 files changed, 5 insertions(+) diff --git a/frontend/src/components/filters/AdministrationDropdown.js b/frontend/src/components/filters/AdministrationDropdown.js index 6a0b1499f..526f9aaee 100644 --- a/frontend/src/components/filters/AdministrationDropdown.js +++ b/frontend/src/components/filters/AdministrationDropdown.js @@ -17,6 +17,7 @@ const AdministrationDropdown = ({ onChange, limitLevel = false, isSelectAllVillage = false, + selectedAdministrations = [], ...props }) => { const { user, administration, levels } = store.useState((state) => state); @@ -81,6 +82,9 @@ const AdministrationDropdown = ({ (admLevel) => admLevel.level === lowestLevel.level - 1 )?.children; admItems = multiadministration; + if (selectedAdministrations.length === admItems.length) { + return; + } store.update((s) => { s.administration = s.administration.concat(admItems); }); diff --git a/frontend/src/pages/mobile-assignment/AddAssignment.jsx b/frontend/src/pages/mobile-assignment/AddAssignment.jsx index b352b4384..48e6f6022 100644 --- a/frontend/src/pages/mobile-assignment/AddAssignment.jsx +++ b/frontend/src/pages/mobile-assignment/AddAssignment.jsx @@ -285,6 +285,7 @@ const AddAssignment = () => { persist={id ? true : false} allowMultiple isSelectAllVillage={true} + selectedAdministrations={selectedAdministrations} /> From 9aa3d19fc22cc62fe1d0c4264d91720775b4ca9c Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 31 Jan 2024 13:21:38 +0530 Subject: [PATCH 5/5] [#1099] checkbox auto checked done --- .../components/filters/AdministrationDropdown.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/filters/AdministrationDropdown.js b/frontend/src/components/filters/AdministrationDropdown.js index 526f9aaee..28aa5ed25 100644 --- a/frontend/src/components/filters/AdministrationDropdown.js +++ b/frontend/src/components/filters/AdministrationDropdown.js @@ -1,4 +1,4 @@ -import React, { useEffect } from "react"; +import React, { useEffect, useState } from "react"; import "./style.scss"; import { Select, Space, Checkbox, Row, Col } from "antd"; import PropTypes from "prop-types"; @@ -21,6 +21,7 @@ const AdministrationDropdown = ({ ...props }) => { const { user, administration, levels } = store.useState((state) => state); + const [checked, setChecked] = useState(false); /** * Get lowest level administrator from maxLevel. * otherwise, sort asc by level and get the last item from levels global state @@ -51,6 +52,15 @@ const AdministrationDropdown = ({ fetchUserAdmin(); }, [fetchUserAdmin, persist]); + useEffect(() => { + const multiadministration = administration?.find( + (admLevel) => admLevel.level === lowestLevel.level - 1 + )?.children; + if (multiadministration?.length === selectedAdministrations?.length) { + setChecked(true); + } + }, [administration, selectedAdministrations, lowestLevel.level]); + const handleChange = async (e, index) => { if (!e) { return; @@ -77,6 +87,7 @@ const AdministrationDropdown = ({ const handleSelectAllVillage = (e) => { if (e.target.checked) { + setChecked(true); let admItems = null; const multiadministration = administration?.find( (admLevel) => admLevel.level === lowestLevel.level - 1 @@ -93,6 +104,7 @@ const AdministrationDropdown = ({ onChange(_values); } } else { + setChecked(false); store.update((s) => { s.administration = s.administration.filter( (data) => data.level <= lowestLevel.level - 1 @@ -187,7 +199,7 @@ const AdministrationDropdown = ({ {isSelectAllVillage && maxLevel === 5 && ( - + Select all village