From d676dc22348840a11ff30ed600f16d556cc27ee3 Mon Sep 17 00:00:00 2001 From: KaWaite <34051327+KaWaite@users.noreply.github.com> Date: Fri, 30 Jun 2023 15:23:32 +0900 Subject: [PATCH] fix(web): workspace or userId being undefined (#527) --- .../organisms/Authentication/RootPage/hooks.ts | 2 ++ .../components/organisms/EarthEditor/Header/hooks.ts | 12 +++++++++++- .../classic/components/pages/Authentication/hooks.ts | 11 ++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/web/src/classic/components/organisms/Authentication/RootPage/hooks.ts b/web/src/classic/components/organisms/Authentication/RootPage/hooks.ts index 4ce92fdc60..26b887eeec 100644 --- a/web/src/classic/components/organisms/Authentication/RootPage/hooks.ts +++ b/web/src/classic/components/organisms/Authentication/RootPage/hooks.ts @@ -65,6 +65,7 @@ export default () => { login(); } else { if (currentWorkspace || !data || !workspaceId) return; + setCurrentUserId(data?.me?.id); setCurrentWorkspace(data.me?.myTeam); navigate(`/dashboard/${workspaceId}`); } @@ -79,6 +80,7 @@ export default () => { login, verifySignup, navigate, + setCurrentUserId, setCurrentWorkspace, ]); diff --git a/web/src/classic/components/organisms/EarthEditor/Header/hooks.ts b/web/src/classic/components/organisms/EarthEditor/Header/hooks.ts index 3fdcb884e4..5c7145dd7f 100644 --- a/web/src/classic/components/organisms/EarthEditor/Header/hooks.ts +++ b/web/src/classic/components/organisms/EarthEditor/Header/hooks.ts @@ -47,7 +47,17 @@ export default () => { skip: !sceneId, }); - const workspaceId = data?.node?.__typename === "Scene" ? data.node.teamId : undefined; + const workspaceId = useMemo( + () => (data?.node?.__typename === "Scene" ? data.node.teamId : undefined), + [data?.node], + ); + + useEffect(() => { + if (!currentWorkspace) { + setCurrentWorkspace(workspaces?.find(w => w.id === workspaceId)); + } + }, [workspaces, workspaceId, currentWorkspace, setCurrentWorkspace]); + const project = useMemo( () => data?.node?.__typename === "Scene" && data.node.project diff --git a/web/src/classic/components/pages/Authentication/hooks.ts b/web/src/classic/components/pages/Authentication/hooks.ts index 4cd839b3d2..5f24a98e92 100644 --- a/web/src/classic/components/pages/Authentication/hooks.ts +++ b/web/src/classic/components/pages/Authentication/hooks.ts @@ -37,8 +37,17 @@ export default () => { useEffect(() => { if (!isAuthenticated || currentWorkspace || !data || !workspaceId) return; + setCurrentUserId(data?.me?.id); setCurrentWorkspace(data.me?.myTeam); - }, [isAuthenticated, navigate, data, workspaceId, currentWorkspace, setCurrentWorkspace]); + }, [ + isAuthenticated, + navigate, + data, + workspaceId, + currentWorkspace, + setCurrentUserId, + setCurrentWorkspace, + ]); useEffect(() => { if (authError || (isAuthenticated && !loading && data?.me === null)) {