From 795b0a8de2821ac7a07d09bb857365c1fe011707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Tue, 10 Feb 2026 18:12:20 +0400 Subject: [PATCH] Remove useAssume from layouts now that we have the /assume page that redirects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Émile Ré --- .../src/components/OrganizationErrorBoundary.tsx | 2 +- .../console/src/components/RootErrorBoundary.tsx | 4 +++- apps/console/src/hooks/iam/useAssume.ts | 4 ++-- .../ViewerMembershipLayoutLoader.tsx | 16 ++++------------ .../employee/EmployeeLayoutLoader.tsx | 16 ++++------------ apps/console/src/routes.tsx | 3 ++- 6 files changed, 16 insertions(+), 29 deletions(-) diff --git a/apps/console/src/components/OrganizationErrorBoundary.tsx b/apps/console/src/components/OrganizationErrorBoundary.tsx index 765f73ed4..ad79cc3b5 100644 --- a/apps/console/src/components/OrganizationErrorBoundary.tsx +++ b/apps/console/src/components/OrganizationErrorBoundary.tsx @@ -11,7 +11,7 @@ export function OrganizationErrorBoundary() { const search = new URLSearchParams([ ["organization-id", organizationId], - ["redirect-path", window.location.href], + ["redirect-path", window.location.pathname + window.location.search], ]); if (error instanceof UnAuthenticatedError) { diff --git a/apps/console/src/components/RootErrorBoundary.tsx b/apps/console/src/components/RootErrorBoundary.tsx index fc34d0cd1..77fcbcbde 100644 --- a/apps/console/src/components/RootErrorBoundary.tsx +++ b/apps/console/src/components/RootErrorBoundary.tsx @@ -6,7 +6,9 @@ import { PageError } from "./PageError"; export function RootErrorBoundary() { const error = useRouteError(); - const search = new URLSearchParams([["redirect-path", window.location.href]]); + const search = new URLSearchParams([ + ["redirect-path", window.location.pathname + window.location.search], + ]); if (error instanceof UnAuthenticatedError) { return ; diff --git a/apps/console/src/hooks/iam/useAssume.ts b/apps/console/src/hooks/iam/useAssume.ts index 130682c7b..4293914b4 100644 --- a/apps/console/src/hooks/iam/useAssume.ts +++ b/apps/console/src/hooks/iam/useAssume.ts @@ -58,7 +58,7 @@ export function useAssume(params: UseAssumeParameters) { if (error instanceof UnAuthenticatedError) { const search = new URLSearchParams([ ["organization-id", organizationId], - ["redirect-path", afterAssumePath ?? window.location.href], + ["redirect-path", afterAssumePath ?? window.location.pathname + window.location.search], ]); void navigate({ pathname: "/auth/login", search: "?" + search.toString() }); @@ -76,7 +76,7 @@ export function useAssume(params: UseAssumeParameters) { switch (result.__typename) { case "PasswordRequired": search.set("organization-id", organizationId); - search.set("redirect-path", afterAssumePath ?? window.location.href); + search.set("redirect-path", afterAssumePath ?? window.location.pathname + window.location.search); void navigate({ pathname: "/auth/passord-login", search: "?" + search.toString() }); break; diff --git a/apps/console/src/pages/iam/organizations/ViewerMembershipLayoutLoader.tsx b/apps/console/src/pages/iam/organizations/ViewerMembershipLayoutLoader.tsx index 16eb3d155..4d1fd216c 100644 --- a/apps/console/src/pages/iam/organizations/ViewerMembershipLayoutLoader.tsx +++ b/apps/console/src/pages/iam/organizations/ViewerMembershipLayoutLoader.tsx @@ -1,9 +1,8 @@ import { Skeleton } from "@probo/ui"; -import { Suspense, useCallback } from "react"; +import { Suspense, useEffect } from "react"; import { useQueryLoader } from "react-relay"; import type { ViewerMembershipLayoutQuery } from "#/__generated__/iam/ViewerMembershipLayoutQuery.graphql"; -import { useAssume } from "#/hooks/iam/useAssume"; import { useOrganizationId } from "#/hooks/useOrganizationId"; import { IAMRelayProvider } from "#/providers/IAMRelayProvider"; @@ -19,16 +18,9 @@ function ViewerMembershipLayoutQueryLoader() { viewerMembershipLayoutQuery, ); - const onAssumeSuccess = useCallback( - () => - loadQuery({ - organizationId, - hideSidebar: false, - }), - [loadQuery, organizationId], - ); - - useAssume({ onSuccess: onAssumeSuccess }); + useEffect(() => { + loadQuery({ organizationId, hideSidebar: false }); + }, [organizationId, loadQuery]); if (!queryRef) { return ; diff --git a/apps/console/src/pages/organizations/employee/EmployeeLayoutLoader.tsx b/apps/console/src/pages/organizations/employee/EmployeeLayoutLoader.tsx index b23446765..d6675eb97 100644 --- a/apps/console/src/pages/organizations/employee/EmployeeLayoutLoader.tsx +++ b/apps/console/src/pages/organizations/employee/EmployeeLayoutLoader.tsx @@ -1,9 +1,8 @@ import { Skeleton } from "@probo/ui"; -import { Suspense, useCallback } from "react"; +import { Suspense, useEffect } from "react"; import { useQueryLoader } from "react-relay"; import type { ViewerMembershipLayoutQuery } from "#/__generated__/iam/ViewerMembershipLayoutQuery.graphql"; -import { useAssume } from "#/hooks/iam/useAssume"; import { useOrganizationId } from "#/hooks/useOrganizationId"; import { IAMRelayProvider } from "#/providers/IAMRelayProvider"; @@ -18,16 +17,9 @@ function EmployeeLayoutQueryLoader() { viewerMembershipLayoutQuery, ); - const onAssumeSuccess = useCallback( - () => - loadQuery({ - organizationId, - hideSidebar: false, - }), - [loadQuery, organizationId], - ); - - useAssume({ onSuccess: onAssumeSuccess }); + useEffect(() => { + loadQuery({ organizationId, hideSidebar: true }); + }, [organizationId, loadQuery]); if (!queryRef) { return ; diff --git a/apps/console/src/routes.tsx b/apps/console/src/routes.tsx index c801b9a05..3c3f88f73 100644 --- a/apps/console/src/routes.tsx +++ b/apps/console/src/routes.tsx @@ -122,7 +122,6 @@ const routes = [ }, { path: "/organizations/:organizationId", - ErrorBoundary: OrganizationErrorBoundary, children: [ { path: "assume", @@ -130,6 +129,7 @@ const routes = [ }, { path: "employee", + ErrorBoundary: OrganizationErrorBoundary, Component: lazy( () => import("./pages/organizations/employee/EmployeeLayoutLoader"), ), @@ -154,6 +154,7 @@ const routes = [ Component: lazy( () => import("./pages/iam/organizations/ViewerMembershipLayoutLoader"), ), + ErrorBoundary: OrganizationErrorBoundary, children: [ { path: "",