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: "",