From f0295c74809df1325d4469bdd225b093b7603a32 Mon Sep 17 00:00:00 2001 From: csawatzky Date: Thu, 15 May 2025 15:19:46 -0600 Subject: [PATCH] changing the use effect to make the call to the dispatch to change as to view as the user but is recording who they were viewing as, if they close without selecting an abject it will restore the previous team to the dispatch --- src/user/AccessObject.tsx | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) 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">