-
Notifications
You must be signed in to change notification settings - Fork 63
/
automation.tsx
92 lines (84 loc) · 2.43 KB
/
automation.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { useEffect, useState } from 'react';
import { createRoot } from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import { TopBarWithBeamer } from 'common/top-bar/top-bar';
import { SlotFillProvider } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { registerTranslations } from 'common';
import { initializeApi } from './api';
import { createStore, storeName } from './listing/store';
import { AutomationListing, AutomationListingHeader } from './listing';
import { registerApiErrorHandler } from './listing/api-error-handler';
import { Notices } from './listing/components/notices';
import { BuildYourOwnSection, HeroSection, TemplatesSection } from './sections';
import { MailPoet } from '../mailpoet';
const trackOpenEvent = () => {
MailPoet.trackEvent('Automations > Listing viewed');
};
function Content(): JSX.Element {
const [isBooting, setIsBooting] = useState(true);
const count = useSelect((select) => select(storeName).getAutomationCount());
useEffect(() => {
if (!isBooting || count === 0) {
return;
}
trackOpenEvent();
setIsBooting(false);
}, [isBooting, count]);
const content =
count > 0 ? (
<>
<AutomationListingHeader />
<AutomationListing />
</>
) : (
<HeroSection />
);
// Hide notices on onboarding screen
useEffect(() => {
const onboardingClass = 'mailpoet-automation-is-onboarding';
const element = document.querySelector('body');
if (count === 0 && !element.classList.contains(onboardingClass)) {
element.classList.add(onboardingClass);
}
if (count > 0 && element.classList.contains(onboardingClass)) {
element.classList.remove(onboardingClass);
}
}, [count]);
return (
<>
{content}
<TemplatesSection />
<BuildYourOwnSection />
</>
);
}
function Automations(): JSX.Element {
return (
<>
<TopBarWithBeamer />
<Notices />
<Content />
</>
);
}
function App(): JSX.Element {
return (
<SlotFillProvider>
<BrowserRouter>
<Automations />
</BrowserRouter>
</SlotFillProvider>
);
}
window.addEventListener('DOMContentLoaded', () => {
createStore();
const container = document.getElementById('mailpoet_automation');
if (container) {
registerTranslations();
registerApiErrorHandler();
initializeApi();
const root = createRoot(container);
root.render(<App />);
}
});