fix privilege movements
This commit is contained in:
parent
8a1d12a218
commit
f47a919b03
@ -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>
|
||||
|
Reference in New Issue
Block a user