@atlaskit/smart-card 46.15.0 → 46.16.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.
- package/CHANGELOG.md +17 -0
- package/analytics.spec.yaml +2 -2
- package/dist/cjs/utils/analytics/analytics.js +1 -1
- package/dist/cjs/view/LinkUrl/index.js +1 -1
- package/dist/cjs/view/PreAuthValuePropositionModal/index.js +56 -110
- package/dist/cjs/view/PreAuthValuePropositionModal/use-pre-auth-value-proposition-modal.js +175 -0
- package/dist/es2019/utils/analytics/analytics.js +1 -1
- package/dist/es2019/view/LinkUrl/index.js +1 -1
- package/dist/es2019/view/PreAuthValuePropositionModal/index.js +54 -102
- package/dist/es2019/view/PreAuthValuePropositionModal/use-pre-auth-value-proposition-modal.js +160 -0
- package/dist/esm/utils/analytics/analytics.js +1 -1
- package/dist/esm/view/LinkUrl/index.js +1 -1
- package/dist/esm/view/PreAuthValuePropositionModal/index.js +56 -110
- package/dist/esm/view/PreAuthValuePropositionModal/use-pre-auth-value-proposition-modal.js +167 -0
- package/dist/types/common/analytics/generated/analytics.types.d.ts +2 -2
- package/dist/types/view/PreAuthValuePropositionModal/index.d.ts +1 -1
- package/dist/types/view/PreAuthValuePropositionModal/use-pre-auth-value-proposition-modal.d.ts +31 -0
- package/package.json +6 -4
|
@@ -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,
|
|
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 {
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
}, [
|
|
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:
|
|
267
|
-
onConnect:
|
|
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 =
|
|
272
|
-
|
|
273
|
-
onClose:
|
|
274
|
-
onOpenComplete:
|
|
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
|
-
|
|
288
|
-
onFinished,
|
|
222
|
+
const PreAuthValuePropositionModalContent = ({
|
|
289
223
|
onOpenChange,
|
|
290
|
-
|
|
291
|
-
}) =>
|
|
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));
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { extractSmartLinkProvider } from '@atlaskit/link-extractors/extract-smart-link-provider';
|
|
3
|
+
import { expVal } from '@atlaskit/platform-feature-experiments/exp-val';
|
|
4
|
+
import { useAnalyticsEvents } from '../../common/analytics/generated/use-analytics-events';
|
|
5
|
+
import { getExtensionKey, getServices } from '../../state/helpers';
|
|
6
|
+
import useSocialProof from '../../state/hooks/use-social-proof';
|
|
7
|
+
import { useSmartLink } from '../../state/hooks/useSmartLink';
|
|
8
|
+
import { preAuthValuePropositionModalService } from '../../state/services/pre-auth-value-proposition-modal';
|
|
9
|
+
export const SMART_LINK_MODAL_ID = 'pre-auth-value-proposition-modal';
|
|
10
|
+
const getModalCloseMethod = event => 'key' in event && event.key === 'Escape' ? 'escape' : 'overlay';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Eligibility, assignment and modal actions for one URL attempt.
|
|
14
|
+
* The existing choreographer adapter owns display permission and cleanup.
|
|
15
|
+
*/
|
|
16
|
+
export function usePreAuthValuePropositionModal({
|
|
17
|
+
url,
|
|
18
|
+
onFinished
|
|
19
|
+
}) {
|
|
20
|
+
const {
|
|
21
|
+
actions,
|
|
22
|
+
config,
|
|
23
|
+
state
|
|
24
|
+
} = useSmartLink(SMART_LINK_MODAL_ID, url, 'inline');
|
|
25
|
+
const {
|
|
26
|
+
fireEvent
|
|
27
|
+
} = useAnalyticsEvents();
|
|
28
|
+
const [isRequested, setIsRequested] = useState(false);
|
|
29
|
+
const finished = useRef(false);
|
|
30
|
+
const hasOpened = useRef(false);
|
|
31
|
+
const hasRecordedShow = useRef(false);
|
|
32
|
+
const [visibleVariant, setVisibleVariant] = useState('modal_text_only');
|
|
33
|
+
const modalOpenTimeRef = useRef(Date.now());
|
|
34
|
+
const provider = useMemo(() => extractSmartLinkProvider(state.details), [state.details]);
|
|
35
|
+
const providerName = provider === null || provider === void 0 ? void 0 : provider.text;
|
|
36
|
+
const services = getServices(state.details);
|
|
37
|
+
const extensionKey = getExtensionKey(state.details);
|
|
38
|
+
const {
|
|
39
|
+
connectedPct,
|
|
40
|
+
isEnabled: isSocialProofAvailable
|
|
41
|
+
} = useSocialProof(extensionKey, true);
|
|
42
|
+
const hasSupportedAuthorization = (config === null || config === void 0 ? void 0 : config.authFlow) !== 'disabled' && services.length > 0;
|
|
43
|
+
const isBaseEligible = state.status === 'unauthorized' && Boolean(providerName) && Boolean(extensionKey) && hasSupportedAuthorization;
|
|
44
|
+
const finishCoordinatedAttempt = useCallback(() => {
|
|
45
|
+
if (finished.current) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
finished.current = true;
|
|
49
|
+
setIsRequested(false);
|
|
50
|
+
onFinished();
|
|
51
|
+
}, [onFinished]);
|
|
52
|
+
const handleUnavailable = useCallback(() => {
|
|
53
|
+
if (finished.current) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (hasOpened.current) {
|
|
57
|
+
fireEvent('ui.modal.closed.preAuthValueProposition', {
|
|
58
|
+
closeMethod: 'coordinator',
|
|
59
|
+
dwellTime: Date.now() - modalOpenTimeRef.current
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
finishCoordinatedAttempt();
|
|
63
|
+
}, [fireEvent, finishCoordinatedAttempt]);
|
|
64
|
+
const shouldClaim = useCallback(() => {
|
|
65
|
+
// Recheck at offer time: another attempt may have consumed the cap while we waited.
|
|
66
|
+
if (finished.current || !isBaseEligible || !extensionKey || preAuthValuePropositionModalService.hasReachedShowLimit(extensionKey)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const variant = expVal('platform_sl_3p_preauth_value_modal', 'variant', 'control');
|
|
70
|
+
if (variant !== 'modal_text_only' && variant !== 'modal_with_image') {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
setVisibleVariant(variant);
|
|
74
|
+
return true;
|
|
75
|
+
}, [extensionKey, isBaseEligible]);
|
|
76
|
+
|
|
77
|
+
// The editor mounts this flow only when platform_sl_3p_preauth_value_modal_killswitch is on.
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (finished.current) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (state.status === 'pending' || state.status === 'resolving') {
|
|
83
|
+
// A previously eligible link that starts resolving again must release its slot.
|
|
84
|
+
if (isRequested) {
|
|
85
|
+
handleUnavailable();
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!isBaseEligible || !extensionKey) {
|
|
90
|
+
handleUnavailable();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (!isRequested) {
|
|
94
|
+
if (preAuthValuePropositionModalService.hasReachedShowLimit(extensionKey)) {
|
|
95
|
+
finishCoordinatedAttempt();
|
|
96
|
+
} else {
|
|
97
|
+
setIsRequested(true);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}, [extensionKey, isBaseEligible, state.status, isRequested, handleUnavailable, finishCoordinatedAttempt]);
|
|
101
|
+
const recordShowOnce = useCallback(() => {
|
|
102
|
+
if (hasRecordedShow.current || !extensionKey) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
hasRecordedShow.current = true;
|
|
106
|
+
preAuthValuePropositionModalService.recordShow(extensionKey);
|
|
107
|
+
}, [extensionKey]);
|
|
108
|
+
const dismissModal = useCallback(closeMethod => {
|
|
109
|
+
if (finished.current) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
// A user can dismiss the visible modal before its entrance animation completes.
|
|
113
|
+
recordShowOnce();
|
|
114
|
+
fireEvent('ui.modal.closed.preAuthValueProposition', {
|
|
115
|
+
closeMethod,
|
|
116
|
+
dwellTime: Date.now() - modalOpenTimeRef.current
|
|
117
|
+
});
|
|
118
|
+
finishCoordinatedAttempt();
|
|
119
|
+
}, [fireEvent, finishCoordinatedAttempt, recordShowOnce]);
|
|
120
|
+
const handleCloseButton = useCallback(() => {
|
|
121
|
+
dismissModal('button');
|
|
122
|
+
}, [dismissModal]);
|
|
123
|
+
const handleModalClose = useCallback(event => {
|
|
124
|
+
dismissModal(getModalCloseMethod(event));
|
|
125
|
+
}, [dismissModal]);
|
|
126
|
+
const handleOpenComplete = useCallback(() => {
|
|
127
|
+
if (finished.current || hasOpened.current || !extensionKey) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
hasOpened.current = true;
|
|
131
|
+
recordShowOnce();
|
|
132
|
+
modalOpenTimeRef.current = Date.now();
|
|
133
|
+
fireEvent('ui.modal.opened.preAuthValueProposition', {});
|
|
134
|
+
}, [fireEvent, extensionKey, recordShowOnce]);
|
|
135
|
+
const connectAccount = useCallback(() => {
|
|
136
|
+
if (finished.current) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
recordShowOnce();
|
|
140
|
+
fireEvent('track.applicationAccount.authStarted', {});
|
|
141
|
+
finishCoordinatedAttempt();
|
|
142
|
+
actions.authorize('inline');
|
|
143
|
+
}, [actions, fireEvent, finishCoordinatedAttempt, recordShowOnce]);
|
|
144
|
+
return {
|
|
145
|
+
isActive: isRequested,
|
|
146
|
+
isEligible: isBaseEligible,
|
|
147
|
+
onUnavailable: handleUnavailable,
|
|
148
|
+
shouldClaim,
|
|
149
|
+
modal: {
|
|
150
|
+
provider,
|
|
151
|
+
variant: visibleVariant,
|
|
152
|
+
connectedPct,
|
|
153
|
+
isSocialProofAvailable,
|
|
154
|
+
onClose: handleModalClose,
|
|
155
|
+
onCloseButton: handleCloseButton,
|
|
156
|
+
onConnect: connectAccount,
|
|
157
|
+
onOpenComplete: handleOpenComplete
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
@@ -4,7 +4,7 @@ export var ANALYTICS_CHANNEL = 'media';
|
|
|
4
4
|
export var context = {
|
|
5
5
|
componentName: 'smart-cards',
|
|
6
6
|
packageName: "@atlaskit/smart-card" || '',
|
|
7
|
-
packageVersion: "46.
|
|
7
|
+
packageVersion: "46.15.0" || ''
|
|
8
8
|
};
|
|
9
9
|
export var TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
|
|
10
10
|
TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
|
|
@@ -12,7 +12,7 @@ import LinkWarningModal from './LinkWarningModal';
|
|
|
12
12
|
import { useLinkWarningModal } from './LinkWarningModal/hooks/use-link-warning-modal';
|
|
13
13
|
var PACKAGE_DATA = {
|
|
14
14
|
packageName: "@atlaskit/smart-card",
|
|
15
|
-
packageVersion: "46.
|
|
15
|
+
packageVersion: "46.15.0",
|
|
16
16
|
componentName: 'linkUrl'
|
|
17
17
|
};
|
|
18
18
|
var LinkUrl = function LinkUrl(_ref) {
|
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
/* index.tsx generated by @compiled/babel-plugin v3.0.4 */
|
|
2
|
-
import
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
import _extends from "@babel/runtime/helpers/extends";
|
|
4
|
+
var _excluded = ["onOpenChange"];
|
|
4
5
|
import "./index.compiled.css";
|
|
5
6
|
import { ax, ix } from "@compiled/react/runtime";
|
|
6
|
-
import React, { lazy, Suspense,
|
|
7
|
+
import React, { lazy, Suspense, useEffect } from 'react';
|
|
8
|
+
import { ErrorBoundary } from 'react-error-boundary';
|
|
7
9
|
import { defineMessages, FormattedMessage } from 'react-intl';
|
|
8
10
|
import Button from '@atlaskit/button/default/button';
|
|
9
11
|
import Heading from '@atlaskit/heading/heading';
|
|
10
|
-
import {
|
|
12
|
+
import { ChoreographedContent } from '@atlaskit/link-provider/choreographed-content';
|
|
11
13
|
import ModalBody from '@atlaskit/modal-dialog/modal-body';
|
|
12
14
|
import Modal from '@atlaskit/modal-dialog/modal-dialog';
|
|
13
15
|
import ModalTitle from '@atlaskit/modal-dialog/modal-title';
|
|
14
16
|
import ModalTransition from '@atlaskit/modal-dialog/modal-transition';
|
|
15
|
-
import { expVal } from '@atlaskit/platform-feature-experiments/exp-val';
|
|
16
17
|
import { Box } from '@atlaskit/primitives/compiled/box';
|
|
17
18
|
import { Flex } from '@atlaskit/primitives/compiled/flex';
|
|
18
19
|
import { Stack } from '@atlaskit/primitives/compiled/stack';
|
|
19
20
|
import { Text } from '@atlaskit/primitives/compiled/text';
|
|
20
|
-
import { useAnalyticsEvents } from '../../common/analytics/generated/use-analytics-events';
|
|
21
21
|
import { messages as smartCardMessages } from '../../messages';
|
|
22
|
-
import { getExtensionKey, getServices } from '../../state/helpers';
|
|
23
|
-
import useSocialProof from '../../state/hooks/use-social-proof';
|
|
24
|
-
import { useSmartLink } from '../../state/hooks/useSmartLink';
|
|
25
|
-
import { preAuthValuePropositionModalService } from '../../state/services/pre-auth-value-proposition-modal';
|
|
26
22
|
import { SmartLinkAnalyticsContext } from '../../utils/analytics/SmartLinkAnalyticsContext';
|
|
27
23
|
import ImageIcon from '../common/image-icon';
|
|
24
|
+
import { SMART_LINK_MODAL_ID, usePreAuthValuePropositionModal } from './use-pre-auth-value-proposition-modal';
|
|
28
25
|
var IllustrationPane = /*#__PURE__*/lazy(function () {
|
|
29
26
|
return import( /* webpackChunkName: "@atlaskit-internal_smart-card-pre-auth-value-proposition-illustration" */'./IllustrationPane');
|
|
30
27
|
});
|
|
31
28
|
var SOCIAL_PROOF_TEAM_PREVIEW_THRESHOLD = 30;
|
|
32
|
-
var SMART_LINK_MODAL_ID = 'pre-auth-value-proposition-modal';
|
|
33
29
|
var messages = defineMessages({
|
|
34
30
|
close: {
|
|
35
31
|
id: 'smart-card.view.PreAuthValuePropositionModal.close',
|
|
@@ -77,9 +73,6 @@ var bold = function bold(chunks) {
|
|
|
77
73
|
as: "strong"
|
|
78
74
|
}, chunks);
|
|
79
75
|
};
|
|
80
|
-
var getModalCloseMethod = function getModalCloseMethod(event) {
|
|
81
|
-
return 'key' in event && event.key === 'Escape' ? 'escape' : 'overlay';
|
|
82
|
-
};
|
|
83
76
|
var ModalCopy = function ModalCopy(_ref) {
|
|
84
77
|
var connectedPct = _ref.connectedPct,
|
|
85
78
|
isSocialProofAvailable = _ref.isSocialProofAvailable,
|
|
@@ -171,40 +164,26 @@ var ModalCopy = function ModalCopy(_ref) {
|
|
|
171
164
|
onClick: onClose
|
|
172
165
|
}, /*#__PURE__*/React.createElement(FormattedMessage, messages.close))))));
|
|
173
166
|
};
|
|
174
|
-
|
|
167
|
+
|
|
168
|
+
/** Mounted only while the existing choreographer grants permission. */
|
|
169
|
+
var ModalContent = function ModalContent(_ref2) {
|
|
175
170
|
var _provider$iconLabel;
|
|
176
|
-
var
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
var _useState = useState(false),
|
|
186
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
187
|
-
isOpen = _useState2[0],
|
|
188
|
-
setIsOpen = _useState2[1];
|
|
189
|
-
var _useState3 = useState('modal_text_only'),
|
|
190
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
191
|
-
visibleVariant = _useState4[0],
|
|
192
|
-
setVisibleVariant = _useState4[1];
|
|
193
|
-
var modalOpenTimeRef = useRef(Date.now());
|
|
194
|
-
var provider = useMemo(function () {
|
|
195
|
-
return extractSmartLinkProvider(state.details);
|
|
196
|
-
}, [state.details]);
|
|
197
|
-
var providerName = provider === null || provider === void 0 ? void 0 : provider.text;
|
|
198
|
-
var isVisible = isOpen && Boolean(providerName);
|
|
171
|
+
var provider = _ref2.provider,
|
|
172
|
+
variant = _ref2.variant,
|
|
173
|
+
connectedPct = _ref2.connectedPct,
|
|
174
|
+
isSocialProofAvailable = _ref2.isSocialProofAvailable,
|
|
175
|
+
onClose = _ref2.onClose,
|
|
176
|
+
onCloseButton = _ref2.onCloseButton,
|
|
177
|
+
onConnect = _ref2.onConnect,
|
|
178
|
+
onOpenComplete = _ref2.onOpenComplete,
|
|
179
|
+
onOpenChange = _ref2.onOpenChange;
|
|
199
180
|
useEffect(function () {
|
|
200
|
-
if (!isVisible) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
181
|
onOpenChange === null || onOpenChange === void 0 || onOpenChange(true);
|
|
204
182
|
return function () {
|
|
205
183
|
return onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(false);
|
|
206
184
|
};
|
|
207
|
-
}, [
|
|
185
|
+
}, [onOpenChange]);
|
|
186
|
+
var providerName = provider === null || provider === void 0 ? void 0 : provider.text;
|
|
208
187
|
var providerIconUrl = typeof (provider === null || provider === void 0 ? void 0 : provider.icon) === 'string' ? provider.icon : undefined;
|
|
209
188
|
var renderProviderIcon = function renderProviderIcon(size, testId, label) {
|
|
210
189
|
if (providerIconUrl) {
|
|
@@ -221,69 +200,18 @@ var PreAuthValuePropositionModalContent = function PreAuthValuePropositionModalC
|
|
|
221
200
|
return provider === null || provider === void 0 ? void 0 : provider.icon;
|
|
222
201
|
};
|
|
223
202
|
var 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);
|
|
224
|
-
var services = getServices(state.details);
|
|
225
|
-
var extensionKey = getExtensionKey(state.details);
|
|
226
|
-
var _useSocialProof = useSocialProof(extensionKey, true),
|
|
227
|
-
connectedPct = _useSocialProof.connectedPct,
|
|
228
|
-
isSocialProofAvailable = _useSocialProof.isEnabled;
|
|
229
|
-
var hasSupportedAuthorization = (config === null || config === void 0 ? void 0 : config.authFlow) !== 'disabled' && services.length > 0;
|
|
230
|
-
var isBaseEligible = state.status === 'unauthorized' && Boolean(providerName) && Boolean(extensionKey) && hasSupportedAuthorization;
|
|
231
|
-
useEffect(function () {
|
|
232
|
-
if (state.status === 'pending' || state.status === 'resolving') {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
if (!isBaseEligible || !extensionKey || preAuthValuePropositionModalService.hasReachedShowLimit(extensionKey)) {
|
|
236
|
-
onFinished();
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
var experimentVariant = expVal('platform_sl_3p_preauth_value_modal', 'variant', 'control');
|
|
240
|
-
if (experimentVariant === 'modal_text_only' || experimentVariant === 'modal_with_image') {
|
|
241
|
-
preAuthValuePropositionModalService.recordShow(extensionKey);
|
|
242
|
-
setVisibleVariant(experimentVariant);
|
|
243
|
-
setIsOpen(true);
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
onFinished();
|
|
247
|
-
}, [extensionKey, isBaseEligible, onFinished, state.status]);
|
|
248
|
-
var dismissModal = useCallback(function (closeMethod) {
|
|
249
|
-
fireEvent('ui.modal.closed.preAuthValueProposition', {
|
|
250
|
-
closeMethod: closeMethod,
|
|
251
|
-
dwellTime: Date.now() - modalOpenTimeRef.current
|
|
252
|
-
});
|
|
253
|
-
setIsOpen(false);
|
|
254
|
-
onFinished();
|
|
255
|
-
}, [fireEvent, onFinished]);
|
|
256
|
-
var handleCloseButton = useCallback(function () {
|
|
257
|
-
dismissModal('button');
|
|
258
|
-
}, [dismissModal]);
|
|
259
|
-
var handleModalClose = useCallback(function (event) {
|
|
260
|
-
dismissModal(getModalCloseMethod(event));
|
|
261
|
-
}, [dismissModal]);
|
|
262
|
-
var handleOpenComplete = useCallback(function () {
|
|
263
|
-
modalOpenTimeRef.current = Date.now();
|
|
264
|
-
fireEvent('ui.modal.opened.preAuthValueProposition', {});
|
|
265
|
-
}, [fireEvent]);
|
|
266
|
-
var connectAccount = useCallback(function () {
|
|
267
|
-
fireEvent('track.applicationAccount.authStarted', {});
|
|
268
|
-
setIsOpen(false);
|
|
269
|
-
actions.authorize('inline');
|
|
270
|
-
onFinished();
|
|
271
|
-
}, [actions, fireEvent, onFinished]);
|
|
272
|
-
if (!isOpen || !providerName) {
|
|
273
|
-
return null;
|
|
274
|
-
}
|
|
275
203
|
var modalCopy = /*#__PURE__*/React.createElement(ModalCopy, {
|
|
276
204
|
connectedPct: connectedPct,
|
|
277
205
|
isSocialProofAvailable: isSocialProofAvailable,
|
|
278
|
-
onClose:
|
|
279
|
-
onConnect:
|
|
206
|
+
onClose: onCloseButton,
|
|
207
|
+
onConnect: onConnect,
|
|
280
208
|
providerIcon: providerIcon,
|
|
281
|
-
providerName: providerName
|
|
209
|
+
providerName: providerName !== null && providerName !== void 0 ? providerName : ''
|
|
282
210
|
});
|
|
283
|
-
var showIllustration =
|
|
284
|
-
|
|
285
|
-
onClose:
|
|
286
|
-
onOpenComplete:
|
|
211
|
+
var showIllustration = variant === 'modal_with_image';
|
|
212
|
+
var modal = providerName ? /*#__PURE__*/React.createElement(ModalTransition, null, /*#__PURE__*/React.createElement(Modal, {
|
|
213
|
+
onClose: onClose,
|
|
214
|
+
onOpenComplete: onOpenComplete,
|
|
287
215
|
testId: "pre-auth-value-proposition-modal",
|
|
288
216
|
width: showIllustration ? 800 : 400
|
|
289
217
|
}, showIllustration ? /*#__PURE__*/React.createElement(Box, {
|
|
@@ -294,20 +222,38 @@ var PreAuthValuePropositionModalContent = function PreAuthValuePropositionModalC
|
|
|
294
222
|
fallback: null
|
|
295
223
|
}, /*#__PURE__*/React.createElement(IllustrationPane, {
|
|
296
224
|
renderProviderIcon: renderProviderIcon
|
|
297
|
-
}))) : modalCopy));
|
|
225
|
+
}))) : modalCopy)) : null;
|
|
226
|
+
return modal;
|
|
227
|
+
};
|
|
228
|
+
var PreAuthValuePropositionModalContent = function PreAuthValuePropositionModalContent(_ref3) {
|
|
229
|
+
var onOpenChange = _ref3.onOpenChange,
|
|
230
|
+
options = _objectWithoutProperties(_ref3, _excluded);
|
|
231
|
+
var _usePreAuthValuePropo = usePreAuthValuePropositionModal(options),
|
|
232
|
+
isActive = _usePreAuthValuePropo.isActive,
|
|
233
|
+
isEligible = _usePreAuthValuePropo.isEligible,
|
|
234
|
+
onUnavailable = _usePreAuthValuePropo.onUnavailable,
|
|
235
|
+
shouldClaim = _usePreAuthValuePropo.shouldClaim,
|
|
236
|
+
modal = _usePreAuthValuePropo.modal;
|
|
237
|
+
return /*#__PURE__*/React.createElement(ChoreographedContent, {
|
|
238
|
+
messageId: "smart-link-pre-auth-value-proposition-modal",
|
|
239
|
+
isActive: isActive,
|
|
240
|
+
onUnavailable: onUnavailable,
|
|
241
|
+
shouldClaim: shouldClaim
|
|
242
|
+
}, function (_ref4) {
|
|
243
|
+
var hasPermission = _ref4.hasPermission;
|
|
244
|
+
return hasPermission && isEligible ? /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
245
|
+
fallback: null,
|
|
246
|
+
onError: onUnavailable
|
|
247
|
+
}, /*#__PURE__*/React.createElement(ModalContent, _extends({}, modal, {
|
|
248
|
+
onOpenChange: onOpenChange
|
|
249
|
+
}))) : null;
|
|
250
|
+
});
|
|
298
251
|
};
|
|
299
|
-
export var PreAuthValuePropositionModal = function PreAuthValuePropositionModal(
|
|
300
|
-
var onFinished = _ref3.onFinished,
|
|
301
|
-
onOpenChange = _ref3.onOpenChange,
|
|
302
|
-
url = _ref3.url;
|
|
252
|
+
export var PreAuthValuePropositionModal = function PreAuthValuePropositionModal(props) {
|
|
303
253
|
return /*#__PURE__*/React.createElement(SmartLinkAnalyticsContext, {
|
|
304
254
|
display: "inline",
|
|
305
255
|
id: SMART_LINK_MODAL_ID,
|
|
306
256
|
source: "preAuthValuePropositionModal",
|
|
307
|
-
url: url
|
|
308
|
-
}, /*#__PURE__*/React.createElement(PreAuthValuePropositionModalContent,
|
|
309
|
-
onFinished: onFinished,
|
|
310
|
-
onOpenChange: onOpenChange,
|
|
311
|
-
url: url
|
|
312
|
-
}));
|
|
257
|
+
url: props.url
|
|
258
|
+
}, /*#__PURE__*/React.createElement(PreAuthValuePropositionModalContent, props));
|
|
313
259
|
};
|