Skip to content

Commit

Permalink
Merge pull request #1081 from akvo/feature/1079-administrative-access…
Browse files Browse the repository at this point in the history
…-level

[#1079] Update edit assignment
  • Loading branch information
dedenbangkit authored Jan 25, 2024
2 parents f5802b6 + 66247ff commit 54cda70
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions frontend/src/pages/mobile-assignment/AddAssignment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,12 @@ const AddAssignment = () => {
});
};

const onSelectLevel = async (val) => {
const onSelectLevel = async (val, option) => {
store.update((s) => {
s.administration.length = val;
s.administration = selectedAdm.filter(
(item) => item.level < option.level
);
});
setLevel(val);
};
Expand Down Expand Up @@ -180,21 +183,25 @@ const AddAssignment = () => {
})
);
store.update((s) => {
s.administration = [...parentAdm, ...selectedAdministration]?.map(
(a, ax) => {
const childLevel = levels.filter((l) => l?.level === ax + 1);
s.administration = [...parentAdm, ...selectedAdministration]
?.slice(
[...parentAdm, ...selectedAdministration].findIndex(
(r) => r.id === authUser.administration.id
)
)
.map((a) => {
const childLevel = levels.filter((l) => l?.level === a.level);
return {
...a,
childLevelName: childLevel?.name || null,
};
}
);
});
});
}
if (!id && preload) {
setPreload(false);
}
}, [id, preload, form, editAssignment, levels, selectedAdm]);
}, [id, preload, form, editAssignment, levels, selectedAdm, authUser]);

useEffect(() => {
fetchData();
Expand Down Expand Up @@ -251,7 +258,7 @@ const AddAssignment = () => {
getPopupContainer={(trigger) => trigger.parentNode}
placeholder={text.selectLevel}
onChange={onSelectLevel}
fieldNames={{ value: "id", label: "name" }}
fieldNames={{ value: "id", label: "name", level: "level" }}
options={admLevels}
allowClear
/>
Expand Down

0 comments on commit 54cda70

Please sign in to comment.