99 SettingsSectionHeader ,
1010 SettingsSectionTitle
1111} from "@app/components/Settings" ;
12- import { StrategySelect } from "@app/components/StrategySelect" ;
12+ import { StrategyOption , StrategySelect } from "@app/components/StrategySelect" ;
1313import HeaderTitle from "@app/components/SettingsSectionTitle" ;
1414import { Button } from "@app/components/ui/button" ;
1515import { useParams , useRouter } from "next/navigation" ;
@@ -45,15 +45,10 @@ import { createApiClient } from "@app/lib/api";
4545import { Checkbox } from "@app/components/ui/checkbox" ;
4646import { ListIdpsResponse } from "@server/routers/idp" ;
4747import { useTranslations } from "next-intl" ;
48+ import { build } from "@server/build" ;
4849
4950type UserType = "internal" | "oidc" ;
5051
51- interface UserTypeOption {
52- id : UserType ;
53- title : string ;
54- description : string ;
55- }
56-
5752interface IdpOption {
5853 idpId : number ;
5954 name : string ;
@@ -147,13 +142,20 @@ export default function Page() {
147142 }
148143 } , [ userType , env . email . emailEnabled , internalForm , externalForm ] ) ;
149144
150- const userTypes : UserTypeOption [ ] = [
145+ const [ userTypes , setUserTypes ] = useState < StrategyOption < string > [ ] > ( [
151146 {
152147 id : "internal" ,
153148 title : t ( "userTypeInternal" ) ,
154- description : t ( "userTypeInternalDescription" )
149+ description : t ( "userTypeInternalDescription" ) ,
150+ disabled : false
151+ } ,
152+ {
153+ id : "oidc" ,
154+ title : t ( "userTypeExternal" ) ,
155+ description : t ( "userTypeExternalDescription" ) ,
156+ disabled : true
155157 }
156- ] ;
158+ ] ) ;
157159
158160 useEffect ( ( ) => {
159161 if ( ! userType ) {
@@ -177,9 +179,6 @@ export default function Page() {
177179
178180 if ( res ?. status === 200 ) {
179181 setRoles ( res . data . data . roles ) ;
180- if ( userType === "internal" ) {
181- setDataLoaded ( true ) ;
182- }
183182 }
184183 }
185184
@@ -200,24 +199,32 @@ export default function Page() {
200199
201200 if ( res ?. status === 200 ) {
202201 setIdps ( res . data . data . idps ) ;
203- setDataLoaded ( true ) ;
204202
205203 if ( res . data . data . idps . length ) {
206- userTypes . push ( {
207- id : "oidc" ,
208- title : t ( "userTypeExternal" ) ,
209- description : t ( "userTypeExternalDescription" )
210- } ) ;
204+ setUserTypes ( ( prev ) =>
205+ prev . map ( ( type ) => {
206+ if ( type . id === "oidc" ) {
207+ return {
208+ ...type ,
209+ disabled : false
210+ } ;
211+ }
212+ return type ;
213+ } )
214+ ) ;
211215 }
212216 }
213217 }
214218
215- setDataLoaded ( false ) ;
216- fetchRoles ( ) ;
217- if ( userType !== "internal" ) {
218- fetchIdps ( ) ;
219+ async function fetchInitialData ( ) {
220+ setDataLoaded ( false ) ;
221+ await fetchRoles ( ) ;
222+ await fetchIdps ( ) ;
223+ setDataLoaded ( true ) ;
219224 }
220- } , [ userType ] ) ;
225+
226+ fetchInitialData ( ) ;
227+ } , [ ] ) ;
221228
222229 async function onSubmitInternal (
223230 values : z . infer < typeof internalFormSchema >
@@ -323,7 +330,7 @@ export default function Page() {
323330
324331 < div >
325332 < SettingsContainer >
326- { ! inviteLink && userTypes . length > 1 ? (
333+ { ! inviteLink && build !== "saas" ? (
327334 < SettingsSection >
328335 < SettingsSectionHeader >
329336 < SettingsSectionTitle >
@@ -610,7 +617,7 @@ export default function Page() {
610617 idp || null
611618 ) ;
612619 } }
613- cols = { 3 }
620+ cols = { 2 }
614621 />
615622 < FormMessage />
616623 </ FormItem >
0 commit comments