Skip to content

Commit 00143a5

Browse files
committed
chore: pass-form-el
1 parent ac7fe33 commit 00143a5

5 files changed

Lines changed: 37 additions & 27 deletions

File tree

e2e/journey-app/callback-map.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ import {
6060
* @param journeyEl - The container element to append the component to
6161
* @param callback - The callback instance
6262
* @param idx - Index for generating unique IDs
63+
* @param onSubmit - Optional callback to trigger form submission
6364
*/
6465
export function renderCallback(
6566
journeyEl: HTMLDivElement,
6667
callback: BaseCallback,
6768
idx: number,
69+
onSubmit?: () => void,
6870
): void {
6971
switch (callback.getType()) {
7072
case 'BooleanAttributeInputCallback':
@@ -83,7 +85,7 @@ export function renderCallback(
8385
confirmationComponent(journeyEl, callback as ConfirmationCallback, idx);
8486
break;
8587
case 'DeviceProfileCallback':
86-
deviceProfileComponent(journeyEl, callback as DeviceProfileCallback, idx);
88+
deviceProfileComponent(journeyEl, callback as DeviceProfileCallback, idx, onSubmit);
8789
break;
8890
case 'HiddenValueCallback':
8991
hiddenValueComponent(journeyEl, callback as HiddenValueCallback, idx);
@@ -101,10 +103,20 @@ export function renderCallback(
101103
passwordComponent(journeyEl, callback as PasswordCallback, idx);
102104
break;
103105
case 'PingOneProtectEvaluationCallback':
104-
pingProtectEvaluationComponent(journeyEl, callback as PingOneProtectEvaluationCallback, idx);
106+
pingProtectEvaluationComponent(
107+
journeyEl,
108+
callback as PingOneProtectEvaluationCallback,
109+
idx,
110+
onSubmit,
111+
);
105112
break;
106113
case 'PingOneProtectInitializeCallback':
107-
pingProtectInitializeComponent(journeyEl, callback as PingOneProtectInitializeCallback, idx);
114+
pingProtectInitializeComponent(
115+
journeyEl,
116+
callback as PingOneProtectInitializeCallback,
117+
idx,
118+
onSubmit,
119+
);
108120
break;
109121
case 'PollingWaitCallback':
110122
pollingWaitComponent(journeyEl, callback as PollingWaitCallback, idx);
@@ -149,9 +161,14 @@ export function renderCallback(
149161
* Renders all callbacks in a step
150162
* @param journeyEl - The container element to append components to
151163
* @param callbacks - Array of callback instances
164+
* @param onSubmit - Optional callback to trigger form submission
152165
*/
153-
export function renderCallbacks(journeyEl: HTMLDivElement, callbacks: BaseCallback[]): void {
166+
export function renderCallbacks(
167+
journeyEl: HTMLDivElement,
168+
callbacks: BaseCallback[],
169+
onSubmit?: () => void,
170+
): void {
154171
callbacks.forEach((callback, idx) => {
155-
renderCallback(journeyEl, callback, idx);
172+
renderCallback(journeyEl, callback, idx, onSubmit);
156173
});
157174
}

e2e/journey-app/components/device-profile.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default function deviceProfileComponent(
1515
journeyEl: HTMLDivElement,
1616
callback: DeviceProfileCallback,
1717
idx: number,
18+
onSubmit?: () => void,
1819
) {
1920
const collectorKey = callback?.payload?.input?.[0].name || `collector-${idx}`;
2021
const message = document.createElement('p');
@@ -46,13 +47,9 @@ export default function deviceProfileComponent(
4647
message.innerText = 'Device profile collected successfully!';
4748
message.style.color = 'green';
4849

49-
// Auto-submit the form after successful collection
50-
setTimeout(() => {
51-
const form = document.getElementById('form') as HTMLFormElement;
52-
if (form) {
53-
form.requestSubmit();
54-
}
55-
}, 500);
50+
if (onSubmit) {
51+
setTimeout(() => onSubmit(), 500);
52+
}
5653
} catch (error) {
5754
console.error('Device profile collection failed:', error);
5855
const errorMessage = error instanceof Error ? error.message : 'Unknown error';

e2e/journey-app/components/ping-protect-evaluation.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default function pingProtectEvaluationComponent(
1515
journeyEl: HTMLDivElement,
1616
callback: PingOneProtectEvaluationCallback,
1717
idx: number,
18+
onSubmit?: () => void,
1819
) {
1920
const collectorKey = callback?.payload?.input?.[0].name || `collector-${idx}`;
2021
const message = document.createElement('p');
@@ -56,13 +57,9 @@ export default function pingProtectEvaluationComponent(
5657
message.innerText = 'Risk assessment completed successfully!';
5758
message.style.color = 'green';
5859

59-
// Auto-submit the form after successful data collection
60-
setTimeout(() => {
61-
const form = document.getElementById('form') as HTMLFormElement;
62-
if (form) {
63-
form.requestSubmit();
64-
}
65-
}, 500);
60+
if (onSubmit) {
61+
setTimeout(() => onSubmit(), 500);
62+
}
6663
} catch (error) {
6764
console.error('Protect evaluation failed:', error);
6865
const errorMessage = error instanceof Error ? error.message : 'Unknown error';

e2e/journey-app/components/ping-protect-initialize.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default function pingProtectInitializeComponent(
2626
journeyEl: HTMLDivElement,
2727
callback: PingOneProtectInitializeCallback,
2828
idx: number,
29+
onSubmit?: () => void,
2930
) {
3031
const collectorKey = callback?.payload?.input?.[0].name || `collector-${idx}`;
3132
const message = document.createElement('p');
@@ -74,13 +75,9 @@ export default function pingProtectInitializeComponent(
7475
message.innerText = 'PingOne Protect initialized successfully!';
7576
message.style.color = 'green';
7677

77-
// Auto-submit the form after successful initialization
78-
setTimeout(() => {
79-
const form = document.getElementById('form') as HTMLFormElement;
80-
if (form) {
81-
form.requestSubmit();
82-
}
83-
}, 500);
78+
if (onSubmit) {
79+
setTimeout(() => onSubmit(), 500);
80+
}
8481
} catch (error) {
8582
console.error('Protect initialization failed:', error);
8683
const errorMessage = error instanceof Error ? error.message : 'Unknown error';

e2e/journey-app/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ if (searchParams.get('middleware') === 'true') {
117117
header.innerText = formName || '';
118118
journeyEl.appendChild(header);
119119

120+
const submitForm = () => formEl.requestSubmit();
121+
120122
const stepRendered =
121123
renderQRCodeStep(journeyEl, step) || renderRecoveryCodesStep(journeyEl, step);
122124

123125
if (!stepRendered) {
124126
const callbacks = step.callbacks;
125-
renderCallbacks(journeyEl, callbacks);
127+
renderCallbacks(journeyEl, callbacks, submitForm);
126128
}
127129

128130
const submitBtn = document.createElement('button');

0 commit comments

Comments
 (0)