From f47a919b0369379c5fdd482fb325db1e6bd54277 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Sun, 11 Sep 2022 12:53:48 +0300 Subject: [PATCH] fix privilege movements --- components/UsersPage/UsersPage.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 }) => (