PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.65
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.65
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
leadin / scripts / gutenberg / Sidebar / contentType.tsx

contentType.tsx in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.3.65, at scripts/gutenberg/Sidebar/contentType.tsx

105 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useEffect, useState } from 'react';
2 import * as WpPluginsLib from '@wordpress/plugins';
3 import { PluginSidebar } from '@wordpress/edit-post';
4 import { PanelBody, Icon } from '@wordpress/components';
5 import { withSelect } from '@wordpress/data';
6 import UISidebarSelectControl from '../UIComponents/UISidebarSelectControl';
7 import SidebarSprocketIcon from '../Common/SidebarSprocketIcon';
8 import styled from 'styled-components';
9 import { __ } from '@wordpress/i18n';
10 import { BackgroudAppContext } from '../../iframe/useBackgroundApp';
11 import { getOrCreateBackgroundApp } from '../../utils/backgroundAppUtils';
12 import { isFullSiteEditor } from '../../utils/withMetaData';
13 import { isRefreshTokenAvailable } from '../../utils/isRefreshTokenAvailable';
14 import { fetchAccessToken } from '../../api/wordpressApiClient';
15
16 export function registerHubspotSidebar() {
17 const ContentTypeLabelStyle = styled.div`
18 white-space: normal;
19 text-transform: none;
20 `;
21
22 const ContentTypeLabel = (
23 <ContentTypeLabelStyle>
24 {__(
25 'Select the content type HubSpot Analytics uses to track this page',
26 'leadin'
27 )}
28 </ContentTypeLabelStyle>
29 );
30
31 const LeadinPluginSidebar = ({ postType }: { postType: string }) => {
32 const [embedder, setEmbedder] = useState<any>(null);
33
34 useEffect(() => {
35 if (isRefreshTokenAvailable()) {
36 fetchAccessToken()
37 .then(
38 ({
39 accessToken,
40 expiresIn,
41 }: {
42 accessToken: string;
43 expiresIn: number;
44 }) => {
45 setEmbedder(getOrCreateBackgroundApp(accessToken, expiresIn));
46 }
47 )
48 .catch(() => {});
49 }
50 }, []);
51
52 return postType && !isFullSiteEditor() ? (
53 <PluginSidebar
54 name="leadin"
55 title="HubSpot"
56 icon={
57 <Icon
58 className="hs-plugin-sidebar-sprocket"
59 icon={SidebarSprocketIcon()}
60 />
61 }
62 >
63 <PanelBody title={__('HubSpot Analytics', 'leadin')} initialOpen={true}>
64 <BackgroudAppContext.Provider value={embedder}>
65 <UISidebarSelectControl
66 metaKey="content-type"
67 className="select-content-type"
68 label={ContentTypeLabel}
69 options={[
70 { label: __('Detect Automatically', 'leadin'), value: '' },
71 { label: __('Blog Post', 'leadin'), value: 'blog-post' },
72 {
73 label: __('Knowledge Article', 'leadin'),
74 value: 'knowledge-article',
75 },
76 { label: __('Landing Page', 'leadin'), value: 'landing-page' },
77 { label: __('Listing Page', 'leadin'), value: 'listing-page' },
78 {
79 label: __('Standard Page', 'leadin'),
80 value: 'standard-page',
81 },
82 ]}
83 />
84 </BackgroudAppContext.Provider>
85 </PanelBody>
86 </PluginSidebar>
87 ) : null;
88 };
89 const LeadinPluginSidebarWrapper = withSelect((select: Function) => {
90 const data = select('core/editor');
91 return {
92 postType:
93 data &&
94 data.getCurrentPostType() &&
95 data.getEditedPostAttribute('meta'),
96 };
97 })(LeadinPluginSidebar);
98 if (WpPluginsLib) {
99 WpPluginsLib.registerPlugin('leadin', {
100 render: LeadinPluginSidebarWrapper,
101 icon: SidebarSprocketIcon,
102 });
103 }
104 }
105