@@ -18,7 +18,6 @@ import { AdminMessage } from "@/submodules/react-components/types/admin-messages
1818import { postProcessAdminMessages } from "@/submodules/react-components/helpers/admin-messages-helper"
1919import AdminMessages from "@/submodules/react-components/components/AdminMessages"
2020import { useTranslation } from "react-i18next"
21- import { useConsoleLog } from "@/submodules/react-components/hooks/useConsoleLog"
2221
2322const Settings : NextPage = ( ) => {
2423 const [ initialFlow , setInitialFlow ] : any = useState < SettingsFlow > ( )
@@ -39,26 +38,27 @@ const Settings: NextPage = () => {
3938 const [ showPassword , setShowPassword ] = useState < boolean > ( false ) ;
4039 const [ showAuthenticator , setShowAuthenticator ] = useState < boolean > ( false ) ;
4140 const [ loadPage , setLoadPage ] = useState < boolean > ( false ) ;
41+ const [ canShow , setCanShow ] = useState < boolean > ( false ) ;
4242
4343 useEffect ( ( ) => {
44- const onLoad = ( ) => {
45- console . log ( 'All elements including images and external resources are fully loaded.' ) ;
46- setTimeout ( ( ) => { setLoadPage ( true ) ; } , 1000 ) ;
47- } ;
48-
49- if ( document . readyState === 'complete' ) {
50- onLoad ( ) ;
51- } else {
52- window . addEventListener ( 'load' , onLoad ) ;
53- return ( ) => window . removeEventListener ( 'load' , onLoad ) ;
54- }
55- } , [ ] ) ;
56- // useEffect(() => {
57- // if (loadPage) return;
58- // setTimeout(() => {
59- // setLoadPage(true);
60- // }, 1000);
61- // }, [loadPage]);
44+ if ( loadPage ) return ;
45+ setTimeout ( ( ) => {
46+ setLoadPage ( true ) ;
47+ const emailButtonVal = ( document . querySelector ( 'input[name="traits.email"]' ) as HTMLInputElement ) ?. value ;
48+ const firstNameButtonVal = ( document . querySelector ( 'input[name="traits.name.first"]' ) as HTMLInputElement ) ?. value ;
49+ const lastNameButtonVal = ( document . querySelector ( 'input[name="traits.name.last"]' ) as HTMLInputElement ) ?. value ;
50+ if ( firstNameButtonVal !== "" && lastNameButtonVal !== "" && firstNameButtonVal !== undefined && lastNameButtonVal !== undefined && emailButtonVal !== "" && emailButtonVal !== undefined && flowId ) {
51+ setShowPassword ( true ) ;
52+ document . querySelector ( 'button[value="profile"]' ) ?. setAttribute ( "class" , "hidden" ) ;
53+ setTimeout ( ( ) => {
54+ const existsPassword = document . querySelector ( 'input[name="password"]' ) !== null ;
55+ if ( ! existsPassword ) {
56+ document . querySelector ( 'button[value="profile"]' ) ?. setAttribute ( "class" , "block" ) ;
57+ }
58+ } , 100 ) ;
59+ }
60+ } , 1000 ) ;
61+ } , [ loadPage , flowId ] ) ;
6262
6363 useEffect ( ( ) => {
6464 getUserInfoExtended ( ( res ) => {
@@ -124,7 +124,7 @@ const Settings: NextPage = () => {
124124 } , [ flowId , router , router . isReady , returnTo , initialFlow ] )
125125
126126 useEffect ( ( ) => {
127- if ( ! initialFlow ) return ;
127+ if ( ! initialFlow || ! loadPage ) return ;
128128 initialFlow . ui . nodes = prepareNodes ( initialFlow ) ;
129129 const checkIfTotp = initialFlow . ui . nodes . find ( ( node : UiNode ) => node . group === "totp" ) ;
130130 const checkIfBackupCodes = initialFlow . ui . nodes . find ( ( node : UiNode ) => node . group === "lookup_secret" ) ;
@@ -141,6 +141,7 @@ const Settings: NextPage = () => {
141141 if ( [ "microsoft" , "google" ] . includes ( initialFlow . identity . metadata_public ?. registration_scope ?. provider_id ) ) {
142142 initialFlow . ui . nodes = initialFlow . ui . nodes . filter ( ( node : UiNode ) => node . group !== "password" ) ;
143143 setIsOidc ( true ) ;
144+ setCanShow ( true ) ;
144145 if ( initialFlow . identity . metadata_public ?. registration_scope ?. invitation_sso ) {
145146 setIsOidcInvitation ( true ) ;
146147 }
@@ -151,13 +152,15 @@ const Settings: NextPage = () => {
151152 document . querySelector ( 'button[value="Google"]' ) ?. setAttribute ( "class" , "hidden" ) ;
152153 }
153154 }
155+ else {
156+ setIsOidc ( false ) ;
157+ setCanShow ( true ) ;
158+ }
154159 } , 100 ) ;
155- } , [ initialFlow ] )
160+ } , [ initialFlow , loadPage ] )
156161
157162 useEffect ( ( ) => {
158- console . log ( loadPage ) ;
159163 if ( ! changedFlow || ! initialFlow || ! loadPage ) return ;
160- // setTimeout(() => {
161164 const firstNameButtonVal = ( document . querySelector ( 'input[name="traits.name.first"]' ) as HTMLInputElement ) ?. value ;
162165 const lastNameButtonVal = ( document . querySelector ( 'input[name="traits.name.last"]' ) as HTMLInputElement ) ?. value ;
163166 if ( isOidc && isOidcInvitation ) {
@@ -171,21 +174,20 @@ const Settings: NextPage = () => {
171174 const passwordButtonVal = ( document . querySelector ( 'input[name="password"]' ) as HTMLInputElement ) ?. value ;
172175 if ( firstNameButtonVal !== "" && lastNameButtonVal !== "" && firstNameButtonVal !== undefined && lastNameButtonVal !== undefined ) {
173176 setShowPassword ( true ) ;
174- document . querySelector ( 'button[value="profile"]' ) ?. setAttribute ( "class" , "hidden" ) ;
177+ if ( flowId && ! isOidc ) {
178+ document . querySelector ( 'button[value="profile"]' ) ?. setAttribute ( "class" , "hidden" ) ;
179+ }
175180 }
176181 if ( firstNameButtonVal !== "" && lastNameButtonVal !== "" && passwordButtonVal !== "" && passwordButtonVal !== undefined ) {
177182 setShowAuthenticator ( true ) ;
178183 }
179-
180- console . log ( firstNameButtonVal , lastNameButtonVal , emailButtonVal , passwordButtonVal , flowId ) ;
181184 if ( ( firstNameButtonVal === "" || lastNameButtonVal === "" || emailButtonVal === "" || passwordButtonVal === "" || firstNameButtonVal === undefined || lastNameButtonVal === undefined || emailButtonVal === undefined || passwordButtonVal === undefined ) && flowId ) {
182185 setBackButtonDisabled ( true ) ;
183186 } else {
184187 setBackButtonDisabled ( false ) ;
185188 }
186189 }
187- // }, 0); // Wait for the page to load
188- } , [ isOidc , isOidcInvitation , initialFlow , changedFlow , loadPage , flowId ] ) ;
190+ } , [ isOidc , isOidcInvitation , initialFlow , changedFlow , flowId , loadPage ] ) ;
189191
190192 useEffect ( ( ) => {
191193 if ( ! changedFlow ) return ;
@@ -232,16 +234,11 @@ const Settings: NextPage = () => {
232234 return Promise . reject ( err )
233235 } )
234236
235- useConsoleLog ( showPassword , 'showPassword' ) ;
236- useConsoleLog ( backButtonDisabled , 'backButtonDisabled' ) ;
237-
238237
239238 useEffect ( ( ) => {
240- console . log ( 'useEffect triggered for messages update' , backButtonDisabled , changedFlow , flowId , isOidc , showPassword ) ;
241239 if ( backButtonDisabled || ! changedFlow || ! changedFlow . ui . messages || ! flowId ) return ;
242240 const messagesCopy = [ ...changedFlow . ui . messages ] ;
243241 const messagesMapped = messagesCopy . map ( ( message : any ) => {
244- console . log ( message . id , isOidc , showPassword , backButtonDisabled , message . id === 1060001 && ! isOidc && showPassword && backButtonDisabled ) ;
245242 if ( message . id === 1050001 && ! isOidc && showPassword && ! backButtonDisabled ) {
246243 router . push ( '/cognition' ) ;
247244 return { ...message , id : '1050001ab' } ;
@@ -251,7 +248,6 @@ const Settings: NextPage = () => {
251248 setMessages ( messagesMapped ) ;
252249 } , [ backButtonDisabled , changedFlow , flowId , isOidc , showPassword ] ) ;
253250
254-
255251 return (
256252 < >
257253 < Head >
@@ -275,7 +271,7 @@ const Settings: NextPage = () => {
275271 />
276272 </ div >
277273
278- { ! isOidc && < >
274+ { ( ! isOidc && canShow ) && < >
279275 { ( ( flowId && showPassword ) || ! flowId ) && (
280276 < div className = "form-container" >
281277 < h3 className = "subtitle" > { ! flowId ? t ( 'changePassword' ) : t ( 'setPassword' ) } </ h3 >
0 commit comments