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
This commit is contained in:
parent
a7ed8ccb21
commit
f0295c7480
1 changed files with 25 additions and 14 deletions
|
|
@ -73,13 +73,19 @@ export default function AccessObject(props: Props) {
|
|||
const [teamsTotal, setTeamsTotal] = useState<number>(0);
|
||||
const [devicesOffset, setDevicesOffset] = useState<number>(0);
|
||||
const [devicesTotal, setDevicesTotal] = useState<number>(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
|
||||
|
|
@ -97,7 +103,6 @@ export default function AccessObject(props: Props) {
|
|||
.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 (
|
||||
<ResponsiveDialog
|
||||
open={isOpen}
|
||||
onClose={close}
|
||||
onClose={() => close(true)}
|
||||
aria-labelledby="access-object-dialog"
|
||||
fullScreen>
|
||||
<AppBar position="sticky">
|
||||
<Toolbar>
|
||||
<IconButton edge="start" color="inherit" onClick={close} aria-label="close">
|
||||
<IconButton edge="start" color="inherit" onClick={() => close(true)} aria-label="close">
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
<Typography variant="h6" noWrap>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue