fix privilege movements

This commit is contained in:
Evert Prants 2022-09-11 12:53:48 +03:00
parent 8a1d12a218
commit f47a919b03
Signed by: evert
GPG Key ID: 1688DA83D222D0B5

View File

@ -58,7 +58,7 @@ const PrivilegeEditor = ({
useEffect(() => {
setAvailablePrivileges(
(data || []).filter(
({ id }) => !(user.privileges || []).some((privvy) => privvy.id === id)
({ id }) => !(userPrivvy || []).some((privvy) => privvy.id === id)
)
);
}, [user, data, userPrivvy]);
@ -91,9 +91,10 @@ const PrivilegeEditor = ({
const toAdd = availablePrivileges.filter(({ id }) =>
selectionAvailable.includes(id.toString())
);
setUserPrivvy([...(userPrivvy || []), ...toAdd]);
const changed = [...(userPrivvy || []), ...toAdd];
setUserPrivvy(changed);
setSelectionAvailable([]);
onChange(userPrivvy);
onChange(changed);
}}
>
>>
@ -103,13 +104,12 @@ const PrivilegeEditor = ({
disabled={!selectionExisting.length}
onClick={() => {
// Remove privileges
onChange(userPrivvy);
setSelectionExisting([]);
setUserPrivvy(
(userPrivvy || []).filter(
const removed = (userPrivvy || []).filter(
({ id }) => !selectionExisting.includes(id.toString())
)
);
setSelectionExisting([]);
onChange(removed);
setUserPrivvy(removed);
}}
>
<<
@ -122,7 +122,7 @@ const PrivilegeEditor = ({
value={selectionExisting}
onChange={(e) => setSelectionExisting(getSelectValues(e.target))}
>
{(user.privileges || []).map(({ name, id }) => (
{(userPrivvy || []).map(({ name, id }) => (
<option value={id} key={id}>
{name}
</option>