@@ -26,6 +26,9 @@ const Settings: NextPage = () => {
26
26
const [ isOidc , setIsOidc ] = useState ( false ) ;
27
27
const [ user , setUser ] = useState < any > ( null ) ;
28
28
const [ activeAdminMessages , setActiveAdminMessages ] = useState < AdminMessage [ ] > ( [ ] ) ;
29
+ const [ isOidcInvitation , setIsOidcInvitation ] = useState ( false ) ;
30
+ const [ backButtonDisabled , setBackButtonDisabled ] = useState ( false ) ;
31
+ const [ messages , setMessages ] = useState < any > ( null ) ;
29
32
// Get ?flow=... from the URL
30
33
const router = useRouter ( )
31
34
const { flow : flowId , return_to : returnTo } = router . query
@@ -101,12 +104,50 @@ const Settings: NextPage = () => {
101
104
setChangedFlow ( initialFlow )
102
105
103
106
//prevent password change option display if sso
104
- if ( [ "microsoft" , "google" ] . includes ( initialFlow . identity . metadata_public ?. registration_scope ?. provider_id ) ) {
105
- initialFlow . ui . nodes = initialFlow . ui . nodes . filter ( ( node : UiNode ) => node . group !== "password" ) ;
106
- setIsOidc ( true ) ;
107
+ requestAnimationFrame ( ( ) => {
108
+ if ( [ "microsoft" , "google" ] . includes ( initialFlow . identity . metadata_public ?. registration_scope ?. provider_id ) ) {
109
+ initialFlow . ui . nodes = initialFlow . ui . nodes . filter ( ( node : UiNode ) => node . group !== "password" ) ;
110
+ setIsOidc ( true ) ;
111
+ if ( initialFlow . identity . metadata_public ?. registration_scope ?. invitation_sso ) {
112
+ setIsOidcInvitation ( true ) ;
113
+ }
114
+ const provider = initialFlow . identity . metadata_public ?. registration_scope ?. provider_id ;
115
+ if ( provider === "google" ) {
116
+ document . querySelector ( 'button[value="Microsoft"]' ) ?. setAttribute ( "class" , "hidden" ) ;
117
+ } else if ( provider === "microsoft" ) {
118
+ document . querySelector ( 'button[value="Google"]' ) ?. setAttribute ( "class" , "hidden" ) ;
119
+ }
120
+ }
121
+ } ) ;
122
+ } , [ initialFlow ] )
123
+
124
+ useEffect ( ( ) => {
125
+ if ( ! changedFlow || ! initialFlow ) return ;
126
+ const firstNameButtonVal = ( document . querySelector ( 'input[name="traits.name.first"]' ) as HTMLInputElement ) ?. value ;
127
+ const lastNameButtonVal = ( document . querySelector ( 'input[name="traits.name.last"]' ) as HTMLInputElement ) ?. value ;
128
+ if ( isOidc && isOidcInvitation ) {
129
+ if ( firstNameButtonVal === "" || lastNameButtonVal === "" ) {
130
+ setBackButtonDisabled ( true ) ;
131
+ } else {
132
+ setBackButtonDisabled ( false ) ;
133
+ }
134
+ } else {
135
+ const emailButtonVal = ( document . querySelector ( 'input[name="traits.email"]' ) as HTMLInputElement ) ?. value ;
136
+ const passwordButtonVal = ( document . querySelector ( 'input[name="password"]' ) as HTMLInputElement ) ?. value ;
137
+ if ( firstNameButtonVal === "" || lastNameButtonVal === "" || emailButtonVal === "" || passwordButtonVal === "" ) {
138
+ setBackButtonDisabled ( true ) ;
139
+ } else {
140
+ setBackButtonDisabled ( false ) ;
141
+ }
107
142
}
143
+ } , [ isOidc , isOidcInvitation , initialFlow , changedFlow ] ) ;
108
144
109
- } , [ initialFlow ] )
145
+ useEffect ( ( ) => {
146
+ if ( ! changedFlow ) return ;
147
+ if ( changedFlow . ui . messages ) {
148
+ setMessages ( changedFlow . ui . messages ) ;
149
+ }
150
+ } , [ changedFlow ] )
110
151
111
152
const onSubmit = ( values : UpdateSettingsFlowBody ) =>
112
153
ory
@@ -142,8 +183,8 @@ const Settings: NextPage = () => {
142
183
< div id = "settings" >
143
184
< h2 className = "title" > Profile management and security settings</ h2 >
144
185
< div className = "form-container" >
186
+ < Messages messages = { messages } />
145
187
< h3 className = "subtitle" > Profile Settings</ h3 >
146
- < Messages messages = { changedFlow ?. ui . messages } />
147
188
< Flow
148
189
hideGlobalMessages
149
190
onSubmit = { onSubmit }
@@ -153,8 +194,7 @@ const Settings: NextPage = () => {
153
194
</ div >
154
195
{ ! isOidc ?
155
196
< div className = "form-container" >
156
- < h3 className = "subtitle" > Change password</ h3 >
157
- < Messages messages = { changedFlow ?. ui . messages } />
197
+ < h3 className = "subtitle" > { flowId ? 'Set' : 'Change' } password</ h3 >
158
198
< Flow
159
199
hideGlobalMessages
160
200
onSubmit = { onSubmit }
@@ -166,7 +206,6 @@ const Settings: NextPage = () => {
166
206
{ containsBackupCodes ? ( < div className = "form-container" >
167
207
< h3 className = "subtitle" > Manage 2FA backup recovery codes</ h3 >
168
208
< p > Recovery codes can be used in panic situations where you have lost access to your 2FA device.</ p >
169
- < Messages messages = { changedFlow ?. ui . messages } />
170
209
< Flow
171
210
hideGlobalMessages
172
211
onSubmit = { onSubmit }
@@ -184,7 +223,6 @@ const Settings: NextPage = () => {
184
223
href = "https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2& hl = en & gl = US "
185
224
target = "_blank" > Android</ a > ).
186
225
</ p >
187
- < Messages messages = { changedFlow ?. ui . messages } />
188
226
< Flow
189
227
hideGlobalMessages
190
228
onSubmit = { onSubmit }
@@ -193,8 +231,19 @@ const Settings: NextPage = () => {
193
231
/>
194
232
</ div > ) : ( < > </ > ) }
195
233
234
+ { isOidc && isOidcInvitation ? ( < div className = "form-container" >
235
+ < Flow
236
+ hideGlobalMessages
237
+ onSubmit = { onSubmit }
238
+ only = "oidc"
239
+ flow = { changedFlow }
240
+ />
241
+ </ div > ) : ( < > </ > ) }
242
+
196
243
< div className = "link-container" >
197
- < a className = "link" data-testid = "forgot-password" href = "/cognition" > Back</ a >
244
+ < button className = "link disabled:opacity-50 disabled:cursor-not-allowed" data-testid = "forgot-password" disabled = { backButtonDisabled } onClick = { ( ) => {
245
+ router . push ( "/cognition" )
246
+ } } > Back</ button >
198
247
</ div >
199
248
</ div >
200
249
</ div >
0 commit comments