diff --git a/components/UsersPage/UsersPage.tsx b/components/UsersPage/UsersPage.tsx index a2db5fa..1ae7ab4 100644 --- a/components/UsersPage/UsersPage.tsx +++ b/components/UsersPage/UsersPage.tsx @@ -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( - ({ id }) => !selectionExisting.includes(id.toString()) - ) + 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 }) => (