@@ -26,6 +26,8 @@ const Settings: NextPage = () => {
2626 const [ isOidc , setIsOidc ] = useState ( false ) ;
2727 const [ user , setUser ] = useState < any > ( null ) ;
2828 const [ activeAdminMessages , setActiveAdminMessages ] = useState < AdminMessage [ ] > ( [ ] ) ;
29+ const [ isOidcInvitation , setIsOidcInvitation ] = useState ( false ) ;
30+ const [ backButtonDisabled , setBackButtonDisabled ] = useState ( false ) ;
2931 // Get ?flow=... from the URL
3032 const router = useRouter ( )
3133 const { flow : flowId , return_to : returnTo } = router . query
@@ -104,9 +106,39 @@ const Settings: NextPage = () => {
104106 if ( [ "microsoft" , "google" ] . includes ( initialFlow . identity . metadata_public ?. registration_scope ?. provider_id ) ) {
105107 initialFlow . ui . nodes = initialFlow . ui . nodes . filter ( ( node : UiNode ) => node . group !== "password" ) ;
106108 setIsOidc ( true ) ;
109+ if ( initialFlow . identity . metadata_public ?. registration_scope ?. invitation_sso ) {
110+ setIsOidcInvitation ( true ) ;
111+ }
112+ const provider = initialFlow . identity . metadata_public ?. registration_scope ?. provider_id ;
113+ if ( provider === "google" ) {
114+ console . log ( document . querySelector ( 'button[value="Microsoft"]' ) )
115+ document . querySelector ( 'button[value="Microsoft"]' ) ?. setAttribute ( "class" , "hidden" ) ;
116+ } else if ( provider === "microsoft" ) {
117+ document . querySelector ( 'button[value="Google"]' ) ?. setAttribute ( "class" , "hidden" ) ;
118+ }
107119 }
120+ } , [ initialFlow , changedFlow ] )
108121
109- } , [ initialFlow ] )
122+ useEffect ( ( ) => {
123+ if ( ! changedFlow || ! initialFlow ) return ;
124+ const firstNameButtonVal = ( document . querySelector ( 'input[name="traits.name.first"]' ) as HTMLInputElement ) ?. value ;
125+ const lastNameButtonVal = ( document . querySelector ( 'input[name="traits.name.last"]' ) as HTMLInputElement ) ?. value ;
126+ if ( isOidc && isOidcInvitation ) {
127+ if ( firstNameButtonVal === "" || lastNameButtonVal === "" ) {
128+ setBackButtonDisabled ( true ) ;
129+ } else {
130+ setBackButtonDisabled ( false ) ;
131+ }
132+ } else {
133+ const emailButtonVal = ( document . querySelector ( 'input[name="traits.email"]' ) as HTMLInputElement ) ?. value ;
134+ const passwordButtonVal = ( document . querySelector ( 'input[name="password"]' ) as HTMLInputElement ) ?. value ;
135+ if ( firstNameButtonVal === "" || lastNameButtonVal === "" || emailButtonVal === "" || passwordButtonVal === "" ) {
136+ setBackButtonDisabled ( true ) ;
137+ } else {
138+ setBackButtonDisabled ( false ) ;
139+ }
140+ }
141+ } , [ isOidc , isOidcInvitation , initialFlow , changedFlow ] ) ;
110142
111143 const onSubmit = ( values : UpdateSettingsFlowBody ) =>
112144 ory
@@ -190,8 +222,19 @@ const Settings: NextPage = () => {
190222 />
191223 </ div > ) : ( < > </ > ) }
192224
225+ { isOidc && isOidcInvitation ? ( < div className = "form-container" >
226+ < Flow
227+ hideGlobalMessages
228+ onSubmit = { onSubmit }
229+ only = "oidc"
230+ flow = { changedFlow }
231+ />
232+ </ div > ) : ( < > </ > ) }
233+
193234 < div className = "link-container" >
194- < a className = "link" data-testid = "forgot-password" href = "/cognition" > Back</ a >
235+ < button className = "link disabled:opacity-50 disabled:cursor-not-allowed" data-testid = "forgot-password" disabled = { backButtonDisabled } onClick = { ( ) => {
236+ router . push ( "/cognition" )
237+ } } > Back</ button >
195238 </ div >
196239 </ div >
197240 </ div >
0 commit comments