diff --git a/frontend/src/lib/__test__/__snapshots__/ui-text.test.js.snap b/frontend/src/lib/__test__/__snapshots__/ui-text.test.js.snap index 7fc90d5c0..14eb2bd7c 100644 --- a/frontend/src/lib/__test__/__snapshots__/ui-text.test.js.snap +++ b/frontend/src/lib/__test__/__snapshots__/ui-text.test.js.snap @@ -218,16 +218,17 @@ Object { "mdPanelTitle": "Master Data", "minute": "Minute", "mobileAddText": "Add Assignment", - "mobileAdmRequired": "Please select one or more villages", + "mobileAdmRequired": "Administration is required: one or multiple", "mobileButtonAdd": "Add new data collector", "mobileButtonSave": "Save", "mobileConfirmDeletion": "Are you sure?", "mobileEditText": "Edit Assignment", - "mobileFormsRequired": "Please select one or more forms", + "mobileFormsRequired": "Form is required: one or multiple", "mobileLabelAdm": "Administrations", "mobileLabelForms": "Forms", "mobileLabelName": "Name", - "mobileNameRequired": "Please input name", + "mobileLevelRequired": "Level is required", + "mobileNameRequired": "Name is required", "mobilePanelAddDesc": "This page allows you to add mobile data collectors to the RUSH platform.", "mobilePanelButton": "Manage Data Collectors", "mobilePanelEditDesc": "This page allows you to edit mobile data collectors to the RUSH platform.", @@ -246,7 +247,7 @@ Object { , "mobilePanelTitle": "Mobile Data Collectors", - "mobileSelectAdm": "Select village...", + "mobileSelectAdm": "Select administrations...", "mobileSelectForms": "Select forms...", "month": "Month", "myProfile": "My Profile", diff --git a/frontend/src/lib/ui-text.js b/frontend/src/lib/ui-text.js index eae2fce8a..a3a812c65 100644 --- a/frontend/src/lib/ui-text.js +++ b/frontend/src/lib/ui-text.js @@ -370,10 +370,11 @@ const uiText = { mobileLabelName: "Name", mobileLabelAdm: "Administrations", mobileLabelForms: "Forms", - mobileNameRequired: "Please input name", - mobileAdmRequired: "Please select one or more villages", - mobileFormsRequired: "Please select one or more forms", - mobileSelectAdm: "Select village...", + mobileNameRequired: "Name is required", + mobileLevelRequired: "Level is required", + mobileAdmRequired: "Administration is required: one or multiple", + mobileFormsRequired: "Form is required: one or multiple", + mobileSelectAdm: "Select administrations...", mobileSelectForms: "Select forms...", mobileConfirmDeletion: "Are you sure?", mobilePanelAddDesc: diff --git a/frontend/src/pages/mobile-assignment/AddAssignment.jsx b/frontend/src/pages/mobile-assignment/AddAssignment.jsx index 5812cb0b3..b23e39048 100644 --- a/frontend/src/pages/mobile-assignment/AddAssignment.jsx +++ b/frontend/src/pages/mobile-assignment/AddAssignment.jsx @@ -12,7 +12,7 @@ import { Modal, } from "antd"; import { useNavigate, useParams } from "react-router-dom"; -import { api, store, uiText } from "../../lib"; +import { api, config, store, uiText } from "../../lib"; import { AdministrationDropdown, Breadcrumbs, @@ -21,7 +21,7 @@ import { import { useNotification } from "../../util/hooks"; import "./style.scss"; -const IS_SUPER_ADMIN = 1; +const IS_SUPER_ADMIN = config.roles.find((x) => x.name === "Super Admin").id; const AddAssignment = () => { const { id } = useParams(); @@ -43,7 +43,7 @@ const AddAssignment = () => { const [level, setLevel] = useState(userAdmLevel); const admLevels = levels - .slice() + .slice(1, levels.length) .filter((l) => l?.level >= userAdmLevel) .sort((a, b) => a?.level - b?.level); const admChildren = selectedAdm @@ -97,6 +97,17 @@ const AddAssignment = () => { }); }; + const onSelectLevel = (val) => { + setLevel(val); + if (selectedAdm.length > 1) { + store.update((s) => { + s.administration = [ + config.fn.administration(authUser.administration.id), + ]; + }); + } + }; + const onFinish = async (values) => { setSubmitting(true); try { @@ -130,12 +141,38 @@ const AddAssignment = () => { administrations: editAssignment.administrations.map((a) => a?.id), forms: editAssignment.forms.map((f) => f?.id), }); + const editAdm = editAssignment?.administrations?.map((a) => + window.dbadm.find((dba) => dba.id === a?.id) + ); + const findLvl = levels.find((l) => l?.level === editAdm?.[0]?.level); + if (findLvl) { + setLevel(findLvl.id); + form.setFieldsValue({ level_id: findLvl.id }); + } + const parentAdm = + editAdm[0]?.path + ?.split(".") + ?.filter((p) => p) + ?.map((pID) => + window.dbadm.find((dba) => dba?.id === parseInt(pID, 10)) + ) || []; + + store.update((s) => { + s.administration = [...parentAdm, ...editAdm]?.map((a, ax) => { + const childLevel = levels.find((l) => l?.level === ax + 1); + return { + ...a, + childLevelName: childLevel?.name || null, + children: window.dbadm.filter((sa) => sa?.parent === a?.id), + }; + }); + }); } if (!id && preload) { setPreload(false); } - }, [id, preload, form, editAssignment]); + }, [id, preload, form, editAssignment, levels]); useEffect(() => { fetchData(); @@ -170,11 +207,20 @@ const AddAssignment = () => { {authUser?.role?.id === IS_SUPER_ADMIN && (
- +