Skip to content

Commit b1cd45a

Browse files
authored
Forms: Add programmatic initialization support (#45531)
1 parent 5b9aa59 commit b1cd45a

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Forms: Add programmatic initialization support via window.jetpackFormsInit()

projects/packages/forms/src/dashboard/index.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,30 @@ import Integrations from './integrations';
1515
import DashboardNotices from './notices-list';
1616
import './style.scss';
1717

18-
window.addEventListener( 'load', () => {
18+
declare global {
19+
interface Window {
20+
jetpackFormsInit?: () => void;
21+
}
22+
}
23+
24+
let isInitialized = false;
25+
26+
/**
27+
* Initialize the Forms dashboard
28+
*/
29+
function initFormsDashboard() {
30+
if ( isInitialized ) {
31+
return;
32+
}
33+
1934
const container = document.getElementById( 'jp-forms-dashboard' );
2035

36+
if ( ! container ) {
37+
return;
38+
}
39+
40+
isInitialized = true;
41+
2142
const router = createHashRouter( [
2243
{
2344
path: '/',
@@ -51,4 +72,7 @@ window.addEventListener( 'load', () => {
5172
<DashboardNotices />
5273
</ThemeProvider>
5374
);
54-
} );
75+
}
76+
77+
window.jetpackFormsInit = initFormsDashboard;
78+
window.addEventListener( 'load', initFormsDashboard );

0 commit comments

Comments
 (0)