fix privilege movements
This commit is contained in:
parent
8a1d12a218
commit
f47a919b03
@ -58,7 +58,7 @@ const PrivilegeEditor = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setAvailablePrivileges(
|
setAvailablePrivileges(
|
||||||
(data || []).filter(
|
(data || []).filter(
|
||||||
({ id }) => !(user.privileges || []).some((privvy) => privvy.id === id)
|
({ id }) => !(userPrivvy || []).some((privvy) => privvy.id === id)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}, [user, data, userPrivvy]);
|
}, [user, data, userPrivvy]);
|
||||||
@ -91,9 +91,10 @@ const PrivilegeEditor = ({
|
|||||||
const toAdd = availablePrivileges.filter(({ id }) =>
|
const toAdd = availablePrivileges.filter(({ id }) =>
|
||||||
selectionAvailable.includes(id.toString())
|
selectionAvailable.includes(id.toString())
|
||||||
);
|
);
|
||||||
setUserPrivvy([...(userPrivvy || []), ...toAdd]);
|
const changed = [...(userPrivvy || []), ...toAdd];
|
||||||
|
setUserPrivvy(changed);
|
||||||
setSelectionAvailable([]);
|
setSelectionAvailable([]);
|
||||||
onChange(userPrivvy);
|
onChange(changed);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
>>
|
>>
|
||||||
@ -103,13 +104,12 @@ const PrivilegeEditor = ({
|
|||||||
disabled={!selectionExisting.length}
|
disabled={!selectionExisting.length}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
// Remove privileges
|
// Remove privileges
|
||||||
onChange(userPrivvy);
|
const removed = (userPrivvy || []).filter(
|
||||||
setSelectionExisting([]);
|
|
||||||
setUserPrivvy(
|
|
||||||
(userPrivvy || []).filter(
|
|
||||||
({ id }) => !selectionExisting.includes(id.toString())
|
({ id }) => !selectionExisting.includes(id.toString())
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
setSelectionExisting([]);
|
||||||
|
onChange(removed);
|
||||||
|
setUserPrivvy(removed);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<<
|
<<
|
||||||
@ -122,7 +122,7 @@ const PrivilegeEditor = ({
|
|||||||
value={selectionExisting}
|
value={selectionExisting}
|
||||||
onChange={(e) => setSelectionExisting(getSelectValues(e.target))}
|
onChange={(e) => setSelectionExisting(getSelectValues(e.target))}
|
||||||
>
|
>
|
||||||
{(user.privileges || []).map(({ name, id }) => (
|
{(userPrivvy || []).map(({ name, id }) => (
|
||||||
<option value={id} key={id}>
|
<option value={id} key={id}>
|
||||||
{name}
|
{name}
|
||||||
</option>
|
</option>
|
||||||
|
Reference in New Issue
Block a user