diff --git a/src/user/AccessObject.tsx b/src/user/AccessObject.tsx index d774789..1eba09e 100644 --- a/src/user/AccessObject.tsx +++ b/src/user/AccessObject.tsx @@ -73,31 +73,36 @@ export default function AccessObject(props: Props) { const [teamsTotal, setTeamsTotal] = useState(0); const [devicesOffset, setDevicesOffset] = useState(0); const [devicesTotal, setDevicesTotal] = useState(0); + const [prevAs, setPrevAs] = useState("") - const close = () => { + + const close = (restoreAs?: boolean) => { + if(restoreAs){ + dispatch({ key: "as", value: prevAs }); + } closeDialogCallback(); }; const getAccess = (key: number | string, name: string, url: string, useImitation = false) => { user.settings.useTeam = false; + //dispatch({ key: "as", value: "" }); userAPI.updateUser(user.id(), user.protobuf()).then(() => { info("Will no longer view as team by default"); permissionAPI - .shareObject( - newScope(kind, key.toString()), - user.settings.email, - [ - pond.Permission.PERMISSION_USERS, - pond.Permission.PERMISSION_READ, - pond.Permission.PERMISSION_WRITE, - pond.Permission.PERMISSION_SHARE - ], - useImitation + .shareObject( + newScope(kind, key.toString()), + user.settings.email, + [ + pond.Permission.PERMISSION_USERS, + pond.Permission.PERMISSION_READ, + pond.Permission.PERMISSION_WRITE, + pond.Permission.PERMISSION_SHARE + ], + useImitation ) .then((_response: any) => { // history.push(url); navigate(url) - dispatch({ key: "as", value: "" }); close(); }) .catch((_err: any) => { @@ -258,6 +263,12 @@ export default function AccessObject(props: Props) { useEffect(() => { if (isOpen && (prevSearchValue !== searchValue || prevKind !== kind || isOpen !== prevOpen)) { + //if the user is viewing as a team record who it was + if(as){ + setPrevAs(as) + } + //change as so the user is viewing as themself + dispatch({ key: "as", value: "" }); load(); } }, [ @@ -350,12 +361,12 @@ export default function AccessObject(props: Props) { return ( close(true)} aria-labelledby="access-object-dialog" fullScreen> - + close(true)} aria-label="close">