@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
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { extractSmartLinkProvider } from '@atlaskit/link-extractors/extract-smart-link-provider';
|
|
4
|
+
import { expVal } from '@atlaskit/platform-feature-experiments/exp-val';
|
|
5
|
+
import { useAnalyticsEvents } from '../../common/analytics/generated/use-analytics-events';
|
|
6
|
+
import { getExtensionKey, getServices } from '../../state/helpers';
|
|
7
|
+
import useSocialProof from '../../state/hooks/use-social-proof';
|
|
8
|
+
import { useSmartLink } from '../../state/hooks/useSmartLink';
|
|
9
|
+
import { preAuthValuePropositionModalService } from '../../state/services/pre-auth-value-proposition-modal';
|
|
10
|
+
export var SMART_LINK_MODAL_ID = 'pre-auth-value-proposition-modal';
|
|
11
|
+
var getModalCloseMethod = function getModalCloseMethod(event) {
|
|
12
|
+
return 'key' in event && event.key === 'Escape' ? 'escape' : 'overlay';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Eligibility, assignment and modal actions for one URL attempt.
|
|
17
|
+
* The existing choreographer adapter owns display permission and cleanup.
|
|
18
|
+
*/
|
|
19
|
+
export function usePreAuthValuePropositionModal(_ref) {
|
|
20
|
+
var url = _ref.url,
|
|
21
|
+
onFinished = _ref.onFinished;
|
|
22
|
+
var _useSmartLink = useSmartLink(SMART_LINK_MODAL_ID, url, 'inline'),
|
|
23
|
+
actions = _useSmartLink.actions,
|
|
24
|
+
config = _useSmartLink.config,
|
|
25
|
+
state = _useSmartLink.state;
|
|
26
|
+
var _useAnalyticsEvents = useAnalyticsEvents(),
|
|
27
|
+
fireEvent = _useAnalyticsEvents.fireEvent;
|
|
28
|
+
var _useState = useState(false),
|
|
29
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
+
isRequested = _useState2[0],
|
|
31
|
+
setIsRequested = _useState2[1];
|
|
32
|
+
var finished = useRef(false);
|
|
33
|
+
var hasOpened = useRef(false);
|
|
34
|
+
var hasRecordedShow = useRef(false);
|
|
35
|
+
var _useState3 = useState('modal_text_only'),
|
|
36
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
37
|
+
visibleVariant = _useState4[0],
|
|
38
|
+
setVisibleVariant = _useState4[1];
|
|
39
|
+
var modalOpenTimeRef = useRef(Date.now());
|
|
40
|
+
var provider = useMemo(function () {
|
|
41
|
+
return extractSmartLinkProvider(state.details);
|
|
42
|
+
}, [state.details]);
|
|
43
|
+
var providerName = provider === null || provider === void 0 ? void 0 : provider.text;
|
|
44
|
+
var services = getServices(state.details);
|
|
45
|
+
var extensionKey = getExtensionKey(state.details);
|
|
46
|
+
var _useSocialProof = useSocialProof(extensionKey, true),
|
|
47
|
+
connectedPct = _useSocialProof.connectedPct,
|
|
48
|
+
isSocialProofAvailable = _useSocialProof.isEnabled;
|
|
49
|
+
var hasSupportedAuthorization = (config === null || config === void 0 ? void 0 : config.authFlow) !== 'disabled' && services.length > 0;
|
|
50
|
+
var isBaseEligible = state.status === 'unauthorized' && Boolean(providerName) && Boolean(extensionKey) && hasSupportedAuthorization;
|
|
51
|
+
var finishCoordinatedAttempt = useCallback(function () {
|
|
52
|
+
if (finished.current) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
finished.current = true;
|
|
56
|
+
setIsRequested(false);
|
|
57
|
+
onFinished();
|
|
58
|
+
}, [onFinished]);
|
|
59
|
+
var handleUnavailable = useCallback(function () {
|
|
60
|
+
if (finished.current) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (hasOpened.current) {
|
|
64
|
+
fireEvent('ui.modal.closed.preAuthValueProposition', {
|
|
65
|
+
closeMethod: 'coordinator',
|
|
66
|
+
dwellTime: Date.now() - modalOpenTimeRef.current
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
finishCoordinatedAttempt();
|
|
70
|
+
}, [fireEvent, finishCoordinatedAttempt]);
|
|
71
|
+
var shouldClaim = useCallback(function () {
|
|
72
|
+
// Recheck at offer time: another attempt may have consumed the cap while we waited.
|
|
73
|
+
if (finished.current || !isBaseEligible || !extensionKey || preAuthValuePropositionModalService.hasReachedShowLimit(extensionKey)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
var variant = expVal('platform_sl_3p_preauth_value_modal', 'variant', 'control');
|
|
77
|
+
if (variant !== 'modal_text_only' && variant !== 'modal_with_image') {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
setVisibleVariant(variant);
|
|
81
|
+
return true;
|
|
82
|
+
}, [extensionKey, isBaseEligible]);
|
|
83
|
+
|
|
84
|
+
// The editor mounts this flow only when platform_sl_3p_preauth_value_modal_killswitch is on.
|
|
85
|
+
useEffect(function () {
|
|
86
|
+
if (finished.current) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (state.status === 'pending' || state.status === 'resolving') {
|
|
90
|
+
// A previously eligible link that starts resolving again must release its slot.
|
|
91
|
+
if (isRequested) {
|
|
92
|
+
handleUnavailable();
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (!isBaseEligible || !extensionKey) {
|
|
97
|
+
handleUnavailable();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!isRequested) {
|
|
101
|
+
if (preAuthValuePropositionModalService.hasReachedShowLimit(extensionKey)) {
|
|
102
|
+
finishCoordinatedAttempt();
|
|
103
|
+
} else {
|
|
104
|
+
setIsRequested(true);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}, [extensionKey, isBaseEligible, state.status, isRequested, handleUnavailable, finishCoordinatedAttempt]);
|
|
108
|
+
var recordShowOnce = useCallback(function () {
|
|
109
|
+
if (hasRecordedShow.current || !extensionKey) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
hasRecordedShow.current = true;
|
|
113
|
+
preAuthValuePropositionModalService.recordShow(extensionKey);
|
|
114
|
+
}, [extensionKey]);
|
|
115
|
+
var dismissModal = useCallback(function (closeMethod) {
|
|
116
|
+
if (finished.current) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
// A user can dismiss the visible modal before its entrance animation completes.
|
|
120
|
+
recordShowOnce();
|
|
121
|
+
fireEvent('ui.modal.closed.preAuthValueProposition', {
|
|
122
|
+
closeMethod: closeMethod,
|
|
123
|
+
dwellTime: Date.now() - modalOpenTimeRef.current
|
|
124
|
+
});
|
|
125
|
+
finishCoordinatedAttempt();
|
|
126
|
+
}, [fireEvent, finishCoordinatedAttempt, recordShowOnce]);
|
|
127
|
+
var handleCloseButton = useCallback(function () {
|
|
128
|
+
dismissModal('button');
|
|
129
|
+
}, [dismissModal]);
|
|
130
|
+
var handleModalClose = useCallback(function (event) {
|
|
131
|
+
dismissModal(getModalCloseMethod(event));
|
|
132
|
+
}, [dismissModal]);
|
|
133
|
+
var handleOpenComplete = useCallback(function () {
|
|
134
|
+
if (finished.current || hasOpened.current || !extensionKey) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
hasOpened.current = true;
|
|
138
|
+
recordShowOnce();
|
|
139
|
+
modalOpenTimeRef.current = Date.now();
|
|
140
|
+
fireEvent('ui.modal.opened.preAuthValueProposition', {});
|
|
141
|
+
}, [fireEvent, extensionKey, recordShowOnce]);
|
|
142
|
+
var connectAccount = useCallback(function () {
|
|
143
|
+
if (finished.current) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
recordShowOnce();
|
|
147
|
+
fireEvent('track.applicationAccount.authStarted', {});
|
|
148
|
+
finishCoordinatedAttempt();
|
|
149
|
+
actions.authorize('inline');
|
|
150
|
+
}, [actions, fireEvent, finishCoordinatedAttempt, recordShowOnce]);
|
|
151
|
+
return {
|
|
152
|
+
isActive: isRequested,
|
|
153
|
+
isEligible: isBaseEligible,
|
|
154
|
+
onUnavailable: handleUnavailable,
|
|
155
|
+
shouldClaim: shouldClaim,
|
|
156
|
+
modal: {
|
|
157
|
+
provider: provider,
|
|
158
|
+
variant: visibleVariant,
|
|
159
|
+
connectedPct: connectedPct,
|
|
160
|
+
isSocialProofAvailable: isSocialProofAvailable,
|
|
161
|
+
onClose: handleModalClose,
|
|
162
|
+
onCloseButton: handleCloseButton,
|
|
163
|
+
onConnect: connectAccount,
|
|
164
|
+
onOpenComplete: handleOpenComplete
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Generates Typescript types for analytics events from analytics.spec.yaml
|
|
5
5
|
*
|
|
6
|
-
* @codegen <<SignedSource::
|
|
6
|
+
* @codegen <<SignedSource::bcb840e9445405411cf34af7d9171bf7>>
|
|
7
7
|
* @codegenCommand afm workspace @atlassian/analytics-tooling analytics:codegen smart-card
|
|
8
8
|
*/
|
|
9
9
|
export type PackageMetaDataContextType = {
|
|
@@ -109,7 +109,7 @@ export type ModalClosedRelatedLinksAttributesType = {
|
|
|
109
109
|
};
|
|
110
110
|
export type ModalOpenedPreAuthValuePropositionAttributesType = {};
|
|
111
111
|
export type ModalClosedPreAuthValuePropositionAttributesType = {
|
|
112
|
-
closeMethod: 'button' | 'escape' | 'overlay';
|
|
112
|
+
closeMethod: 'button' | 'escape' | 'overlay' | 'coordinator';
|
|
113
113
|
dwellTime: number;
|
|
114
114
|
};
|
|
115
115
|
export type RelatedLinksSuccessAttributesType = {
|
|
@@ -4,4 +4,4 @@ export type PreAuthValuePropositionModalProps = {
|
|
|
4
4
|
onOpenChange?: (isOpen: boolean) => void;
|
|
5
5
|
url: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const PreAuthValuePropositionModal: (
|
|
7
|
+
export declare const PreAuthValuePropositionModal: (props: PreAuthValuePropositionModalProps) => JSX.Element;
|
package/dist/types/view/PreAuthValuePropositionModal/use-pre-auth-value-proposition-modal.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { extractSmartLinkProvider } from '@atlaskit/link-extractors/extract-smart-link-provider';
|
|
2
|
+
import type { KeyboardOrMouseEvent } from '@atlaskit/modal-dialog/types';
|
|
3
|
+
export declare const SMART_LINK_MODAL_ID = "pre-auth-value-proposition-modal";
|
|
4
|
+
type PreAuthValuePropositionModalOptions = {
|
|
5
|
+
onFinished: () => void;
|
|
6
|
+
url: string;
|
|
7
|
+
};
|
|
8
|
+
type PreAuthModalVariant = 'modal_text_only' | 'modal_with_image';
|
|
9
|
+
type PreAuthValuePropositionModalModel = {
|
|
10
|
+
connectedPct?: number;
|
|
11
|
+
isSocialProofAvailable: boolean;
|
|
12
|
+
onClose: (event: KeyboardOrMouseEvent) => void;
|
|
13
|
+
onCloseButton: () => void;
|
|
14
|
+
onConnect: () => void;
|
|
15
|
+
onOpenComplete: () => void;
|
|
16
|
+
provider: ReturnType<typeof extractSmartLinkProvider>;
|
|
17
|
+
variant: PreAuthModalVariant;
|
|
18
|
+
};
|
|
19
|
+
type PreAuthValuePropositionModalState = {
|
|
20
|
+
isActive: boolean;
|
|
21
|
+
isEligible: boolean;
|
|
22
|
+
modal: PreAuthValuePropositionModalModel;
|
|
23
|
+
onUnavailable: () => void;
|
|
24
|
+
shouldClaim: () => boolean;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Eligibility, assignment and modal actions for one URL attempt.
|
|
28
|
+
* The existing choreographer adapter owns display permission and cleanup.
|
|
29
|
+
*/
|
|
30
|
+
export declare function usePreAuthValuePropositionModal({ url, onFinished, }: PreAuthValuePropositionModalOptions): PreAuthValuePropositionModalState;
|
|
31
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/smart-card",
|
|
3
|
-
"version": "46.
|
|
3
|
+
"version": "46.16.0",
|
|
4
4
|
"description": "Smart card component",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@atlaskit/adf-utils": "^20.9.0",
|
|
42
|
-
"@atlaskit/afm-i18n-platform-linking-platform-smart-card": "2.
|
|
42
|
+
"@atlaskit/afm-i18n-platform-linking-platform-smart-card": "2.312.0",
|
|
43
43
|
"@atlaskit/analytics-cross-product": "^2.3.0",
|
|
44
44
|
"@atlaskit/analytics-gas-types": "^6.2.0",
|
|
45
45
|
"@atlaskit/analytics-next": "^12.6.0",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"uuid": "^11.1.1"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|
|
117
|
-
"@atlaskit/link-provider": "^6.
|
|
117
|
+
"@atlaskit/link-provider": "^6.2.0",
|
|
118
118
|
"react": "^18.2.0",
|
|
119
119
|
"react-dom": "^18.2.0",
|
|
120
120
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
"@atlaskit/css-reset": "^8.4.0",
|
|
129
129
|
"@atlaskit/datetime-picker": "^19.5.0",
|
|
130
130
|
"@atlaskit/inline-message": "^16.4.0",
|
|
131
|
-
"@atlaskit/link-provider": "^6.
|
|
131
|
+
"@atlaskit/link-provider": "^6.2.0",
|
|
132
132
|
"@atlaskit/media-test-helpers": "^43.0.0",
|
|
133
133
|
"@atlaskit/page": "^15.3.0",
|
|
134
134
|
"@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-migration": "^3.5.0",
|
|
@@ -141,9 +141,11 @@
|
|
|
141
141
|
"@atlassian/experiment-test-utils": "^0.2.0",
|
|
142
142
|
"@atlassian/feature-flags-test-utils": "^1.3.0",
|
|
143
143
|
"@atlassian/gemini": "^1.55.0",
|
|
144
|
+
"@atlassian/ipm-choreographer": "^0.35.0",
|
|
144
145
|
"@atlassian/structured-docs-types": "workspace:^",
|
|
145
146
|
"@atlassian/testing-library": "^0.12.0",
|
|
146
147
|
"@atlassian/workbench": "workspace:*",
|
|
148
|
+
"@atlassiansox/analytics-web-client": "^5.32.0",
|
|
147
149
|
"@testing-library/dom": "^10.1.0",
|
|
148
150
|
"@testing-library/jest-dom": "^6.4.5",
|
|
149
151
|
"@testing-library/react": "^16.3.0",
|