11import { createRoute , redirect } from '@tanstack/react-router' ;
22
3+ import { checkIAMEnabled } from 'src/features/IAM/hooks/useIsIAMEnabled' ;
4+
35import { rootRoute } from '../root' ;
46import { IAMRoute } from './IAMRoute' ;
57
@@ -18,11 +20,7 @@ const iamRoute = createRoute({
1820 getParentRoute : ( ) => rootRoute ,
1921 validateSearch : ( search : IamUsersSearchParams ) => search ,
2022 path : 'iam' ,
21- } ) . lazy ( ( ) =>
22- import ( 'src/features/IAM/iamLandingLazyRoute' ) . then (
23- ( m ) => m . iamLandingLazyRoute
24- )
25- ) ;
23+ } ) ;
2624
2725const iamCatchAllRoute = createRoute ( {
2826 getParentRoute : ( ) => iamRoute ,
@@ -32,10 +30,7 @@ const iamCatchAllRoute = createRoute({
3230 } ,
3331} ) ;
3432
35- const iamIndexRoute = createRoute ( {
36- beforeLoad : async ( ) => {
37- throw redirect ( { to : '/iam/users' } ) ;
38- } ,
33+ const iamTabsRoute = createRoute ( {
3934 getParentRoute : ( ) => iamRoute ,
4035 path : '/' ,
4136} ) . lazy ( ( ) =>
@@ -45,8 +40,20 @@ const iamIndexRoute = createRoute({
4540) ;
4641
4742const iamUsersRoute = createRoute ( {
48- getParentRoute : ( ) => iamRoute ,
43+ getParentRoute : ( ) => iamTabsRoute ,
4944 path : 'users' ,
45+ beforeLoad : async ( { context } ) => {
46+ const isIAMEnabled = await checkIAMEnabled (
47+ context . queryClient ,
48+ context . flags
49+ ) ;
50+
51+ if ( ! isIAMEnabled ) {
52+ throw redirect ( {
53+ to : '/account/users' ,
54+ } ) ;
55+ }
56+ } ,
5057} ) . lazy ( ( ) =>
5158 import ( 'src/features/IAM/Users/UsersTable/usersLandingLazyRoute' ) . then (
5259 ( m ) => m . usersLandingLazyRoute
@@ -62,8 +69,20 @@ const iamUsersCatchAllRoute = createRoute({
6269} ) ;
6370
6471const iamRolesRoute = createRoute ( {
65- getParentRoute : ( ) => iamRoute ,
72+ getParentRoute : ( ) => iamTabsRoute ,
6673 path : 'roles' ,
74+ beforeLoad : async ( { context } ) => {
75+ const isIAMEnabled = await checkIAMEnabled (
76+ context . queryClient ,
77+ context . flags
78+ ) ;
79+
80+ if ( ! isIAMEnabled ) {
81+ throw redirect ( {
82+ to : '/account/users' ,
83+ } ) ;
84+ }
85+ } ,
6786} ) . lazy ( ( ) =>
6887 import ( 'src/features/IAM/Roles/rolesLandingLazyRoute' ) . then (
6988 ( m ) => m . rolesLandingLazyRoute
@@ -79,8 +98,8 @@ const iamRolesCatchAllRoute = createRoute({
7998} ) ;
8099
81100const iamUserNameRoute = createRoute ( {
82- getParentRoute : ( ) => rootRoute ,
83- path : 'iam /users/$username' ,
101+ getParentRoute : ( ) => iamRoute ,
102+ path : '/users/$username' ,
84103} ) . lazy ( ( ) =>
85104 import ( 'src/features/IAM/Users/userDetailsLandingLazyRoute' ) . then (
86105 ( m ) => m . userDetailsLandingLazyRoute
@@ -105,6 +124,20 @@ const iamUserNameIndexRoute = createRoute({
105124const iamUserNameDetailsRoute = createRoute ( {
106125 getParentRoute : ( ) => iamUserNameRoute ,
107126 path : 'details' ,
127+ beforeLoad : async ( { context, params } ) => {
128+ const isIAMEnabled = await checkIAMEnabled (
129+ context . queryClient ,
130+ context . flags
131+ ) ;
132+ const { username } = params ;
133+
134+ if ( ! isIAMEnabled && username ) {
135+ throw redirect ( {
136+ to : '/account/users/$username/profile' ,
137+ params : { username } ,
138+ } ) ;
139+ }
140+ } ,
108141} ) . lazy ( ( ) =>
109142 import ( 'src/features/IAM/Users/UserDetails/userProfileLazyRoute' ) . then (
110143 ( m ) => m . userProfileLazyRoute
@@ -114,6 +147,20 @@ const iamUserNameDetailsRoute = createRoute({
114147const iamUserNameRolesRoute = createRoute ( {
115148 getParentRoute : ( ) => iamUserNameRoute ,
116149 path : 'roles' ,
150+ beforeLoad : async ( { context, params } ) => {
151+ const isIAMEnabled = await checkIAMEnabled (
152+ context . queryClient ,
153+ context . flags
154+ ) ;
155+ const { username } = params ;
156+
157+ if ( ! isIAMEnabled && username ) {
158+ throw redirect ( {
159+ to : '/account/users/$username/permissions' ,
160+ params : { username } ,
161+ } ) ;
162+ }
163+ } ,
117164} ) . lazy ( ( ) =>
118165 import ( 'src/features/IAM/Users/UserRoles/userRolesLazyRoute' ) . then (
119166 ( m ) => m . userRolesLazyRoute
@@ -124,6 +171,20 @@ const iamUserNameEntitiesRoute = createRoute({
124171 getParentRoute : ( ) => iamUserNameRoute ,
125172 path : 'entities' ,
126173 validateSearch : ( search : IamEntitiesSearchParams ) => search ,
174+ beforeLoad : async ( { context, params } ) => {
175+ const isIAMEnabled = await checkIAMEnabled (
176+ context . queryClient ,
177+ context . flags
178+ ) ;
179+ const { username } = params ;
180+
181+ if ( ! isIAMEnabled && username ) {
182+ throw redirect ( {
183+ to : '/account/users/$username' ,
184+ params : { username } ,
185+ } ) ;
186+ }
187+ } ,
127188} ) . lazy ( ( ) =>
128189 import ( 'src/features/IAM/Users/UserEntities/userEntitiesLazyRoute' ) . then (
129190 ( m ) => m . userEntitiesLazyRoute
@@ -178,12 +239,13 @@ const iamUserNameEntitiesCatchAllRoute = createRoute({
178239} ) ;
179240
180241export const iamRouteTree = iamRoute . addChildren ( [
181- iamIndexRoute ,
182- iamRolesRoute ,
183- iamUsersRoute ,
242+ iamTabsRoute . addChildren ( [
243+ iamRolesRoute ,
244+ iamUsersRoute ,
245+ iamUsersCatchAllRoute ,
246+ iamRolesCatchAllRoute ,
247+ ] ) ,
184248 iamCatchAllRoute ,
185- iamUsersCatchAllRoute ,
186- iamRolesCatchAllRoute ,
187249 iamUserNameRoute . addChildren ( [
188250 iamUserNameIndexRoute ,
189251 iamUserNameDetailsRoute ,
0 commit comments