components
1 year ago
constants.ts
1 year ago
helpers.ts
1 year ago
index.tsx
1 year ago
style.scss
1 year ago
types.ts
1 year ago
index.tsx
47 lines
| 1 | import * as jpDataUtils from '@automattic/jetpack-script-data'; |
| 2 | import { createRoot } from '@wordpress/element'; |
| 3 | import { NewsletterWidget } from './components/newsletter-widget'; |
| 4 | import type { SubscriberTotalsByDate } from './types'; |
| 5 | |
| 6 | declare global { |
| 7 | interface Window { |
| 8 | jetpackNewsletterWidgetConfigData?: { |
| 9 | emailSubscribers?: number; |
| 10 | paidSubscribers?: number; |
| 11 | allSubscribers?: number; |
| 12 | subscriberTotalsByDate?: SubscriberTotalsByDate; |
| 13 | }; |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | document.addEventListener( 'DOMContentLoaded', () => { |
| 18 | const container = document.getElementById( 'newsletter-widget-app' ); |
| 19 | |
| 20 | if ( ! container ) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | const { emailSubscribers, paidSubscribers, allSubscribers, subscriberTotalsByDate } = |
| 25 | window.jetpackNewsletterWidgetConfigData || {}; |
| 26 | const { suffix: site } = jpDataUtils.getSiteData(); |
| 27 | const adminUrl = jpDataUtils.getAdminUrl(); |
| 28 | const isWpcomSite = jpDataUtils.isWpcomPlatformSite(); |
| 29 | |
| 30 | if ( ! site || ! adminUrl || isWpcomSite === undefined ) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | const root = createRoot( container ); |
| 35 | root.render( |
| 36 | <NewsletterWidget |
| 37 | site={ site } |
| 38 | adminUrl={ adminUrl } |
| 39 | isWpcomSite={ isWpcomSite } |
| 40 | emailSubscribers={ emailSubscribers } |
| 41 | paidSubscribers={ paidSubscribers } |
| 42 | allSubscribers={ allSubscribers } |
| 43 | subscriberTotalsByDate={ subscriberTotalsByDate } |
| 44 | /> |
| 45 | ); |
| 46 | } ); |
| 47 |