@@ -40,11 +40,24 @@ const Settings: NextPage = () => {
4040 const [ loadPage , setLoadPage ] = useState < boolean > ( false ) ;
4141
4242 useEffect ( ( ) => {
43- if ( loadPage ) return ;
44- setTimeout ( ( ) => {
45- setLoadPage ( true ) ;
46- } , 1000 ) ;
47- } , [ loadPage ] ) ;
43+ const onLoad = ( ) => {
44+ console . log ( 'All elements including images and external resources are fully loaded.' ) ;
45+ setTimeout ( ( ) => { setLoadPage ( true ) ; } , 1000 ) ;
46+ } ;
47+
48+ if ( document . readyState === 'complete' ) {
49+ onLoad ( ) ;
50+ } else {
51+ window . addEventListener ( 'load' , onLoad ) ;
52+ return ( ) => window . removeEventListener ( 'load' , onLoad ) ;
53+ }
54+ } , [ ] ) ;
55+ // useEffect(() => {
56+ // if (loadPage) return;
57+ // setTimeout(() => {
58+ // setLoadPage(true);
59+ // }, 1000);
60+ // }, [loadPage]);
4861
4962 useEffect ( ( ) => {
5063 getUserInfoExtended ( ( res ) => {
@@ -141,33 +154,35 @@ const Settings: NextPage = () => {
141154 } , [ initialFlow ] )
142155
143156 useEffect ( ( ) => {
144- if ( ! changedFlow || ! initialFlow ) return ;
145- const firstNameButtonVal = ( document . querySelector ( 'input[name="traits.name.first"]' ) as HTMLInputElement ) ?. value ;
146- const lastNameButtonVal = ( document . querySelector ( 'input[name="traits.name.last"]' ) as HTMLInputElement ) ?. value ;
147- if ( isOidc && isOidcInvitation ) {
148- if ( ( firstNameButtonVal === "" || lastNameButtonVal === "" || firstNameButtonVal === undefined || lastNameButtonVal === undefined ) && flowId ) {
149- setBackButtonDisabled ( true ) ;
157+ if ( ! changedFlow || ! initialFlow || ! loadPage ) return ;
158+ setTimeout ( ( ) => {
159+ const firstNameButtonVal = ( document . querySelector ( 'input[name="traits.name.first"]' ) as HTMLInputElement ) ?. value ;
160+ const lastNameButtonVal = ( document . querySelector ( 'input[name="traits.name.last"]' ) as HTMLInputElement ) ?. value ;
161+ if ( isOidc && isOidcInvitation ) {
162+ if ( ( firstNameButtonVal === "" || lastNameButtonVal === "" || firstNameButtonVal === undefined || lastNameButtonVal === undefined ) && flowId ) {
163+ setBackButtonDisabled ( true ) ;
164+ } else {
165+ setBackButtonDisabled ( false ) ;
166+ }
150167 } else {
151- setBackButtonDisabled ( false ) ;
152- }
153- } else {
154- const emailButtonVal = ( document . querySelector ( 'input[name="traits.email"]' ) as HTMLInputElement ) ?. value ;
155- const passwordButtonVal = ( document . querySelector ( 'input[name="password"]' ) as HTMLInputElement ) ?. value ;
156- if ( firstNameButtonVal !== "" && lastNameButtonVal !== "" && firstNameButtonVal !== undefined && lastNameButtonVal !== undefined ) {
157- setShowPassword ( true ) ;
158- document . querySelector ( 'button[value="profile"]' ) ?. setAttribute ( "class" , "hidden" ) ;
159- }
160- if ( firstNameButtonVal !== "" && lastNameButtonVal !== "" && passwordButtonVal !== "" && passwordButtonVal !== undefined ) {
161- setShowAuthenticator ( true ) ;
162- }
168+ const emailButtonVal = ( document . querySelector ( 'input[name="traits.email"]' ) as HTMLInputElement ) ?. value ;
169+ const passwordButtonVal = ( document . querySelector ( 'input[name="password"]' ) as HTMLInputElement ) ?. value ;
170+ if ( firstNameButtonVal !== "" && lastNameButtonVal !== "" && firstNameButtonVal !== undefined && lastNameButtonVal !== undefined ) {
171+ setShowPassword ( true ) ;
172+ document . querySelector ( 'button[value="profile"]' ) ?. setAttribute ( "class" , "hidden" ) ;
173+ }
174+ if ( firstNameButtonVal !== "" && lastNameButtonVal !== "" && passwordButtonVal !== "" && passwordButtonVal !== undefined ) {
175+ setShowAuthenticator ( true ) ;
176+ }
163177
164- if ( ( firstNameButtonVal === "" || lastNameButtonVal === "" || emailButtonVal === "" || passwordButtonVal === "" || firstNameButtonVal === undefined || lastNameButtonVal === undefined || emailButtonVal === undefined || passwordButtonVal === undefined ) && flowId ) {
165- setBackButtonDisabled ( true ) ;
166- } else {
167- setBackButtonDisabled ( false ) ;
178+ if ( ( firstNameButtonVal === "" || lastNameButtonVal === "" || emailButtonVal === "" || passwordButtonVal === "" || firstNameButtonVal === undefined || lastNameButtonVal === undefined || emailButtonVal === undefined || passwordButtonVal === undefined ) && flowId ) {
179+ setBackButtonDisabled ( true ) ;
180+ } else {
181+ setBackButtonDisabled ( false ) ;
182+ }
168183 }
169- }
170- } , [ isOidc , isOidcInvitation , initialFlow , changedFlow ] ) ;
184+ } , 0 ) ; // Wait for the page to load
185+ } , [ isOidc , isOidcInvitation , initialFlow , changedFlow , loadPage ] ) ;
171186
172187 useEffect ( ( ) => {
173188 if ( ! changedFlow ) return ;
@@ -181,6 +196,10 @@ const Settings: NextPage = () => {
181196 if ( message . id === 1050001 && showPassword ) {
182197 return { ...message , id : 1050001 + 'a' } ;
183198 }
199+ if ( message . id === 1060001 && ! isOidc && ! isOidcInvitation ) {
200+ return { ...message , id : 1060001 + 'b' } ;
201+
202+ }
184203 }
185204 return message ;
186205 } ) ;
@@ -219,11 +238,7 @@ const Settings: NextPage = () => {
219238 }
220239 return message ;
221240 } ) ;
222- messagesCopy . forEach ( ( message : any ) => {
223- if ( message . id === '1050001ab' ) {
224- router . push ( '/cognition' ) ;
225- }
226- } )
241+ console . log ( messagesMapped ) ;
227242 setMessages ( messagesMapped ) ;
228243 } , [ backButtonDisabled , changedFlow , flowId , isOidc ] ) ;
229244
@@ -238,7 +253,7 @@ const Settings: NextPage = () => {
238253 </ Head >
239254 < div className = "app-container" >
240255 < KernLogo />
241- { language && < div id = "settings" >
256+ { ( language && loadPage ) && < div id = "settings" >
242257 < h2 className = "title" > { t ( 'heading' ) } </ h2 >
243258 < div className = "form-container" >
244259 < Messages messages = { messages } />
@@ -251,20 +266,18 @@ const Settings: NextPage = () => {
251266 />
252267 </ div >
253268
254- { loadPage && < >
255- { ! isOidc && < >
256- { ( ( flowId && showPassword ) || ! flowId ) && (
257- < div className = "form-container" >
258- < h3 className = "subtitle" > { ! flowId ? t ( 'changePassword' ) : t ( 'setPassword' ) } </ h3 >
259- < Flow
260- hideGlobalMessages
261- onSubmit = { onSubmit }
262- only = "password"
263- flow = { changedFlow }
264- />
265- </ div >
266- ) }
267- </ > }
269+ { ! isOidc && < >
270+ { ( ( flowId && showPassword ) || ! flowId ) && (
271+ < div className = "form-container" >
272+ < h3 className = "subtitle" > { ! flowId ? t ( 'changePassword' ) : t ( 'setPassword' ) } </ h3 >
273+ < Flow
274+ hideGlobalMessages
275+ onSubmit = { onSubmit }
276+ only = "password"
277+ flow = { changedFlow }
278+ />
279+ </ div >
280+ ) }
268281 </ > }
269282
270283 { showAuthenticator && < >
0 commit comments