@atlaskit/contextual-survey 2.0.11

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 (64) hide show
  1. package/CHANGELOG.md +258 -0
  2. package/LICENSE +13 -0
  3. package/README.md +13 -0
  4. package/build/tsconfig.json +17 -0
  5. package/constants/package.json +7 -0
  6. package/dist/cjs/components/ContextualSurvey.js +274 -0
  7. package/dist/cjs/components/FeedbackAcknowledgement.js +26 -0
  8. package/dist/cjs/components/FeedbackScoreButtons.js +60 -0
  9. package/dist/cjs/components/SignUpPrompt.js +84 -0
  10. package/dist/cjs/components/SignUpSuccess.js +29 -0
  11. package/dist/cjs/components/SuccessContainer.js +35 -0
  12. package/dist/cjs/components/SurveyContainer.js +48 -0
  13. package/dist/cjs/components/SurveyForm.js +159 -0
  14. package/dist/cjs/components/SurveyMarshal.js +67 -0
  15. package/dist/cjs/components/useEscapeToDismiss.js +78 -0
  16. package/dist/cjs/constants.js +15 -0
  17. package/dist/cjs/index.js +35 -0
  18. package/dist/cjs/types.js +5 -0
  19. package/dist/cjs/version.json +5 -0
  20. package/dist/es2019/components/ContextualSurvey.js +178 -0
  21. package/dist/es2019/components/FeedbackAcknowledgement.js +12 -0
  22. package/dist/es2019/components/FeedbackScoreButtons.js +69 -0
  23. package/dist/es2019/components/SignUpPrompt.js +46 -0
  24. package/dist/es2019/components/SignUpSuccess.js +12 -0
  25. package/dist/es2019/components/SuccessContainer.js +22 -0
  26. package/dist/es2019/components/SurveyContainer.js +37 -0
  27. package/dist/es2019/components/SurveyForm.js +121 -0
  28. package/dist/es2019/components/SurveyMarshal.js +62 -0
  29. package/dist/es2019/components/useEscapeToDismiss.js +69 -0
  30. package/dist/es2019/constants.js +4 -0
  31. package/dist/es2019/index.js +2 -0
  32. package/dist/es2019/types.js +1 -0
  33. package/dist/es2019/version.json +5 -0
  34. package/dist/esm/components/ContextualSurvey.js +244 -0
  35. package/dist/esm/components/FeedbackAcknowledgement.js +13 -0
  36. package/dist/esm/components/FeedbackScoreButtons.js +44 -0
  37. package/dist/esm/components/SignUpPrompt.js +66 -0
  38. package/dist/esm/components/SignUpSuccess.js +16 -0
  39. package/dist/esm/components/SuccessContainer.js +21 -0
  40. package/dist/esm/components/SurveyContainer.js +30 -0
  41. package/dist/esm/components/SurveyForm.js +132 -0
  42. package/dist/esm/components/SurveyMarshal.js +55 -0
  43. package/dist/esm/components/useEscapeToDismiss.js +68 -0
  44. package/dist/esm/constants.js +4 -0
  45. package/dist/esm/index.js +2 -0
  46. package/dist/esm/types.js +1 -0
  47. package/dist/esm/version.json +5 -0
  48. package/dist/types/components/ContextualSurvey.d.ts +39 -0
  49. package/dist/types/components/FeedbackAcknowledgement.d.ts +2 -0
  50. package/dist/types/components/FeedbackScoreButtons.d.ts +6 -0
  51. package/dist/types/components/SignUpPrompt.d.ts +5 -0
  52. package/dist/types/components/SignUpSuccess.d.ts +4 -0
  53. package/dist/types/components/SuccessContainer.d.ts +6 -0
  54. package/dist/types/components/SurveyContainer.d.ts +7 -0
  55. package/dist/types/components/SurveyForm.d.ts +11 -0
  56. package/dist/types/components/SurveyMarshal.d.ts +13 -0
  57. package/dist/types/components/useEscapeToDismiss.d.ts +6 -0
  58. package/dist/types/constants.d.ts +2 -0
  59. package/dist/types/index.d.ts +3 -0
  60. package/dist/types/types.d.ts +5 -0
  61. package/docs/0-intro.tsx +115 -0
  62. package/package.json +58 -0
  63. package/tsconfig.json +16 -0
  64. package/types/package.json +7 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,258 @@
1
+ # @atlaskit/contextual-survey
2
+
3
+ ## 2.0.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 2.0.10
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 2.0.9
16
+
17
+ ### Patch Changes
18
+
19
+ - [`cad4332df17`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cad4332df17) - [ux] Fixed flickering in context survey by removing theme overrides
20
+ - Updated dependencies
21
+
22
+ ## 2.0.8
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies
27
+
28
+ ## 2.0.7
29
+
30
+ ### Patch Changes
31
+
32
+ - [`d3265f19be`](https://bitbucket.org/atlassian/atlassian-frontend/commits/d3265f19be) - Transpile packages using babel rather than tsc
33
+
34
+ ## 2.0.6
35
+
36
+ ### Patch Changes
37
+
38
+ - Updated dependencies
39
+
40
+ ## 2.0.5
41
+
42
+ ### Patch Changes
43
+
44
+ - [`5f58283e1f`](https://bitbucket.org/atlassian/atlassian-frontend/commits/5f58283e1f) - Export types using Typescript's new "export type" syntax to satisfy Typescript's --isolatedModules compiler option.
45
+ This requires version 3.8 of Typescript, read more about how we handle Typescript versions here: https://atlaskit.atlassian.com/get-started
46
+ Also add `typescript` to `devDependencies` to denote version that the package was built with.
47
+
48
+ ## 2.0.4
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies
53
+
54
+ ## 2.0.3
55
+
56
+ ### Patch Changes
57
+
58
+ - Updated dependencies
59
+
60
+ ## 2.0.2
61
+
62
+ ### Patch Changes
63
+
64
+ - Updated dependencies
65
+
66
+ ## 2.0.1
67
+
68
+ ### Patch Changes
69
+
70
+ - [`6c525a8229`](https://bitbucket.org/atlassian/atlassian-frontend/commits/6c525a8229) - Upgraded to TypeScript 3.9.6 and tslib to 2.0.0
71
+
72
+ Since tslib is a dependency for all our packages we recommend that products also follow this tslib upgrade
73
+ to prevent duplicates of tslib being bundled.
74
+
75
+ ## 2.0.0
76
+
77
+ ### Major Changes
78
+
79
+ - [`87f4720f27`](https://bitbucket.org/atlassian/atlassian-frontend/commits/87f4720f27) - Officially dropping IE11 support, from this version onwards there are no warranties of the package working in IE11.
80
+ For more information see: https://community.developer.atlassian.com/t/atlaskit-to-drop-support-for-internet-explorer-11-from-1st-july-2020/39534
81
+
82
+ ### Patch Changes
83
+
84
+ - Updated dependencies
85
+
86
+ ## 1.0.10
87
+
88
+ ### Patch Changes
89
+
90
+ - [`3ba793cffa`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3ba793cffa) - Update all the theme imports in contextual-survey
91
+
92
+ ## 1.0.9
93
+
94
+ ### Patch Changes
95
+
96
+ - [`4560b65a4f`](https://bitbucket.org/atlassian/atlassian-frontend/commits/4560b65a4f) - upgrade react-transition-group to latest
97
+
98
+ ## 1.0.8
99
+
100
+ ### Patch Changes
101
+
102
+ - [patch][dd7e8b4bc7](https://bitbucket.org/atlassian/atlassian-frontend/commits/dd7e8b4bc7):
103
+
104
+ Change imports to comply with Atlassian conventions
105
+
106
+ ## 1.0.7
107
+
108
+ ### Patch Changes
109
+
110
+ - [patch][6548261c9a](https://bitbucket.org/atlassian/atlassian-frontend/commits/6548261c9a):
111
+
112
+ Remove namespace imports from React, ReactDom, and PropTypes- Updated dependencies [6548261c9a](https://bitbucket.org/atlassian/atlassian-frontend/commits/6548261c9a):
113
+
114
+ - @atlaskit/docs@8.3.2
115
+ - @atlaskit/button@13.3.7
116
+ - @atlaskit/checkbox@10.1.7
117
+ - @atlaskit/form@7.1.2
118
+ - @atlaskit/icon@20.0.1
119
+ - @atlaskit/textarea@2.2.4
120
+ - @atlaskit/theme@9.5.1
121
+ - @atlaskit/tooltip@15.2.3
122
+
123
+ ## 1.0.6
124
+
125
+ ### Patch Changes
126
+
127
+ - Updated dependencies [c0102a3ea2](https://bitbucket.org/atlassian/atlassian-frontend/commits/c0102a3ea2):
128
+ - @atlaskit/icon@20.0.0
129
+ - @atlaskit/form@7.1.1
130
+ - @atlaskit/docs@8.3.1
131
+ - @atlaskit/button@13.3.6
132
+ - @atlaskit/checkbox@10.1.6
133
+ - @atlaskit/tooltip@15.2.2
134
+
135
+ ## 1.0.5
136
+
137
+ ### Patch Changes
138
+
139
+ - [patch][24865cfaff](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/24865cfaff):
140
+
141
+ Pull in update to form to fix a bug which could cause the internal fieldId to be incorrectly set- [patch][24865cfaff](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/24865cfaff):
142
+
143
+ Form has been converted to Typescript. TypeScript consumers will now get static type safety. Flow types are no longer provided. No API changes.- Updated dependencies [24865cfaff](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/24865cfaff):
144
+
145
+ - Updated dependencies [24865cfaff](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/24865cfaff):
146
+ - Updated dependencies [24865cfaff](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/24865cfaff):
147
+ - Updated dependencies [24865cfaff](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/24865cfaff):
148
+ - Updated dependencies [24865cfaff](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/24865cfaff):
149
+ - Updated dependencies [24865cfaff](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/24865cfaff):
150
+ - @atlaskit/tooltip@15.2.0
151
+ - @atlaskit/form@7.0.0
152
+ - @atlaskit/checkbox@10.1.4
153
+ - @atlaskit/textarea@2.2.3
154
+
155
+ ## 1.0.4
156
+
157
+ ### Patch Changes
158
+
159
+ - [patch][35d2229b2a](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/35d2229b2a):
160
+
161
+ Adding missing license to packages and update to Copyright 2019 Atlassian Pty Ltd.
162
+
163
+ ## 1.0.3
164
+
165
+ - Updated dependencies [97bab7fd28](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/97bab7fd28):
166
+ - @atlaskit/button@13.3.1
167
+ - @atlaskit/form@6.2.3
168
+ - @atlaskit/checkbox@10.0.0
169
+ - @atlaskit/docs@8.1.7
170
+
171
+ ## 1.0.2
172
+
173
+ ### Patch Changes
174
+
175
+ - [patch][097b696613](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/097b696613):
176
+
177
+ Components now depend on TS 3.6 internally, in order to fix an issue with TS resolving non-relative imports as relative imports
178
+
179
+ ## 1.0.1
180
+
181
+ ### Patch Changes
182
+
183
+ - [patch][f34776be97](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/f34776be97):
184
+
185
+ Type definition files are now referenced in package.json
186
+
187
+ ## 1.0.0
188
+
189
+ ### Major Changes
190
+
191
+ - [major][271b7db35b](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/271b7db35b):
192
+
193
+ _💥 Most of the changes listed are breaking changes from the 0.x release_
194
+
195
+ ### New component for placement: `<SurveyMarshal />`
196
+
197
+ We no longer require consumers to know anything about `react-transition-group` to use this package. The `<SurveyMarshal />` takes care of the placement and mounting / unmounting animation of the component. It accepts a _function as a child_ which needs to return the `<ContextualSurvey />`. This pattern also allows the `<ContextualSurvey />` to not be evaluated when it is not mounted
198
+
199
+ ```js
200
+ import { SurveyMarshal, ContextualSurvey } from '@atlaskit/contextual-survey';
201
+
202
+ <SurveyMarshal shouldShow={showSurvey}>
203
+ {() => <ContextualSurvey />}
204
+ </SurveyMarshal>;
205
+ ```
206
+
207
+ ### Other
208
+
209
+ - `getUserHasAnsweredMailingList: () => boolean | () => Promise<boolean>` has been streamlined to just be `() => Promise<boolean>`.
210
+ - ~~`onSignUp() => Promise<void>`~~ has become `onMailingListAnswer(answer) => Promise<void>`. Previously `onSignUp` was only called if the user selected they wanted to sign up. `onMailingListAnswer` will be called when the user selects they want to sign up, as well as if they select that they do not want to sign up.
211
+ - 💄 `<ContextualSurvey />` now animates in as well as out
212
+ - 💄 No more scrollbars during closing animation
213
+ - 💄 Fixing spacing for `FeedbackAcknowledgement` screen
214
+ - 💄 Audit dismiss button alignment
215
+ - 🛠Preventing double calls to `onDismiss()`
216
+ - 🛠`onDismiss()` now provided with a `enum:DismissTrigger` to give more information about the reason for the dismiss
217
+ - 🛠If `<ContextualSurvey />` is dismissed while `onSubmit` is resolving, then `getUserHasAnsweredMailingList()` is not called. We do this as we won't be showing the email sign up
218
+ - 🛠If the user marks that they do not want to be contacted, then `getUserHasAnsweredMailingList()` is not called. Previously `getUserHasAnsweredMailingList()` was always called _regardless_ of whether the user wanted to be contacted. The email sign up is only showed if the user states that they want to be contacted and if `getUserHasAnsweredMailingList` returns `false`. We now don't call `getUserHasAnsweredMailingList` if the user has stated they don't want to be contacted as it is a precondition.
219
+ - 🚀 The user is able to dismiss the form at any time using the `escape` key
220
+ - 🕵️‍ After clicking a score the response `textarea` is given browser focus.
221
+ - ✅ New behaviour for the _can contact_ checkbox. It is now not selected by default. When a user types into the response text area for the first time we swap it to checked. From that point the user is welcome to change it's value and we do not automatically swap it to checked again. This allows people to select a score but not be contacted for it. It also recognises that the engagement platform would like to be able to respond to people who provide feedback.
222
+ - ♿️ Added `aria-pressed` to currently selected score
223
+ - 📖 Documentation explaining application flow
224
+ - 👩‍🔬 Added automated test for happy path
225
+ - ❌ No longer exporting `surveyWidth` and `surveyMargin`. All placement is handled by `<SurveyMarshal />`
226
+
227
+ ## 0.1.3
228
+
229
+ - Updated dependencies [87a2638655](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/87a2638655):
230
+ - @atlaskit/button@13.0.10
231
+ - @atlaskit/form@6.1.2
232
+ - @atlaskit/checkbox@9.0.0
233
+
234
+ ## 0.1.2
235
+
236
+ - Updated dependencies [06326ef3f7](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/06326ef3f7):
237
+ - @atlaskit/docs@8.1.3
238
+ - @atlaskit/button@13.0.9
239
+ - @atlaskit/checkbox@8.0.5
240
+ - @atlaskit/form@6.1.1
241
+ - @atlaskit/tooltip@15.0.2
242
+ - @atlaskit/icon@19.0.0
243
+
244
+ ## 0.1.1
245
+
246
+ ### Patch Changes
247
+
248
+ - [patch][0fc1ac28e8](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/0fc1ac28e8):
249
+
250
+ Fixed missing background colour.
251
+
252
+ ## 0.1.0
253
+
254
+ ### Minor Changes
255
+
256
+ - [minor][25f45f87f4](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/25f45f87f4):
257
+
258
+ Create contextual survey component
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2019 Atlassian Pty Ltd
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # Contextual Survey
2
+
3
+ This component is used to ask for feedback from the user, without blocking them from continuing using the product.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ yarn add @atlaskit/contextual-survey
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Detailed docs and example usage can be found [here](https://atlaskit.atlassian.com/packages/engagement-platform/contextual-survey).
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "../tsconfig",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "target": "es5",
6
+ "paths": {}
7
+ },
8
+ "include": [
9
+ "../src/**/*.ts",
10
+ "../src/**/*.tsx"
11
+ ],
12
+ "exclude": [
13
+ "../src/**/__tests__/*",
14
+ "../src/**/*.test.*",
15
+ "../src/**/test.*"
16
+ ]
17
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@atlaskit/contextual-survey/constants",
3
+ "main": "../dist/cjs/constants.js",
4
+ "module": "../dist/esm/constants.js",
5
+ "module:es2019": "../dist/es2019/constants.js",
6
+ "types": "../dist/types/constants.d.ts"
7
+ }
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.default = exports.AUTO_DISAPPEAR_DURATION = exports.DismissTrigger = void 0;
11
+
12
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
+
14
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
+
16
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
+
18
+ var _react = _interopRequireWildcard(require("react"));
19
+
20
+ var _FeedbackAcknowledgement = _interopRequireDefault(require("./FeedbackAcknowledgement"));
21
+
22
+ var _SignUpPrompt = _interopRequireDefault(require("./SignUpPrompt"));
23
+
24
+ var _SignUpSuccess = _interopRequireDefault(require("./SignUpSuccess"));
25
+
26
+ var _SurveyContainer = _interopRequireDefault(require("./SurveyContainer"));
27
+
28
+ var _SurveyForm = _interopRequireDefault(require("./SurveyForm"));
29
+
30
+ var _useEscapeToDismiss = _interopRequireDefault(require("./useEscapeToDismiss"));
31
+
32
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
33
+
34
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
35
+
36
+ var DismissTrigger;
37
+ exports.DismissTrigger = DismissTrigger;
38
+
39
+ (function (DismissTrigger) {
40
+ DismissTrigger["AutoDismiss"] = "AUTO_DISMISS";
41
+ DismissTrigger["Manual"] = "MANUAL";
42
+ DismissTrigger["Finished"] = "FINISHED";
43
+ DismissTrigger["Unmount"] = "UNMOUNT";
44
+ })(DismissTrigger || (exports.DismissTrigger = DismissTrigger = {}));
45
+
46
+ var AUTO_DISAPPEAR_DURATION = 8000;
47
+ exports.AUTO_DISAPPEAR_DURATION = AUTO_DISAPPEAR_DURATION;
48
+
49
+ var _default = function _default(_ref) {
50
+ var question = _ref.question,
51
+ statement = _ref.statement,
52
+ onDismiss = _ref.onDismiss,
53
+ onSubmit = _ref.onSubmit,
54
+ onMailingListAnswer = _ref.onMailingListAnswer,
55
+ getUserHasAnsweredMailingList = _ref.getUserHasAnsweredMailingList,
56
+ _ref$textLabel = _ref.textLabel,
57
+ textLabel = _ref$textLabel === void 0 ? 'Why did you give that rating' : _ref$textLabel,
58
+ _ref$textPlaceholder = _ref.textPlaceholder,
59
+ textPlaceholder = _ref$textPlaceholder === void 0 ? 'Tell us why' : _ref$textPlaceholder;
60
+ var autoDisappearTimeoutRef = (0, _react.useRef)(null); // only allow a single dismiss for a component
61
+
62
+ var isDismissedRef = (0, _react.useRef)(false);
63
+ var tryDismiss = (0, _react.useCallback)(function (trigger) {
64
+ // Already called dismiss once
65
+ if (isDismissedRef.current) {
66
+ return;
67
+ }
68
+
69
+ isDismissedRef.current = true;
70
+ onDismissRef.current({
71
+ trigger: trigger
72
+ });
73
+ }, []);
74
+
75
+ var _useState = (0, _react.useState)('SURVEY'),
76
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
77
+ currentStep = _useState2[0],
78
+ setCurrentStep = _useState2[1];
79
+
80
+ var trySetCurrentStep = (0, _react.useCallback)(function (step) {
81
+ // Already dismissed - cannot update the step
82
+ if (isDismissedRef.current) {
83
+ if (process.env.NODE_ENV !== 'production') {
84
+ // eslint-disable-next-line no-console
85
+ console.log("not setting step \"".concat(step, "\" as survey is already dismissed"));
86
+ }
87
+
88
+ return;
89
+ }
90
+
91
+ setCurrentStep(step);
92
+ }, [setCurrentStep]); // using a ref so that we don't break all of our caches if a consumer is using an arrow function
93
+
94
+ var onDismissRef = (0, _react.useRef)(onDismiss);
95
+ (0, _react.useEffect)(function () {
96
+ onDismissRef.current = onDismiss;
97
+ }, [onDismiss]);
98
+ var tryClearTimeout = (0, _react.useCallback)(function () {
99
+ var id = autoDisappearTimeoutRef.current;
100
+
101
+ if (id) {
102
+ clearTimeout(id);
103
+ autoDisappearTimeoutRef.current = null;
104
+ }
105
+ }, []); // Cleanup any auto dismiss after dismiss
106
+
107
+ (0, _react.useEffect)(function () {
108
+ return function unmount() {
109
+ tryClearTimeout();
110
+ tryDismiss(DismissTrigger.Unmount);
111
+ };
112
+ }, [tryClearTimeout, tryDismiss]);
113
+ var onSurveySubmit = (0, _react.useCallback)( /*#__PURE__*/function () {
114
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(formValues, form) {
115
+ var callback,
116
+ userHasAnswered,
117
+ _args = arguments;
118
+ return _regenerator.default.wrap(function _callee$(_context) {
119
+ while (1) {
120
+ switch (_context.prev = _context.next) {
121
+ case 0:
122
+ callback = _args.length > 2 && _args[2] !== undefined ? _args[2] : function () {};
123
+ _context.next = 3;
124
+ return onSubmit(formValues);
125
+
126
+ case 3:
127
+ if (!isDismissedRef.current) {
128
+ _context.next = 6;
129
+ break;
130
+ }
131
+
132
+ callback();
133
+ return _context.abrupt("return");
134
+
135
+ case 6:
136
+ if (formValues.canContact) {
137
+ _context.next = 10;
138
+ break;
139
+ }
140
+
141
+ callback();
142
+ trySetCurrentStep('POST_SURVEY_NO_CONSENT');
143
+ return _context.abrupt("return");
144
+
145
+ case 10:
146
+ _context.next = 12;
147
+ return getUserHasAnsweredMailingList();
148
+
149
+ case 12:
150
+ userHasAnswered = _context.sent;
151
+ callback(); // Not entering phase 2: user has already answered this question
152
+
153
+ if (!userHasAnswered) {
154
+ _context.next = 17;
155
+ break;
156
+ }
157
+
158
+ trySetCurrentStep('POST_SURVEY_HAS_SIGN_UP');
159
+ return _context.abrupt("return");
160
+
161
+ case 17:
162
+ // Enter phase 2
163
+ trySetCurrentStep('SIGN_UP_PROMPT');
164
+
165
+ case 18:
166
+ case "end":
167
+ return _context.stop();
168
+ }
169
+ }
170
+ }, _callee);
171
+ }));
172
+
173
+ return function (_x, _x2) {
174
+ return _ref2.apply(this, arguments);
175
+ };
176
+ }(), [getUserHasAnsweredMailingList, onSubmit, trySetCurrentStep]);
177
+ var onMailingListResponse = (0, _react.useCallback)( /*#__PURE__*/function () {
178
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(answer) {
179
+ return _regenerator.default.wrap(function _callee2$(_context2) {
180
+ while (1) {
181
+ switch (_context2.prev = _context2.next) {
182
+ case 0:
183
+ _context2.next = 2;
184
+ return onMailingListAnswer(answer);
185
+
186
+ case 2:
187
+ if (!answer) {
188
+ _context2.next = 5;
189
+ break;
190
+ }
191
+
192
+ trySetCurrentStep('SIGN_UP_SUCCESS');
193
+ return _context2.abrupt("return");
194
+
195
+ case 5:
196
+ // We have already thanked to user, we can simply close
197
+ tryDismiss(DismissTrigger.Finished);
198
+
199
+ case 6:
200
+ case "end":
201
+ return _context2.stop();
202
+ }
203
+ }
204
+ }, _callee2);
205
+ }));
206
+
207
+ return function (_x3) {
208
+ return _ref3.apply(this, arguments);
209
+ };
210
+ }(), // eslint-disable-next-line react-hooks/exhaustive-deps
211
+ [tryDismiss, trySetCurrentStep]); // Start the auto disappear when we are finished
212
+
213
+ (0, _react.useEffect)(function () {
214
+ // Already dismissed
215
+ if (isDismissedRef.current) {
216
+ return;
217
+ } // Timeout already scheduled
218
+
219
+
220
+ if (autoDisappearTimeoutRef.current) {
221
+ return;
222
+ }
223
+
224
+ if (['SIGN_UP_SUCCESS', 'POST_SURVEY_NO_CONSENT', 'POST_SURVEY_HAS_SIGN_UP'].includes(currentStep)) {
225
+ autoDisappearTimeoutRef.current = window.setTimeout(function () {
226
+ return tryDismiss(DismissTrigger.AutoDismiss);
227
+ }, AUTO_DISAPPEAR_DURATION);
228
+ }
229
+ }, [currentStep, tryDismiss]);
230
+ (0, _useEscapeToDismiss.default)({
231
+ onDismiss: function onDismiss() {
232
+ return tryDismiss(DismissTrigger.Manual);
233
+ }
234
+ });
235
+
236
+ var content = function () {
237
+ if (currentStep === 'SURVEY') {
238
+ return /*#__PURE__*/_react.default.createElement(_SurveyForm.default, {
239
+ question: question,
240
+ statement: statement,
241
+ textLabel: textLabel,
242
+ textPlaceholder: textPlaceholder,
243
+ onSubmit: onSurveySubmit
244
+ });
245
+ }
246
+
247
+ if (currentStep === 'SIGN_UP_PROMPT') {
248
+ return /*#__PURE__*/_react.default.createElement(_SignUpPrompt.default, {
249
+ onAnswer: onMailingListResponse
250
+ });
251
+ }
252
+
253
+ if (currentStep === 'SIGN_UP_SUCCESS') {
254
+ return /*#__PURE__*/_react.default.createElement(_SignUpSuccess.default, null);
255
+ }
256
+
257
+ if (currentStep === 'POST_SURVEY_NO_CONSENT' || currentStep === 'POST_SURVEY_HAS_SIGN_UP') {
258
+ return /*#__PURE__*/_react.default.createElement(_FeedbackAcknowledgement.default, null);
259
+ }
260
+
261
+ return null;
262
+ }();
263
+
264
+ var manualDismiss = (0, _react.useCallback)(function () {
265
+ // clear any pending timers
266
+ tryClearTimeout();
267
+ tryDismiss(DismissTrigger.Manual);
268
+ }, [tryDismiss, tryClearTimeout]);
269
+ return /*#__PURE__*/_react.default.createElement(_SurveyContainer.default, {
270
+ onDismiss: manualDismiss
271
+ }, content);
272
+ };
273
+
274
+ exports.default = _default;