|
1 |
| -/* eslint no-new: 0 */ |
2 | 1 | 'use es6';
|
3 | 2 |
|
4 | 3 | import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
5 |
| -import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; |
6 |
| -import _createClass from "@babel/runtime/helpers/esm/createClass"; |
| 4 | +import { jsxs as _jsxs } from "react/jsx-runtime"; |
7 | 5 | import { jsx as _jsx } from "react/jsx-runtime";
|
8 |
| -import i18n from 'I18n'; |
9 |
| -import ReactDOM from 'react-dom'; |
10 |
| -import { Router } from 'react-router'; |
11 |
| -import { Provider } from 'react-redux'; |
12 |
| -import { fromJS } from 'immutable'; |
13 |
| -import userInfo from 'hub-http/userInfo'; |
14 |
| -import PortalIdParser from 'PortalIdParser'; |
15 |
| -import createHistory from 'SequencesUI/util/createHistory'; |
16 |
| -import { hasSequencesAccess } from './lib/permissions'; |
17 |
| -import configureStore from './util/configureStore'; |
18 |
| -import { tracker } from './util/UsageTracker'; |
19 |
| -import { RhumbProvider } from 'react-rhumb'; |
20 |
| -import historyAdapter from 'react-rhumb/historyAdapterV3'; |
21 |
| -import rhumbConfig from '../rhumb-config.yaml'; |
22 |
| -import GateContainer from './data/GateContainer'; |
23 |
| -import UserContainer from './data/UserContainer'; |
24 |
| -import PortalContainer from './data/PortalContainer'; |
25 |
| -import EmailConfirmBarPrebuilt from 'email-confirm-ui/prebuilts/HubHttpPrebuilt'; |
26 |
| -import { DataFetchingClient, DataFetchingClientProvider } from 'data-fetching-client'; |
27 |
| -import generateRoutes from './lib/routes'; |
28 |
| -import initScopeContainer from './initializers/initScopeContainer'; |
29 |
| -var GATES_TO_CHECK = ['Sequences:EnrollmentsReadOnlyView', 'Sequences:WootricSurveyEnabled', 'Sequences:WorkflowEnroll', 'Sequences:EmbeddedAutomation', 'sequences-settings-tab', 'Sequences:NewEmailPerformance']; |
30 |
| -var client = new DataFetchingClient(); |
31 |
| - |
32 |
| -var Application = /*#__PURE__*/function () { |
33 |
| -function Application() { |
34 |
| -_classCallCheck(this, Application); |
35 |
| -} |
| 6 | +import { useEffect, useState, useContext, useCallback, useMemo, createContext } from 'react'; |
| 7 | +import ContextualFlydown from './ContextualFlydown'; |
| 8 | +import TrialBanner from './TrialBanner'; |
| 9 | +import { FlydownContext } from './FlydownContext'; |
| 10 | +import { postMessage, verifyEvent } from './utils'; |
| 11 | +import { NavMarker } from 'react-rhumb'; |
| 12 | +import { useMaybeAutoExpandFlydown } from './useMaybeAutoExpandFlydown'; |
| 13 | +import { usePortalSettings } from './usePortalSettings'; |
| 14 | +import SwitchTrialViewPopover from './SwitchTrialViewPopover'; |
| 15 | +import { isAdmin } from 'ui-addon-upgrades/_core/common/eligibility/getIsAdmin'; |
| 16 | +import { tracker, getCommonTrackingProperties, syncTracker } from './tracker'; |
| 17 | +import { frameProps, isTrialActive } from './queryParamUtils'; |
| 18 | +import { MultiTrialDropdownContext } from './contexts/MultiTrialDropdownContext'; |
| 19 | +import { useUserInfo } from './useUserInfo'; |
| 20 | +import { useForwardSalesChatEvent } from './utils/zorseWidgetUtils'; |
| 21 | +import AlertWrapper from './utils/AlertWrapper'; |
| 22 | +import { useIsUngated } from './useIsUngated'; |
| 23 | +export var TrialStateContext = /*#__PURE__*/createContext(); |
| 24 | + |
| 25 | +function App() { |
| 26 | +var _useContext = useContext(FlydownContext), |
| 27 | +showFlydown = _useContext.showFlydown, |
| 28 | +setShowFlydown = _useContext.setShowFlydown; |
| 29 | + |
| 30 | +var _useContext2 = useContext(MultiTrialDropdownContext), |
| 31 | +setShowMultiTrialDropdown = _useContext2.setShowMultiTrialDropdown, |
| 32 | +setSwitchTrialViewRef = _useContext2.setSwitchTrialViewRef, |
| 33 | +switchTrialViewRef = _useContext2.switchTrialViewRef; |
| 34 | + |
| 35 | +var _useState = useState(frameProps.trialBannerState), |
| 36 | +_useState2 = _slicedToArray(_useState, 2), |
| 37 | +trialState = _useState2[0], |
| 38 | +setTrialState = _useState2[1]; |
| 39 | + |
| 40 | +var _useState3 = useState(frameProps.preferredTrial || {}), |
| 41 | +_useState4 = _slicedToArray(_useState3, 2), |
| 42 | +preferredTrial = _useState4[0], |
| 43 | +setPreferredTrial = _useState4[1]; |
36 | 44 |
|
37 |
| -_createClass(Application, [{ |
38 |
| -key: "start", |
39 |
| -value: function start() { |
40 |
| -window.AppInstance = this; |
| 45 | +var _useState5 = useState(false), |
| 46 | +_useState6 = _slicedToArray(_useState5, 2), |
| 47 | +hasTrackedPageView = _useState6[0], |
| 48 | +setHasTrackedPageView = _useState6[1]; |
41 | 49 |
|
42 |
| -if (window.newrelic && window.performance && window.performance.getEntriesByName) { |
43 |
| -var scriptStartEntries = window.performance.getEntriesByName('scriptStartTime'); |
| 50 | +useEffect(function () { |
| 51 | +window.addEventListener('message', function (event) { |
| 52 | +if (verifyEvent(window.parent, event)) { |
| 53 | +if (event.data === 'FLYDOWN_CLOSE') { |
| 54 | +postMessage('FLYDOWN_CLOSE'); |
| 55 | +setShowFlydown(false); |
| 56 | +setShowMultiTrialDropdown(false); // Dismiss MultiTrialDropdown when user clicks outside of banner iframe |
44 | 57 |
|
45 |
| -if (scriptStartEntries.length > 0) { |
46 |
| -window.newrelic.setCustomAttribute('scriptStartTime', scriptStartEntries[0].startTime); |
47 |
| -window.newrelic.setCustomAttribute('appStartTime', window.performance.now()); |
| 58 | +setSwitchTrialViewRef(null); // Dismiss "switch trial views" popover when user clicks outside of banner iframe |
48 | 59 | }
|
49 | 60 | }
|
| 61 | +}); |
| 62 | +}, [setShowFlydown, switchTrialViewRef, setSwitchTrialViewRef, setShowMultiTrialDropdown]); /// for tts chat event capture |
50 | 63 |
|
51 |
| -this.init().then(this.actualStart.bind(this)).done(); |
| 64 | +useForwardSalesChatEvent(); |
| 65 | +var productApiName = preferredTrial.productApiName, |
| 66 | +expiresAt = preferredTrial.expiresAt, |
| 67 | +upgradeProduct = preferredTrial.trialName; |
| 68 | +var activeTrials = useMemo(function () { |
| 69 | +if (!trialState) { |
| 70 | +return []; |
52 | 71 | }
|
53 |
| -}, { |
54 |
| -key: "init", |
55 |
| -value: function init() { |
56 |
| -PortalIdParser.get(); |
57 |
| -return Promise.all([userInfo(), i18n.Info]).then(function (_ref) { |
58 |
| -var _ref2 = _slicedToArray(_ref, 1), |
59 |
| -authData = _ref2[0]; |
60 |
| - |
61 |
| -var user = authData.user, |
62 |
| -gates = authData.gates, |
63 |
| -portal = authData.portal; |
64 |
| -UserContainer.set(user); |
65 |
| -PortalContainer.set(fromJS(portal)); |
66 |
| -initScopeContainer(user.scopes); |
67 |
| -GateContainer.set(GATES_TO_CHECK.reduce(function (acc, gate) { |
68 |
| -acc[gate] = gates.includes(gate); |
69 |
| -return acc; |
70 |
| -}, {})); |
71 |
| - |
72 |
| -if (!hasSequencesAccess()) { |
73 |
| -return window.location.href = "/upgrade/" + PortalIdParser.get() + "/sequences"; |
74 |
| -} |
75 | 72 |
|
76 |
| -return { |
77 |
| -authData: authData |
78 |
| -}; |
79 |
| -}); |
| 73 | +return trialState.filter(function (trial) { |
| 74 | +return isTrialActive(trial.status); |
| 75 | +}); |
| 76 | +}, [trialState]); |
| 77 | +var expiredTrials = useMemo(function () { |
| 78 | +if (!trialState) { |
| 79 | +return []; |
80 | 80 | }
|
81 |
| -}, { |
82 |
| -key: "actualStart", |
83 |
| -value: function actualStart() { |
84 |
| -tracker.track('pageView', { |
85 |
| -subscreen: 'sequences-index' |
86 |
| -}); |
87 |
| -this.startRedux(); |
88 |
| -new EmailConfirmBarPrebuilt(); |
| 81 | + |
| 82 | +return trialState.filter(function (trial) { |
| 83 | +return !isTrialActive(trial.status); |
| 84 | +}); |
| 85 | +}, [trialState]); |
| 86 | +var isMultiTrial = activeTrials.length > 1; |
| 87 | +var userInfo = useUserInfo(); |
| 88 | +var isUngatedForBannerPortals = useIsUngated('Trials:BannerPortals'); |
| 89 | +useEffect(function () { |
| 90 | +if (productApiName && expiresAt && upgradeProduct && isMultiTrial !== null) { |
| 91 | +tracker.setProperties(getCommonTrackingProperties({ |
| 92 | +activeTrials: activeTrials, |
| 93 | +apiName: productApiName, |
| 94 | +expiredTrials: expiredTrials, |
| 95 | +expiresAt: expiresAt, |
| 96 | +upgradeProduct: upgradeProduct, |
| 97 | +isMultiTrial: isMultiTrial |
| 98 | +})); |
| 99 | +syncTracker.setProperties(getCommonTrackingProperties({ |
| 100 | +activeTrials: activeTrials, |
| 101 | +apiName: productApiName, |
| 102 | +expiredTrials: expiredTrials, |
| 103 | +expiresAt: expiresAt, |
| 104 | +upgradeProduct: upgradeProduct, |
| 105 | +isMultiTrial: isMultiTrial |
| 106 | +})); |
89 | 107 | }
|
90 |
| -}, { |
91 |
| -key: "startRedux", |
92 |
| -value: function startRedux() { |
93 |
| -this.store = configureStore(); |
94 |
| -this.initRouter(); |
| 108 | + |
| 109 | +if (!hasTrackedPageView && trialState && userInfo) { |
| 110 | +// de-abstract isAdmin call so we can track whether the data has been fetched |
| 111 | +var userIsAdmin = !!(userInfo && isAdmin(userInfo)); |
| 112 | +tracker.setProperties({ |
| 113 | +isAdmin: userIsAdmin |
| 114 | +}); |
| 115 | +tracker.track('pageView'); |
| 116 | +postMessage('FRAME_READY'); |
| 117 | +setHasTrackedPageView(true); |
95 | 118 | }
|
96 |
| -}, { |
97 |
| -key: "initRouter", |
98 |
| -value: function initRouter() { |
99 |
| -var pageContainer = document.getElementsByClassName('page')[0]; |
100 |
| -var history = createHistory("/sequences/" + PortalIdParser.get()); |
101 |
| -ReactDOM.render( /*#__PURE__*/_jsx(RhumbProvider, { |
102 |
| -captureExceptions: true, |
103 |
| -config: rhumbConfig, |
104 |
| -history: historyAdapter(history), |
105 |
| -children: /*#__PURE__*/_jsx(Provider, { |
106 |
| -store: this.store, |
107 |
| -children: /*#__PURE__*/_jsx(DataFetchingClientProvider, { |
108 |
| -client: client, |
109 |
| -children: /*#__PURE__*/_jsx(Router, { |
110 |
| -routes: generateRoutes(), |
111 |
| -history: history |
112 |
| -}) |
113 |
| -}) |
114 |
| -}) |
115 |
| -}), pageContainer); |
| 119 | +}, [productApiName, expiresAt, upgradeProduct, isMultiTrial, activeTrials, expiredTrials, hasTrackedPageView, trialState, userInfo]); |
| 120 | +var portalSettings = usePortalSettings(showFlydown); |
| 121 | +var handleShowFlydownClick = useCallback(function () { |
| 122 | +setShowMultiTrialDropdown(false); |
| 123 | + |
| 124 | +if (!showFlydown) { |
| 125 | +postMessage('FLYDOWN_OPEN'); |
| 126 | +setShowFlydown(true); |
| 127 | +} else { |
| 128 | +setShowFlydown(false); |
| 129 | +postMessage('FLYDOWN_CLOSE'); |
116 | 130 | }
|
117 |
| -}]); |
| 131 | +}, [showFlydown, setShowFlydown, setShowMultiTrialDropdown]); |
| 132 | + |
| 133 | +var renderFlydown = function renderFlydown() { |
| 134 | +if (!showFlydown) return null; |
| 135 | +return /*#__PURE__*/_jsx(ContextualFlydown, { |
| 136 | +preferredTrialUpgradeProduct: upgradeProduct, |
| 137 | +onToggleFlydown: handleShowFlydownClick |
| 138 | +}); |
| 139 | +}; |
| 140 | + |
| 141 | +useMaybeAutoExpandFlydown(portalSettings, handleShowFlydownClick); // Some flows require the flydown to be open upon first visit |
| 142 | + |
| 143 | +var hasFetchedAllNeededInfoForTracking = !!(upgradeProduct && userInfo); |
| 144 | +var isLoadingGate = isUngatedForBannerPortals === null; |
| 145 | + |
| 146 | +if (!hasFetchedAllNeededInfoForTracking || isLoadingGate) { |
| 147 | +return null; |
| 148 | +} |
118 | 149 |
|
119 |
| -return Application; |
120 |
| -}(); |
| 150 | +return /*#__PURE__*/_jsxs("div", { |
| 151 | +"data-test-id": "trial-banner", |
| 152 | +children: [/*#__PURE__*/_jsx(NavMarker, { |
| 153 | +name: "BANNER_LOAD" |
| 154 | +}), /*#__PURE__*/_jsx(AlertWrapper, { |
| 155 | +children: /*#__PURE__*/_jsxs(TrialStateContext.Provider, { |
| 156 | +value: { |
| 157 | +trialState: trialState, |
| 158 | +onChangeTrialState: setTrialState, |
| 159 | +preferredTrial: preferredTrial, |
| 160 | +onChangePreferredTrial: setPreferredTrial |
| 161 | +}, |
| 162 | +children: [/*#__PURE__*/_jsx(TrialBanner, { |
| 163 | +onShowFlydownClick: handleShowFlydownClick, |
| 164 | +showFlydown: showFlydown |
| 165 | +}), renderFlydown(), /*#__PURE__*/_jsx(SwitchTrialViewPopover, { |
| 166 | +showFlydown: showFlydown |
| 167 | +})] |
| 168 | +}) |
| 169 | +})] |
| 170 | +}); |
| 171 | +} |
121 | 172 |
|
122 |
| -export { Application as default }; |
| 173 | +export default App; |
0 commit comments