@atlaskit/smart-card 46.15.0 → 46.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/analytics.spec.yaml +2 -2
  3. package/dist/cjs/extractors/action/extract-invoke-preview-action.js +1 -2
  4. package/dist/cjs/extractors/embed/extract-smart-link-context.js +11 -15
  5. package/dist/cjs/utils/analytics/analytics.js +1 -1
  6. package/dist/cjs/view/CardWithUrl/card-error-boundary/index.js +53 -47
  7. package/dist/cjs/view/EmbedCard/views/unresolved-view/index.js +1 -2
  8. package/dist/cjs/view/LinkUrl/index.js +1 -1
  9. package/dist/cjs/view/PreAuthValuePropositionModal/index.js +56 -110
  10. package/dist/cjs/view/PreAuthValuePropositionModal/use-pre-auth-value-proposition-modal.js +175 -0
  11. package/dist/es2019/extractors/action/extract-invoke-preview-action.js +1 -2
  12. package/dist/es2019/extractors/embed/extract-smart-link-context.js +12 -16
  13. package/dist/es2019/utils/analytics/analytics.js +1 -1
  14. package/dist/es2019/view/CardWithUrl/card-error-boundary/index.js +53 -48
  15. package/dist/es2019/view/EmbedCard/views/unresolved-view/index.js +1 -2
  16. package/dist/es2019/view/LinkUrl/index.js +1 -1
  17. package/dist/es2019/view/PreAuthValuePropositionModal/index.js +54 -102
  18. package/dist/es2019/view/PreAuthValuePropositionModal/use-pre-auth-value-proposition-modal.js +160 -0
  19. package/dist/esm/extractors/action/extract-invoke-preview-action.js +1 -2
  20. package/dist/esm/extractors/embed/extract-smart-link-context.js +11 -15
  21. package/dist/esm/utils/analytics/analytics.js +1 -1
  22. package/dist/esm/view/CardWithUrl/card-error-boundary/index.js +51 -45
  23. package/dist/esm/view/EmbedCard/views/unresolved-view/index.js +1 -2
  24. package/dist/esm/view/LinkUrl/index.js +1 -1
  25. package/dist/esm/view/PreAuthValuePropositionModal/index.js +56 -110
  26. package/dist/esm/view/PreAuthValuePropositionModal/use-pre-auth-value-proposition-modal.js +167 -0
  27. package/dist/types/common/analytics/generated/analytics.types.d.ts +2 -2
  28. package/dist/types/view/PreAuthValuePropositionModal/index.d.ts +1 -1
  29. package/dist/types/view/PreAuthValuePropositionModal/use-pre-auth-value-proposition-modal.d.ts +31 -0
  30. package/package.json +7 -4
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SMART_LINK_MODAL_ID = void 0;
8
+ exports.usePreAuthValuePropositionModal = usePreAuthValuePropositionModal;
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _react = require("react");
11
+ var _extractSmartLinkProvider = require("@atlaskit/link-extractors/extract-smart-link-provider");
12
+ var _expVal = require("@atlaskit/platform-feature-experiments/exp-val");
13
+ var _useAnalyticsEvents2 = require("../../common/analytics/generated/use-analytics-events");
14
+ var _helpers = require("../../state/helpers");
15
+ var _useSocialProof2 = _interopRequireDefault(require("../../state/hooks/use-social-proof"));
16
+ var _useSmartLink2 = require("../../state/hooks/useSmartLink");
17
+ var _preAuthValuePropositionModal = require("../../state/services/pre-auth-value-proposition-modal");
18
+ var SMART_LINK_MODAL_ID = exports.SMART_LINK_MODAL_ID = 'pre-auth-value-proposition-modal';
19
+ var getModalCloseMethod = function getModalCloseMethod(event) {
20
+ return 'key' in event && event.key === 'Escape' ? 'escape' : 'overlay';
21
+ };
22
+
23
+ /**
24
+ * Eligibility, assignment and modal actions for one URL attempt.
25
+ * The existing choreographer adapter owns display permission and cleanup.
26
+ */
27
+ function usePreAuthValuePropositionModal(_ref) {
28
+ var url = _ref.url,
29
+ onFinished = _ref.onFinished;
30
+ var _useSmartLink = (0, _useSmartLink2.useSmartLink)(SMART_LINK_MODAL_ID, url, 'inline'),
31
+ actions = _useSmartLink.actions,
32
+ config = _useSmartLink.config,
33
+ state = _useSmartLink.state;
34
+ var _useAnalyticsEvents = (0, _useAnalyticsEvents2.useAnalyticsEvents)(),
35
+ fireEvent = _useAnalyticsEvents.fireEvent;
36
+ var _useState = (0, _react.useState)(false),
37
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
38
+ isRequested = _useState2[0],
39
+ setIsRequested = _useState2[1];
40
+ var finished = (0, _react.useRef)(false);
41
+ var hasOpened = (0, _react.useRef)(false);
42
+ var hasRecordedShow = (0, _react.useRef)(false);
43
+ var _useState3 = (0, _react.useState)('modal_text_only'),
44
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
45
+ visibleVariant = _useState4[0],
46
+ setVisibleVariant = _useState4[1];
47
+ var modalOpenTimeRef = (0, _react.useRef)(Date.now());
48
+ var provider = (0, _react.useMemo)(function () {
49
+ return (0, _extractSmartLinkProvider.extractSmartLinkProvider)(state.details);
50
+ }, [state.details]);
51
+ var providerName = provider === null || provider === void 0 ? void 0 : provider.text;
52
+ var services = (0, _helpers.getServices)(state.details);
53
+ var extensionKey = (0, _helpers.getExtensionKey)(state.details);
54
+ var _useSocialProof = (0, _useSocialProof2.default)(extensionKey, true),
55
+ connectedPct = _useSocialProof.connectedPct,
56
+ isSocialProofAvailable = _useSocialProof.isEnabled;
57
+ var hasSupportedAuthorization = (config === null || config === void 0 ? void 0 : config.authFlow) !== 'disabled' && services.length > 0;
58
+ var isBaseEligible = state.status === 'unauthorized' && Boolean(providerName) && Boolean(extensionKey) && hasSupportedAuthorization;
59
+ var finishCoordinatedAttempt = (0, _react.useCallback)(function () {
60
+ if (finished.current) {
61
+ return;
62
+ }
63
+ finished.current = true;
64
+ setIsRequested(false);
65
+ onFinished();
66
+ }, [onFinished]);
67
+ var handleUnavailable = (0, _react.useCallback)(function () {
68
+ if (finished.current) {
69
+ return;
70
+ }
71
+ if (hasOpened.current) {
72
+ fireEvent('ui.modal.closed.preAuthValueProposition', {
73
+ closeMethod: 'coordinator',
74
+ dwellTime: Date.now() - modalOpenTimeRef.current
75
+ });
76
+ }
77
+ finishCoordinatedAttempt();
78
+ }, [fireEvent, finishCoordinatedAttempt]);
79
+ var shouldClaim = (0, _react.useCallback)(function () {
80
+ // Recheck at offer time: another attempt may have consumed the cap while we waited.
81
+ if (finished.current || !isBaseEligible || !extensionKey || _preAuthValuePropositionModal.preAuthValuePropositionModalService.hasReachedShowLimit(extensionKey)) {
82
+ return false;
83
+ }
84
+ var variant = (0, _expVal.expVal)('platform_sl_3p_preauth_value_modal', 'variant', 'control');
85
+ if (variant !== 'modal_text_only' && variant !== 'modal_with_image') {
86
+ return false;
87
+ }
88
+ setVisibleVariant(variant);
89
+ return true;
90
+ }, [extensionKey, isBaseEligible]);
91
+
92
+ // The editor mounts this flow only when platform_sl_3p_preauth_value_modal_killswitch is on.
93
+ (0, _react.useEffect)(function () {
94
+ if (finished.current) {
95
+ return;
96
+ }
97
+ if (state.status === 'pending' || state.status === 'resolving') {
98
+ // A previously eligible link that starts resolving again must release its slot.
99
+ if (isRequested) {
100
+ handleUnavailable();
101
+ }
102
+ return;
103
+ }
104
+ if (!isBaseEligible || !extensionKey) {
105
+ handleUnavailable();
106
+ return;
107
+ }
108
+ if (!isRequested) {
109
+ if (_preAuthValuePropositionModal.preAuthValuePropositionModalService.hasReachedShowLimit(extensionKey)) {
110
+ finishCoordinatedAttempt();
111
+ } else {
112
+ setIsRequested(true);
113
+ }
114
+ }
115
+ }, [extensionKey, isBaseEligible, state.status, isRequested, handleUnavailable, finishCoordinatedAttempt]);
116
+ var recordShowOnce = (0, _react.useCallback)(function () {
117
+ if (hasRecordedShow.current || !extensionKey) {
118
+ return;
119
+ }
120
+ hasRecordedShow.current = true;
121
+ _preAuthValuePropositionModal.preAuthValuePropositionModalService.recordShow(extensionKey);
122
+ }, [extensionKey]);
123
+ var dismissModal = (0, _react.useCallback)(function (closeMethod) {
124
+ if (finished.current) {
125
+ return;
126
+ }
127
+ // A user can dismiss the visible modal before its entrance animation completes.
128
+ recordShowOnce();
129
+ fireEvent('ui.modal.closed.preAuthValueProposition', {
130
+ closeMethod: closeMethod,
131
+ dwellTime: Date.now() - modalOpenTimeRef.current
132
+ });
133
+ finishCoordinatedAttempt();
134
+ }, [fireEvent, finishCoordinatedAttempt, recordShowOnce]);
135
+ var handleCloseButton = (0, _react.useCallback)(function () {
136
+ dismissModal('button');
137
+ }, [dismissModal]);
138
+ var handleModalClose = (0, _react.useCallback)(function (event) {
139
+ dismissModal(getModalCloseMethod(event));
140
+ }, [dismissModal]);
141
+ var handleOpenComplete = (0, _react.useCallback)(function () {
142
+ if (finished.current || hasOpened.current || !extensionKey) {
143
+ return;
144
+ }
145
+ hasOpened.current = true;
146
+ recordShowOnce();
147
+ modalOpenTimeRef.current = Date.now();
148
+ fireEvent('ui.modal.opened.preAuthValueProposition', {});
149
+ }, [fireEvent, extensionKey, recordShowOnce]);
150
+ var connectAccount = (0, _react.useCallback)(function () {
151
+ if (finished.current) {
152
+ return;
153
+ }
154
+ recordShowOnce();
155
+ fireEvent('track.applicationAccount.authStarted', {});
156
+ finishCoordinatedAttempt();
157
+ actions.authorize('inline');
158
+ }, [actions, fireEvent, finishCoordinatedAttempt, recordShowOnce]);
159
+ return {
160
+ isActive: isRequested,
161
+ isEligible: isBaseEligible,
162
+ onUnavailable: handleUnavailable,
163
+ shouldClaim: shouldClaim,
164
+ modal: {
165
+ provider: provider,
166
+ variant: visibleVariant,
167
+ connectedPct: connectedPct,
168
+ isSocialProofAvailable: isSocialProofAvailable,
169
+ onClose: handleModalClose,
170
+ onCloseButton: handleCloseButton,
171
+ onConnect: connectAccount,
172
+ onOpenComplete: handleOpenComplete
173
+ }
174
+ };
175
+ }
@@ -13,7 +13,6 @@ import { canShowAction } from '../../utils/actions/can-show-action';
13
13
  import { openEmbedModal } from '../../view/EmbedModal/utils';
14
14
  import { extractIsSupportTheming } from '../common/meta/extractIsSupportTheming';
15
15
  import { extractIsTrusted } from '../common/meta/extractIsTrusted';
16
- import { extractLinkIcon } from '../flexible/icon/extract-link-icon';
17
16
  import { extractSmartLinkIcon } from '../flexible/icon/extract-smart-link-icon';
18
17
  import { extractInvokeDownloadAction } from './extract-invoke-download-action';
19
18
  import { extractInvokeViewAction } from './extract-invoke-view-action';
@@ -107,7 +106,7 @@ export const extractInvokePreviewAction = param => {
107
106
  invokeViewAction: extractInvokeViewAction(param, true),
108
107
  isSupportTheming: extractIsSupportTheming(meta),
109
108
  isTrusted: extractIsTrusted(meta),
110
- linkIcon: fg('platform_lp_use_generator_icon_for_provider') ? extractSmartLinkIcon(response) : extractLinkIcon(response),
109
+ linkIcon: extractSmartLinkIcon(response),
111
110
  providerName: (_extractSmartLinkProv = extractSmartLinkProvider(response)) === null || _extractSmartLinkProv === void 0 ? void 0 : _extractSmartLinkProv.text,
112
111
  onClose,
113
112
  origin,
@@ -1,7 +1,6 @@
1
1
  import { extractEntityIcon } from '@atlaskit/link-extractors/extract-entity-icon';
2
2
  import { extractEntityProvider } from '@atlaskit/link-extractors/extract-entity-provider';
3
3
  import { isEntityPresent } from '@atlaskit/link-extractors/is-entity-present';
4
- import { fg } from '@atlaskit/platform-feature-flags/fg';
5
4
  import { getEmptyJsonLd } from '../../utils/get-empty-json-ld';
6
5
  import { generateContext } from '../common/context/generateContext';
7
6
 
@@ -10,22 +9,19 @@ import { generateContext } from '../common/context/generateContext';
10
9
  */
11
10
  export function extractSmartLinkContext(response) {
12
11
  if (isEntityPresent(response)) {
13
- if (fg('platform_lp_use_generator_icon_for_provider')) {
14
- var _entityIcon$url, _entityIcon$label;
15
- const entityProvider = extractEntityProvider(response);
16
- if (!entityProvider) {
17
- return undefined;
18
- }
19
- const entityIcon = extractEntityIcon(response);
20
- return {
21
- ...entityProvider,
22
- icon: (_entityIcon$url = entityIcon === null || entityIcon === void 0 ? void 0 : entityIcon.url) !== null && _entityIcon$url !== void 0 ? _entityIcon$url : entityProvider.icon,
23
- iconLabel: (_entityIcon$label = entityIcon === null || entityIcon === void 0 ? void 0 : entityIcon.label) !== null && _entityIcon$label !== void 0 ? _entityIcon$label : entityProvider.iconLabel,
24
- providerIcon: entityProvider.icon,
25
- providerIconLabel: entityProvider.iconLabel
26
- };
12
+ var _entityIcon$url, _entityIcon$label;
13
+ const entityProvider = extractEntityProvider(response);
14
+ if (!entityProvider) {
15
+ return undefined;
27
16
  }
28
- return extractEntityProvider(response);
17
+ const entityIcon = extractEntityIcon(response);
18
+ return {
19
+ ...entityProvider,
20
+ icon: (_entityIcon$url = entityIcon === null || entityIcon === void 0 ? void 0 : entityIcon.url) !== null && _entityIcon$url !== void 0 ? _entityIcon$url : entityProvider.icon,
21
+ iconLabel: (_entityIcon$label = entityIcon === null || entityIcon === void 0 ? void 0 : entityIcon.label) !== null && _entityIcon$label !== void 0 ? _entityIcon$label : entityProvider.iconLabel,
22
+ providerIcon: entityProvider.icon,
23
+ providerIconLabel: entityProvider.iconLabel
24
+ };
29
25
  }
30
26
  return generateContext((response === null || response === void 0 ? void 0 : response.data) || getEmptyJsonLd());
31
27
  }
@@ -4,7 +4,7 @@ export const ANALYTICS_CHANNEL = 'media';
4
4
  export const context = {
5
5
  componentName: 'smart-cards',
6
6
  packageName: "@atlaskit/smart-card" || '',
7
- packageVersion: "46.14.6" || ''
7
+ packageVersion: "46.16.0" || ''
8
8
  };
9
9
  export let TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
10
10
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -33,7 +33,6 @@ const CardErrorBoundaryNew = ({
33
33
  const {
34
34
  appearance,
35
35
  id,
36
- onError,
37
36
  url
38
37
  } = props;
39
38
  const ErrorFallbackComponent = props.fallbackComponent;
@@ -46,58 +45,64 @@ const CardErrorBoundaryNew = ({
46
45
  const store = smartCardContext === null || smartCardContext === void 0 ? void 0 : smartCardContext.store;
47
46
  const display = isFlexibleCard ? 'flexible' : appearance;
48
47
 
49
- // Parity with CardWithURLRenderer error handler
48
+ // Analytics parity with CardWithURLRenderer only. Preserve CardSSR's local error
49
+ // containment: forwarding caught errors to the consumer can cause a rethrow.
50
50
  const errorHandler = useCallback((error, info) => {
51
- const {
52
- componentStack
53
- } = info;
54
- const errorInfo = {
55
- componentStack
56
- };
57
- // Read the link state when the error happens: useSmartCardContext does not subscribe
58
- // to store updates, so a value captured during render can be stale by now.
59
- const state = store ? getUrl(store, url) : undefined;
60
- const analyticsContext = getSmartLinkAnalyticsContext({
61
- display,
62
- id,
63
- response: state === null || state === void 0 ? void 0 : state.details,
64
- status: state === null || state === void 0 ? void 0 : state.status,
65
- url,
66
- error: state === null || state === void 0 ? void 0 : state.error
67
- });
68
- // NB: APIErrors are thrown in response to Object Resolver Service. We do not
69
- // fire an event for these, as they do not cover failed UI render events.
70
- // The rest of the errors caught here are unexpected, and correlate
71
- // to the reliability of the smart-card front-end components.
72
- // Likewise, chunk loading errors are not caused by a failure of smart-card rendering.
73
- if (error.name === 'ChunkLoadError') {
74
- fireEvent('operational.smartLink.chunkLoadFailed', {
75
- ...(analyticsContext === null || analyticsContext === void 0 ? void 0 : analyticsContext.attributes),
76
- display,
77
- error: error,
78
- errorInfo: errorInfo,
79
- definitionId: null
80
- });
81
- } else if (error.name !== 'APIError') {
82
- startUfoExperience('smart-link-rendered', id, {
83
- ssr: true
84
- });
85
- failUfoExperience('smart-link-rendered', id);
86
- failUfoExperience('smart-link-authenticated', id);
87
- fireEvent('ui.smartLink.renderFailed', {
88
- ...(analyticsContext === null || analyticsContext === void 0 ? void 0 : analyticsContext.attributes),
51
+ try {
52
+ // Error inspection and diagnostics must never break the local fallback.
53
+ const errorName = error !== null && typeof error === 'object' && 'name' in error ? error.name : undefined;
54
+ // Resolver API errors do not represent failed UI renders.
55
+ if (errorName === 'APIError') {
56
+ return;
57
+ }
58
+ const {
59
+ componentStack
60
+ } = info;
61
+ const errorInfo = {
62
+ componentStack
63
+ };
64
+ // Read the link state when the error happens: useSmartCardContext does not subscribe
65
+ // to store updates, so a value captured during render can be stale by now.
66
+ const state = store ? getUrl(store, url) : undefined;
67
+ const analyticsContext = getSmartLinkAnalyticsContext({
89
68
  display,
90
69
  id,
91
- error: error,
92
- errorInfo: errorInfo
70
+ response: state === null || state === void 0 ? void 0 : state.details,
71
+ status: state === null || state === void 0 ? void 0 : state.status,
72
+ url,
73
+ error: state === null || state === void 0 ? void 0 : state.error
93
74
  });
75
+ // NB: APIErrors are thrown in response to Object Resolver Service. We do not
76
+ // fire an event for these, as they do not cover failed UI render events.
77
+ // The rest of the errors caught here are unexpected, and correlate
78
+ // to the reliability of the smart-card front-end components.
79
+ // Likewise, chunk loading errors are not caused by a failure of smart-card rendering.
80
+ if (errorName === 'ChunkLoadError') {
81
+ fireEvent('operational.smartLink.chunkLoadFailed', {
82
+ ...(analyticsContext === null || analyticsContext === void 0 ? void 0 : analyticsContext.attributes),
83
+ display,
84
+ error: error,
85
+ errorInfo: errorInfo,
86
+ definitionId: null
87
+ });
88
+ } else {
89
+ startUfoExperience('smart-link-rendered', id, {
90
+ ssr: true
91
+ });
92
+ failUfoExperience('smart-link-rendered', id);
93
+ failUfoExperience('smart-link-authenticated', id);
94
+ fireEvent('ui.smartLink.renderFailed', {
95
+ ...(analyticsContext === null || analyticsContext === void 0 ? void 0 : analyticsContext.attributes),
96
+ display,
97
+ id,
98
+ error: error,
99
+ errorInfo: errorInfo
100
+ });
101
+ }
102
+ } catch {
103
+ // Best-effort diagnostics must not escape the card error boundary.
94
104
  }
95
- onError && onError({
96
- status: 'errored',
97
- url,
98
- err: error
99
- });
100
- }, [display, fireEvent, id, onError, store, url]);
105
+ }, [display, fireEvent, id, store, url]);
101
106
  const errorBoundaryFallbackComponent = () => {
102
107
  if (ErrorFallbackComponent) {
103
108
  return /*#__PURE__*/React.createElement(ErrorFallbackComponent, null);
@@ -4,7 +4,6 @@ import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { useMemo } from 'react';
5
5
  import Heading from '@atlaskit/heading/heading';
6
6
  import LinkGlyph from '@atlaskit/icon/core/link';
7
- import { fg } from '@atlaskit/platform-feature-flags/fg';
8
7
  import { Text } from '@atlaskit/primitives/compiled/text';
9
8
  import { ExpandedFrame } from '../../components/ExpandedFrame';
10
9
  import { ImageIcon } from '../../components/ImageIcon';
@@ -29,7 +28,7 @@ const UnresolvedView = ({
29
28
  }) => {
30
29
  // Unresolved embeds have no entity title. The frame shows the provider name, so
31
30
  // pair it with the provider/generator icon rather than the entity-type icon.
32
- const shouldUseProviderIcon = providerIcon != null && fg('platform_lp_use_generator_icon_for_provider');
31
+ const shouldUseProviderIcon = providerIcon != null;
33
32
  const frameIconUrlOrElement = shouldUseProviderIcon ? providerIcon : iconUrlOrElement;
34
33
  const frameIconLabel = shouldUseProviderIcon ? providerIconLabel : undefined;
35
34
  const icon = useMemo(() => {
@@ -9,7 +9,7 @@ import LinkWarningModal from './LinkWarningModal';
9
9
  import { useLinkWarningModal } from './LinkWarningModal/hooks/use-link-warning-modal';
10
10
  const PACKAGE_DATA = {
11
11
  packageName: "@atlaskit/smart-card",
12
- packageVersion: "46.14.6",
12
+ packageVersion: "46.16.0",
13
13
  componentName: 'linkUrl'
14
14
  };
15
15
  const LinkUrl = ({
@@ -2,31 +2,26 @@
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
3
  import "./index.compiled.css";
4
4
  import { ax, ix } from "@compiled/react/runtime";
5
- import React, { lazy, Suspense, useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
+ import React, { lazy, Suspense, useEffect } from 'react';
6
+ import { ErrorBoundary } from 'react-error-boundary';
6
7
  import { defineMessages, FormattedMessage } from 'react-intl';
7
8
  import Button from '@atlaskit/button/default/button';
8
9
  import Heading from '@atlaskit/heading/heading';
9
- import { extractSmartLinkProvider } from '@atlaskit/link-extractors/extract-smart-link-provider';
10
+ import { ChoreographedContent } from '@atlaskit/link-provider/choreographed-content';
10
11
  import ModalBody from '@atlaskit/modal-dialog/modal-body';
11
12
  import Modal from '@atlaskit/modal-dialog/modal-dialog';
12
13
  import ModalTitle from '@atlaskit/modal-dialog/modal-title';
13
14
  import ModalTransition from '@atlaskit/modal-dialog/modal-transition';
14
- import { expVal } from '@atlaskit/platform-feature-experiments/exp-val';
15
15
  import { Box } from '@atlaskit/primitives/compiled/box';
16
16
  import { Flex } from '@atlaskit/primitives/compiled/flex';
17
17
  import { Stack } from '@atlaskit/primitives/compiled/stack';
18
18
  import { Text } from '@atlaskit/primitives/compiled/text';
19
- import { useAnalyticsEvents } from '../../common/analytics/generated/use-analytics-events';
20
19
  import { messages as smartCardMessages } from '../../messages';
21
- import { getExtensionKey, getServices } from '../../state/helpers';
22
- import useSocialProof from '../../state/hooks/use-social-proof';
23
- import { useSmartLink } from '../../state/hooks/useSmartLink';
24
- import { preAuthValuePropositionModalService } from '../../state/services/pre-auth-value-proposition-modal';
25
20
  import { SmartLinkAnalyticsContext } from '../../utils/analytics/SmartLinkAnalyticsContext';
26
21
  import ImageIcon from '../common/image-icon';
22
+ import { SMART_LINK_MODAL_ID, usePreAuthValuePropositionModal } from './use-pre-auth-value-proposition-modal';
27
23
  const IllustrationPane = /*#__PURE__*/lazy(() => import( /* webpackChunkName: "@atlaskit-internal_smart-card-pre-auth-value-proposition-illustration" */'./IllustrationPane'));
28
24
  const SOCIAL_PROOF_TEAM_PREVIEW_THRESHOLD = 30;
29
- const SMART_LINK_MODAL_ID = 'pre-auth-value-proposition-modal';
30
25
  const messages = defineMessages({
31
26
  close: {
32
27
  id: 'smart-card.view.PreAuthValuePropositionModal.close',
@@ -72,7 +67,6 @@ const styles = {
72
67
  const bold = chunks => /*#__PURE__*/React.createElement(Text, {
73
68
  as: "strong"
74
69
  }, chunks);
75
- const getModalCloseMethod = event => 'key' in event && event.key === 'Escape' ? 'escape' : 'overlay';
76
70
  const ModalCopy = ({
77
71
  connectedPct,
78
72
  isSocialProofAvailable,
@@ -165,33 +159,25 @@ const ModalCopy = ({
165
159
  onClick: onClose
166
160
  }, /*#__PURE__*/React.createElement(FormattedMessage, messages.close))))));
167
161
  };
168
- const PreAuthValuePropositionModalContent = ({
169
- onFinished,
170
- onOpenChange,
171
- url
162
+
163
+ /** Mounted only while the existing choreographer grants permission. */
164
+ const ModalContent = ({
165
+ provider,
166
+ variant,
167
+ connectedPct,
168
+ isSocialProofAvailable,
169
+ onClose,
170
+ onCloseButton,
171
+ onConnect,
172
+ onOpenComplete,
173
+ onOpenChange
172
174
  }) => {
173
175
  var _provider$iconLabel;
174
- const {
175
- actions,
176
- config,
177
- state
178
- } = useSmartLink(SMART_LINK_MODAL_ID, url, 'inline');
179
- const {
180
- fireEvent
181
- } = useAnalyticsEvents();
182
- const [isOpen, setIsOpen] = useState(false);
183
- const [visibleVariant, setVisibleVariant] = useState('modal_text_only');
184
- const modalOpenTimeRef = useRef(Date.now());
185
- const provider = useMemo(() => extractSmartLinkProvider(state.details), [state.details]);
186
- const providerName = provider === null || provider === void 0 ? void 0 : provider.text;
187
- const isVisible = isOpen && Boolean(providerName);
188
176
  useEffect(() => {
189
- if (!isVisible) {
190
- return;
191
- }
192
177
  onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(true);
193
178
  return () => onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(false);
194
- }, [isVisible, onOpenChange]);
179
+ }, [onOpenChange]);
180
+ const providerName = provider === null || provider === void 0 ? void 0 : provider.text;
195
181
  const providerIconUrl = typeof (provider === null || provider === void 0 ? void 0 : provider.icon) === 'string' ? provider.icon : undefined;
196
182
  const renderProviderIcon = (size, testId, label) => {
197
183
  if (providerIconUrl) {
@@ -208,70 +194,18 @@ const PreAuthValuePropositionModalContent = ({
208
194
  return provider === null || provider === void 0 ? void 0 : provider.icon;
209
195
  };
210
196
  const providerIcon = renderProviderIcon(24, 'pre-auth-value-proposition-modal-provider-icon', (_provider$iconLabel = provider === null || provider === void 0 ? void 0 : provider.iconLabel) !== null && _provider$iconLabel !== void 0 ? _provider$iconLabel : providerName);
211
- const services = getServices(state.details);
212
- const extensionKey = getExtensionKey(state.details);
213
- const {
214
- connectedPct,
215
- isEnabled: isSocialProofAvailable
216
- } = useSocialProof(extensionKey, true);
217
- const hasSupportedAuthorization = (config === null || config === void 0 ? void 0 : config.authFlow) !== 'disabled' && services.length > 0;
218
- const isBaseEligible = state.status === 'unauthorized' && Boolean(providerName) && Boolean(extensionKey) && hasSupportedAuthorization;
219
- useEffect(() => {
220
- if (state.status === 'pending' || state.status === 'resolving') {
221
- return;
222
- }
223
- if (!isBaseEligible || !extensionKey || preAuthValuePropositionModalService.hasReachedShowLimit(extensionKey)) {
224
- onFinished();
225
- return;
226
- }
227
- const experimentVariant = expVal('platform_sl_3p_preauth_value_modal', 'variant', 'control');
228
- if (experimentVariant === 'modal_text_only' || experimentVariant === 'modal_with_image') {
229
- preAuthValuePropositionModalService.recordShow(extensionKey);
230
- setVisibleVariant(experimentVariant);
231
- setIsOpen(true);
232
- return;
233
- }
234
- onFinished();
235
- }, [extensionKey, isBaseEligible, onFinished, state.status]);
236
- const dismissModal = useCallback(closeMethod => {
237
- fireEvent('ui.modal.closed.preAuthValueProposition', {
238
- closeMethod,
239
- dwellTime: Date.now() - modalOpenTimeRef.current
240
- });
241
- setIsOpen(false);
242
- onFinished();
243
- }, [fireEvent, onFinished]);
244
- const handleCloseButton = useCallback(() => {
245
- dismissModal('button');
246
- }, [dismissModal]);
247
- const handleModalClose = useCallback(event => {
248
- dismissModal(getModalCloseMethod(event));
249
- }, [dismissModal]);
250
- const handleOpenComplete = useCallback(() => {
251
- modalOpenTimeRef.current = Date.now();
252
- fireEvent('ui.modal.opened.preAuthValueProposition', {});
253
- }, [fireEvent]);
254
- const connectAccount = useCallback(() => {
255
- fireEvent('track.applicationAccount.authStarted', {});
256
- setIsOpen(false);
257
- actions.authorize('inline');
258
- onFinished();
259
- }, [actions, fireEvent, onFinished]);
260
- if (!isOpen || !providerName) {
261
- return null;
262
- }
263
197
  const modalCopy = /*#__PURE__*/React.createElement(ModalCopy, {
264
198
  connectedPct: connectedPct,
265
199
  isSocialProofAvailable: isSocialProofAvailable,
266
- onClose: handleCloseButton,
267
- onConnect: connectAccount,
200
+ onClose: onCloseButton,
201
+ onConnect: onConnect,
268
202
  providerIcon: providerIcon,
269
- providerName: providerName
203
+ providerName: providerName !== null && providerName !== void 0 ? providerName : ''
270
204
  });
271
- const showIllustration = visibleVariant === 'modal_with_image';
272
- return /*#__PURE__*/React.createElement(ModalTransition, null, /*#__PURE__*/React.createElement(Modal, {
273
- onClose: handleModalClose,
274
- onOpenComplete: handleOpenComplete,
205
+ const showIllustration = variant === 'modal_with_image';
206
+ const modal = providerName ? /*#__PURE__*/React.createElement(ModalTransition, null, /*#__PURE__*/React.createElement(Modal, {
207
+ onClose: onClose,
208
+ onOpenComplete: onOpenComplete,
275
209
  testId: "pre-auth-value-proposition-modal",
276
210
  width: showIllustration ? 800 : 400
277
211
  }, showIllustration ? /*#__PURE__*/React.createElement(Box, {
@@ -282,19 +216,37 @@ const PreAuthValuePropositionModalContent = ({
282
216
  fallback: null
283
217
  }, /*#__PURE__*/React.createElement(IllustrationPane, {
284
218
  renderProviderIcon: renderProviderIcon
285
- }))) : modalCopy));
219
+ }))) : modalCopy)) : null;
220
+ return modal;
286
221
  };
287
- export const PreAuthValuePropositionModal = ({
288
- onFinished,
222
+ const PreAuthValuePropositionModalContent = ({
289
223
  onOpenChange,
290
- url
291
- }) => /*#__PURE__*/React.createElement(SmartLinkAnalyticsContext, {
224
+ ...options
225
+ }) => {
226
+ const {
227
+ isActive,
228
+ isEligible,
229
+ onUnavailable,
230
+ shouldClaim,
231
+ modal
232
+ } = usePreAuthValuePropositionModal(options);
233
+ return /*#__PURE__*/React.createElement(ChoreographedContent, {
234
+ messageId: "smart-link-pre-auth-value-proposition-modal",
235
+ isActive: isActive,
236
+ onUnavailable: onUnavailable,
237
+ shouldClaim: shouldClaim
238
+ }, ({
239
+ hasPermission
240
+ }) => hasPermission && isEligible ? /*#__PURE__*/React.createElement(ErrorBoundary, {
241
+ fallback: null,
242
+ onError: onUnavailable
243
+ }, /*#__PURE__*/React.createElement(ModalContent, _extends({}, modal, {
244
+ onOpenChange: onOpenChange
245
+ }))) : null);
246
+ };
247
+ export const PreAuthValuePropositionModal = props => /*#__PURE__*/React.createElement(SmartLinkAnalyticsContext, {
292
248
  display: "inline",
293
249
  id: SMART_LINK_MODAL_ID,
294
250
  source: "preAuthValuePropositionModal",
295
- url: url
296
- }, /*#__PURE__*/React.createElement(PreAuthValuePropositionModalContent, {
297
- onFinished: onFinished,
298
- onOpenChange: onOpenChange,
299
- url: url
300
- }));
251
+ url: props.url
252
+ }, /*#__PURE__*/React.createElement(PreAuthValuePropositionModalContent, props));