Skip to content

Commit 01be65b

Browse files
Test
1 parent 96cb4af commit 01be65b

File tree

2 files changed

+65
-49
lines changed

2 files changed

+65
-49
lines changed

pages/settings.tsx

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -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 && <>

util/helper-functions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const customMessageOverridesEnglish = {
22
1060001: "Welcome to the app! You have successfully registered. Set your first and last name to continue.",
33
'1060001a': "Welcome to the app! You have successfully registered. Set your first, last name and link your account to continue.",
4+
'1060001b': "Welcome to the app! You have successfully recovered your account.",
45
1050001: "Your changes are saved!",
56
'1050001a': "Your changes are saved! Please set your password to continue.",
67
'1050001ab': "Your password has been set successfully! ",
@@ -12,6 +13,7 @@ const customMessageOverridesEnglish = {
1213
const customMessageOverridesGerman = {
1314
1060001: "Willkommen in der App! Sie haben sich erfolgreich registriert. Bitte geben Sie Ihren Vor- und Nachnamen ein, um fortzufahren.",
1415
'1060001a': "Willkommen in der App! Sie haben sich erfolgreich registriert. Bitte geben Sie Ihren Vor- und Nachnamen ein und verknüpfen Sie Ihr Konto, um fortzufahren.",
16+
'1060001b': "Willkommen in der App! Sie haben Ihr Konto erfolgreich wiederhergestellt.",
1517
1050001: "Ihre Änderungen wurden gespeichert!",
1618
'1050001a': "Ihre Änderungen wurden gespeichert! Bitte setzen Sie Ihr Passwort, um fortzufahren.",
1719
'1050001ab': "Ihr Passwort wurde erfolgreich gesetzt! ",
@@ -23,6 +25,7 @@ const customMessageOverridesGerman = {
2325
const customMessageOverridesDutch = {
2426
1060001: "Welkom bij de app! Je bent succesvol geregistreerd. Vul je voor- en achternaam in om verder te gaan.",
2527
'1060001a': "Welkom bij de app! Je bent succesvol geregistreerd. Vul je voor- en achternaam in en koppel je account om verder te gaan.",
28+
'1060001b': "Welkom bij de app! Je hebt je account succesvol hersteld.",
2629
1050001: "Uw wijzigingen zijn opgeslagen!",
2730
'1050001a': "Uw wijzigingen zijn opgeslagen! Stel uw wachtwoord in om verder te gaan.",
2831
'1050001ab': "Uw wachtwoord is succesvol ingesteld! ",

0 commit comments

Comments
 (0)