@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.
- package/CHANGELOG.md +258 -0
- package/LICENSE +13 -0
- package/README.md +13 -0
- package/build/tsconfig.json +17 -0
- package/constants/package.json +7 -0
- package/dist/cjs/components/ContextualSurvey.js +274 -0
- package/dist/cjs/components/FeedbackAcknowledgement.js +26 -0
- package/dist/cjs/components/FeedbackScoreButtons.js +60 -0
- package/dist/cjs/components/SignUpPrompt.js +84 -0
- package/dist/cjs/components/SignUpSuccess.js +29 -0
- package/dist/cjs/components/SuccessContainer.js +35 -0
- package/dist/cjs/components/SurveyContainer.js +48 -0
- package/dist/cjs/components/SurveyForm.js +159 -0
- package/dist/cjs/components/SurveyMarshal.js +67 -0
- package/dist/cjs/components/useEscapeToDismiss.js +78 -0
- package/dist/cjs/constants.js +15 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/components/ContextualSurvey.js +178 -0
- package/dist/es2019/components/FeedbackAcknowledgement.js +12 -0
- package/dist/es2019/components/FeedbackScoreButtons.js +69 -0
- package/dist/es2019/components/SignUpPrompt.js +46 -0
- package/dist/es2019/components/SignUpSuccess.js +12 -0
- package/dist/es2019/components/SuccessContainer.js +22 -0
- package/dist/es2019/components/SurveyContainer.js +37 -0
- package/dist/es2019/components/SurveyForm.js +121 -0
- package/dist/es2019/components/SurveyMarshal.js +62 -0
- package/dist/es2019/components/useEscapeToDismiss.js +69 -0
- package/dist/es2019/constants.js +4 -0
- package/dist/es2019/index.js +2 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/components/ContextualSurvey.js +244 -0
- package/dist/esm/components/FeedbackAcknowledgement.js +13 -0
- package/dist/esm/components/FeedbackScoreButtons.js +44 -0
- package/dist/esm/components/SignUpPrompt.js +66 -0
- package/dist/esm/components/SignUpSuccess.js +16 -0
- package/dist/esm/components/SuccessContainer.js +21 -0
- package/dist/esm/components/SurveyContainer.js +30 -0
- package/dist/esm/components/SurveyForm.js +132 -0
- package/dist/esm/components/SurveyMarshal.js +55 -0
- package/dist/esm/components/useEscapeToDismiss.js +68 -0
- package/dist/esm/constants.js +4 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/components/ContextualSurvey.d.ts +39 -0
- package/dist/types/components/FeedbackAcknowledgement.d.ts +2 -0
- package/dist/types/components/FeedbackScoreButtons.d.ts +6 -0
- package/dist/types/components/SignUpPrompt.d.ts +5 -0
- package/dist/types/components/SignUpSuccess.d.ts +4 -0
- package/dist/types/components/SuccessContainer.d.ts +6 -0
- package/dist/types/components/SurveyContainer.d.ts +7 -0
- package/dist/types/components/SurveyForm.d.ts +11 -0
- package/dist/types/components/SurveyMarshal.d.ts +13 -0
- package/dist/types/components/useEscapeToDismiss.d.ts +6 -0
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/types.d.ts +5 -0
- package/docs/0-intro.tsx +115 -0
- package/package.json +58 -0
- package/tsconfig.json +16 -0
- package/types/package.json +7 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
|
+
import { css, jsx } from '@emotion/core';
|
|
4
|
+
import Button from '@atlaskit/button/custom-theme-button';
|
|
5
|
+
import { fontSize, gridSize } from '@atlaskit/theme/constants';
|
|
6
|
+
import SuccessContainer from './SuccessContainer';
|
|
7
|
+
export default (({
|
|
8
|
+
onAnswer
|
|
9
|
+
}) => {
|
|
10
|
+
const [pending, setPending] = useState(null);
|
|
11
|
+
const answeredWith = useCallback(async answer => {
|
|
12
|
+
setPending(answer ? 'yes' : 'no');
|
|
13
|
+
await onAnswer(answer);
|
|
14
|
+
}, [setPending, onAnswer]);
|
|
15
|
+
const isDisabled = Boolean(pending);
|
|
16
|
+
return jsx(SuccessContainer, null, jsx("h1", {
|
|
17
|
+
css: css`
|
|
18
|
+
font-size: ${fontSize()}px;
|
|
19
|
+
font-weight: 600;
|
|
20
|
+
margin: 0;
|
|
21
|
+
line-height: ${gridSize() * 3}px;
|
|
22
|
+
`
|
|
23
|
+
}, "Thanks for your feedback"), jsx("p", null, "Are you interested in participating in our research?"), jsx("p", null, "Sign up for the", ' ', jsx("a", {
|
|
24
|
+
href: "https://www.atlassian.com/research-group"
|
|
25
|
+
}, "Atlassian Research Group"), ' ', "and we may contact you in the future with research opportunities."), jsx("div", {
|
|
26
|
+
css: css`
|
|
27
|
+
margin-top: ${gridSize() * 4}px;
|
|
28
|
+
display: flex;
|
|
29
|
+
justify-content: flex-end;
|
|
30
|
+
|
|
31
|
+
& > * + * {
|
|
32
|
+
margin-left: ${gridSize()}px;
|
|
33
|
+
}
|
|
34
|
+
`
|
|
35
|
+
}, jsx(Button, {
|
|
36
|
+
appearance: "subtle",
|
|
37
|
+
onClick: () => answeredWith(false),
|
|
38
|
+
isDisabled: isDisabled,
|
|
39
|
+
isLoading: pending === 'no'
|
|
40
|
+
}, "No, thanks"), jsx(Button, {
|
|
41
|
+
appearance: "primary",
|
|
42
|
+
onClick: () => answeredWith(true),
|
|
43
|
+
isDisabled: isDisabled,
|
|
44
|
+
isLoading: pending === 'yes'
|
|
45
|
+
}, "Yes, sign me up")));
|
|
46
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { css, jsx } from '@emotion/core';
|
|
3
|
+
import { fontSize, gridSize } from '@atlaskit/theme/constants';
|
|
4
|
+
import SuccessContainer from './SuccessContainer';
|
|
5
|
+
export default (({}) => jsx(SuccessContainer, null, jsx("h1", {
|
|
6
|
+
css: css`
|
|
7
|
+
font-size: ${fontSize()}px;
|
|
8
|
+
font-weight: 600;
|
|
9
|
+
line-height: ${gridSize() * 3}px;
|
|
10
|
+
margin: 0;
|
|
11
|
+
`
|
|
12
|
+
}, "Thanks for signing up"), jsx("p", null, "We may reach out to you in the future to participate in additional research.")));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { css, jsx } from '@emotion/core';
|
|
3
|
+
import CheckCircleIcon from '@atlaskit/icon/glyph/check-circle';
|
|
4
|
+
import { G300 } from '@atlaskit/theme/colors';
|
|
5
|
+
import { gridSize } from '@atlaskit/theme/constants';
|
|
6
|
+
export default (({
|
|
7
|
+
children
|
|
8
|
+
}) => jsx("section", {
|
|
9
|
+
css: css`
|
|
10
|
+
margin-left: ${gridSize() * 5}px;
|
|
11
|
+
`
|
|
12
|
+
}, jsx("div", {
|
|
13
|
+
css: css`
|
|
14
|
+
position: absolute;
|
|
15
|
+
top: ${gridSize() * 3}px;
|
|
16
|
+
left: ${gridSize() * 3}px;
|
|
17
|
+
`
|
|
18
|
+
}, jsx(CheckCircleIcon, {
|
|
19
|
+
label: "",
|
|
20
|
+
"aria-hidden": true,
|
|
21
|
+
primaryColor: G300
|
|
22
|
+
})), children));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { css, jsx } from '@emotion/core';
|
|
3
|
+
import Button from '@atlaskit/button/custom-theme-button';
|
|
4
|
+
import CrossIcon from '@atlaskit/icon/glyph/cross';
|
|
5
|
+
import { N0, N50 } from '@atlaskit/theme/colors';
|
|
6
|
+
import { borderRadius, gridSize } from '@atlaskit/theme/constants';
|
|
7
|
+
import { e500 } from '@atlaskit/theme/elevation';
|
|
8
|
+
import { surveyInnerWidth } from '../constants';
|
|
9
|
+
const padding = gridSize() * 3;
|
|
10
|
+
export default (({
|
|
11
|
+
children,
|
|
12
|
+
onDismiss
|
|
13
|
+
}) => {
|
|
14
|
+
return jsx("div", {
|
|
15
|
+
css: css`
|
|
16
|
+
background-color: ${N0};
|
|
17
|
+
border-radius: ${borderRadius()}px;
|
|
18
|
+
padding: ${padding}px;
|
|
19
|
+
${e500()}
|
|
20
|
+
width: ${surveyInnerWidth}px;
|
|
21
|
+
`
|
|
22
|
+
}, jsx("div", {
|
|
23
|
+
css: css`
|
|
24
|
+
position: absolute;
|
|
25
|
+
top: ${padding - gridSize()}px;
|
|
26
|
+
right: ${padding - gridSize()}px;
|
|
27
|
+
`
|
|
28
|
+
}, jsx(Button, {
|
|
29
|
+
iconBefore: jsx(CrossIcon, {
|
|
30
|
+
label: "",
|
|
31
|
+
primaryColor: N50
|
|
32
|
+
}),
|
|
33
|
+
"aria-label": "Dismiss",
|
|
34
|
+
appearance: "subtle",
|
|
35
|
+
onClick: onDismiss
|
|
36
|
+
})), children);
|
|
37
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
|
|
3
|
+
/** @jsx jsx */
|
|
4
|
+
import { useCallback, useRef, useState } from 'react';
|
|
5
|
+
import { css, jsx } from '@emotion/core';
|
|
6
|
+
import { Transition } from 'react-transition-group';
|
|
7
|
+
import Button from '@atlaskit/button/custom-theme-button';
|
|
8
|
+
import { Checkbox } from '@atlaskit/checkbox';
|
|
9
|
+
import Form, { CheckboxField, Field, FormFooter } from '@atlaskit/form';
|
|
10
|
+
import Textarea from '@atlaskit/textarea';
|
|
11
|
+
import { fontSize } from '@atlaskit/theme/constants';
|
|
12
|
+
import FeedbackScoreButtons from './FeedbackScoreButtons';
|
|
13
|
+
|
|
14
|
+
const getExpandedHeight = (ref, state) => {
|
|
15
|
+
if (!ref.current) {
|
|
16
|
+
return '0';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
switch (state) {
|
|
20
|
+
case 'entering':
|
|
21
|
+
return `${ref.current.scrollHeight}px`;
|
|
22
|
+
|
|
23
|
+
case 'entered':
|
|
24
|
+
// needed for TextField auto height expand
|
|
25
|
+
return `none`;
|
|
26
|
+
|
|
27
|
+
default:
|
|
28
|
+
return '0';
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const transitionDuration = 200;
|
|
33
|
+
export default (({
|
|
34
|
+
question,
|
|
35
|
+
statement,
|
|
36
|
+
textPlaceholder,
|
|
37
|
+
textLabel,
|
|
38
|
+
onSubmit
|
|
39
|
+
}) => {
|
|
40
|
+
const [expanded, setExpanded] = useState(false);
|
|
41
|
+
const [canContactDefault, setCanContactDefault] = useState(false);
|
|
42
|
+
const hasAutoFilledCanContactRef = useRef(false);
|
|
43
|
+
const expandedAreaRef = useRef(null);
|
|
44
|
+
const onScoreSelect = useCallback(() => {
|
|
45
|
+
setExpanded(true);
|
|
46
|
+
}, [setExpanded]); // On the first type the user types some feedback we auto select
|
|
47
|
+
// the option for allowing feedback. This automatic selection only
|
|
48
|
+
// happens once. After that it is up to the user to control
|
|
49
|
+
|
|
50
|
+
const onFeedbackChange = useCallback(() => {
|
|
51
|
+
if (hasAutoFilledCanContactRef.current) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
hasAutoFilledCanContactRef.current = true;
|
|
56
|
+
setCanContactDefault(true);
|
|
57
|
+
}, []);
|
|
58
|
+
return jsx("section", {
|
|
59
|
+
"aria-labelledby": "contextualSurveyQuestion"
|
|
60
|
+
}, jsx("h1", {
|
|
61
|
+
id: "contextualSurveyQuestion",
|
|
62
|
+
css: css`
|
|
63
|
+
font-size: ${fontSize()}px;
|
|
64
|
+
font-weight: 600;
|
|
65
|
+
`
|
|
66
|
+
}, question), statement && jsx("p", {
|
|
67
|
+
id: "contextualSurveyStatement"
|
|
68
|
+
}, statement), jsx(Form, {
|
|
69
|
+
onSubmit: onSubmit
|
|
70
|
+
}, ({
|
|
71
|
+
formProps,
|
|
72
|
+
submitting
|
|
73
|
+
}) => jsx("form", formProps, jsx(Field, {
|
|
74
|
+
name: "feedbackScore",
|
|
75
|
+
isDisabled: submitting,
|
|
76
|
+
isRequired: true
|
|
77
|
+
}, ({
|
|
78
|
+
fieldProps
|
|
79
|
+
}) => jsx(FeedbackScoreButtons, _extends({}, fieldProps, {
|
|
80
|
+
onChange: score => {
|
|
81
|
+
fieldProps.onChange(score);
|
|
82
|
+
onScoreSelect();
|
|
83
|
+
}
|
|
84
|
+
}))), jsx(Transition, {
|
|
85
|
+
in: expanded,
|
|
86
|
+
timeout: transitionDuration,
|
|
87
|
+
mountOnEnter: true
|
|
88
|
+
}, state => jsx("div", {
|
|
89
|
+
css: css`
|
|
90
|
+
transition: max-height ${transitionDuration}ms ease-in-out;
|
|
91
|
+
overflow: hidden;
|
|
92
|
+
max-height: ${getExpandedHeight(expandedAreaRef, state)};
|
|
93
|
+
`,
|
|
94
|
+
ref: expandedAreaRef
|
|
95
|
+
}, jsx(Field, {
|
|
96
|
+
name: "writtenFeedback",
|
|
97
|
+
defaultValue: "",
|
|
98
|
+
isDisabled: submitting
|
|
99
|
+
}, ({
|
|
100
|
+
fieldProps
|
|
101
|
+
}) => jsx(Textarea, _extends({}, fieldProps, {
|
|
102
|
+
"aria-label": textLabel,
|
|
103
|
+
placeholder: textPlaceholder,
|
|
104
|
+
onChange: event => {
|
|
105
|
+
fieldProps.onChange(event);
|
|
106
|
+
onFeedbackChange();
|
|
107
|
+
}
|
|
108
|
+
}))), jsx(CheckboxField, {
|
|
109
|
+
name: "canContact",
|
|
110
|
+
isDisabled: submitting,
|
|
111
|
+
defaultIsChecked: canContactDefault
|
|
112
|
+
}, ({
|
|
113
|
+
fieldProps
|
|
114
|
+
}) => jsx(Checkbox, _extends({}, fieldProps, {
|
|
115
|
+
label: "Atlassian can contact me about this feedback"
|
|
116
|
+
}))), jsx(FormFooter, null, jsx(Button, {
|
|
117
|
+
type: "submit",
|
|
118
|
+
appearance: "primary",
|
|
119
|
+
isLoading: submitting
|
|
120
|
+
}, "Submit")))))));
|
|
121
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { css, jsx } from '@emotion/core';
|
|
3
|
+
import { Transition } from 'react-transition-group';
|
|
4
|
+
import { layers } from '@atlaskit/theme/constants';
|
|
5
|
+
import { surveyInnerWidth, surveyOffset } from '../constants';
|
|
6
|
+
const animationDuration = 300;
|
|
7
|
+
const offscreen = {
|
|
8
|
+
translateX: `${surveyInnerWidth + surveyOffset}px`,
|
|
9
|
+
opacity: '0'
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const getAnimationProps = state => {
|
|
13
|
+
switch (state) {
|
|
14
|
+
case 'entering':
|
|
15
|
+
{
|
|
16
|
+
return offscreen;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
case 'entered':
|
|
20
|
+
{
|
|
21
|
+
return {
|
|
22
|
+
translateX: '0',
|
|
23
|
+
opacity: '1'
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
case 'exited':
|
|
28
|
+
case 'exiting':
|
|
29
|
+
{
|
|
30
|
+
return offscreen;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default function SurveyMarshal(props) {
|
|
36
|
+
const {
|
|
37
|
+
children,
|
|
38
|
+
shouldShow
|
|
39
|
+
} = props;
|
|
40
|
+
return jsx(Transition, {
|
|
41
|
+
in: shouldShow,
|
|
42
|
+
timeout: animationDuration,
|
|
43
|
+
unmountOnExit: true
|
|
44
|
+
}, state => {
|
|
45
|
+
const {
|
|
46
|
+
translateX,
|
|
47
|
+
opacity
|
|
48
|
+
} = getAnimationProps(state);
|
|
49
|
+
return jsx("div", {
|
|
50
|
+
css: css`
|
|
51
|
+
position: fixed;
|
|
52
|
+
right: ${surveyOffset}px;
|
|
53
|
+
bottom: ${surveyOffset}px;
|
|
54
|
+
z-index: ${layers.flag()};
|
|
55
|
+
transform: translateX(${translateX});
|
|
56
|
+
opacity: ${opacity};
|
|
57
|
+
transition: all ${animationDuration}ms ease-in-out;
|
|
58
|
+
transition-property: transform, opacity;
|
|
59
|
+
`
|
|
60
|
+
}, children());
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
export const escape = 27;
|
|
3
|
+
|
|
4
|
+
function bind(target, eventName, handler, options) {
|
|
5
|
+
target.addEventListener(eventName, handler, options);
|
|
6
|
+
return function unbind() {
|
|
7
|
+
target.removeEventListener(eventName, handler, options);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function shouldDismiss(target) {
|
|
12
|
+
if (!target) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!(target instanceof HTMLElement)) {
|
|
17
|
+
return true;
|
|
18
|
+
} // Closest doesn't exist for ie11
|
|
19
|
+
// Because we cannot be sure if in a text area - just don't allow dismissing
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if (!target.closest) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const inTextArea = Boolean(target.closest('textarea')); // Allow dismissing if not in a textarea
|
|
27
|
+
|
|
28
|
+
return !inTextArea;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default function useEscapeToDismiss({
|
|
32
|
+
onDismiss
|
|
33
|
+
}) {
|
|
34
|
+
const onDismissRef = useRef(onDismiss); // Defensively accounting for consumer passing in a new function
|
|
35
|
+
// each time. We just want to call the latest one
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
onDismissRef.current = onDismiss;
|
|
39
|
+
}, [onDismiss]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
let unbind;
|
|
42
|
+
|
|
43
|
+
function onKeyDown(event) {
|
|
44
|
+
if (event.keyCode !== escape) {
|
|
45
|
+
return;
|
|
46
|
+
} // Escape pressed
|
|
47
|
+
// We don't want to close if the user is typing in the text area
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if (!shouldDismiss(event.target)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (unbind) {
|
|
55
|
+
// only want to call dismiss once
|
|
56
|
+
unbind();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
onDismissRef.current();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
unbind = bind(window, 'keydown', // @ts-ignore: the typescript for this is lame
|
|
63
|
+
onKeyDown, {
|
|
64
|
+
passive: true
|
|
65
|
+
}); // double calls to unbind is fine
|
|
66
|
+
|
|
67
|
+
return unbind;
|
|
68
|
+
}, []);
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
5
|
+
import FeedbackAcknowledgement from './FeedbackAcknowledgement';
|
|
6
|
+
import SignUpPrompt from './SignUpPrompt';
|
|
7
|
+
import SignUpSuccess from './SignUpSuccess';
|
|
8
|
+
import SurveyContainer from './SurveyContainer';
|
|
9
|
+
import SurveyForm from './SurveyForm';
|
|
10
|
+
import useEscapeToDismiss from './useEscapeToDismiss';
|
|
11
|
+
export var DismissTrigger;
|
|
12
|
+
|
|
13
|
+
(function (DismissTrigger) {
|
|
14
|
+
DismissTrigger["AutoDismiss"] = "AUTO_DISMISS";
|
|
15
|
+
DismissTrigger["Manual"] = "MANUAL";
|
|
16
|
+
DismissTrigger["Finished"] = "FINISHED";
|
|
17
|
+
DismissTrigger["Unmount"] = "UNMOUNT";
|
|
18
|
+
})(DismissTrigger || (DismissTrigger = {}));
|
|
19
|
+
|
|
20
|
+
export var AUTO_DISAPPEAR_DURATION = 8000;
|
|
21
|
+
export default (function (_ref) {
|
|
22
|
+
var question = _ref.question,
|
|
23
|
+
statement = _ref.statement,
|
|
24
|
+
onDismiss = _ref.onDismiss,
|
|
25
|
+
onSubmit = _ref.onSubmit,
|
|
26
|
+
onMailingListAnswer = _ref.onMailingListAnswer,
|
|
27
|
+
getUserHasAnsweredMailingList = _ref.getUserHasAnsweredMailingList,
|
|
28
|
+
_ref$textLabel = _ref.textLabel,
|
|
29
|
+
textLabel = _ref$textLabel === void 0 ? 'Why did you give that rating' : _ref$textLabel,
|
|
30
|
+
_ref$textPlaceholder = _ref.textPlaceholder,
|
|
31
|
+
textPlaceholder = _ref$textPlaceholder === void 0 ? 'Tell us why' : _ref$textPlaceholder;
|
|
32
|
+
var autoDisappearTimeoutRef = useRef(null); // only allow a single dismiss for a component
|
|
33
|
+
|
|
34
|
+
var isDismissedRef = useRef(false);
|
|
35
|
+
var tryDismiss = useCallback(function (trigger) {
|
|
36
|
+
// Already called dismiss once
|
|
37
|
+
if (isDismissedRef.current) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
isDismissedRef.current = true;
|
|
42
|
+
onDismissRef.current({
|
|
43
|
+
trigger: trigger
|
|
44
|
+
});
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
var _useState = useState('SURVEY'),
|
|
48
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
49
|
+
currentStep = _useState2[0],
|
|
50
|
+
setCurrentStep = _useState2[1];
|
|
51
|
+
|
|
52
|
+
var trySetCurrentStep = useCallback(function (step) {
|
|
53
|
+
// Already dismissed - cannot update the step
|
|
54
|
+
if (isDismissedRef.current) {
|
|
55
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
56
|
+
// eslint-disable-next-line no-console
|
|
57
|
+
console.log("not setting step \"".concat(step, "\" as survey is already dismissed"));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
setCurrentStep(step);
|
|
64
|
+
}, [setCurrentStep]); // using a ref so that we don't break all of our caches if a consumer is using an arrow function
|
|
65
|
+
|
|
66
|
+
var onDismissRef = useRef(onDismiss);
|
|
67
|
+
useEffect(function () {
|
|
68
|
+
onDismissRef.current = onDismiss;
|
|
69
|
+
}, [onDismiss]);
|
|
70
|
+
var tryClearTimeout = useCallback(function () {
|
|
71
|
+
var id = autoDisappearTimeoutRef.current;
|
|
72
|
+
|
|
73
|
+
if (id) {
|
|
74
|
+
clearTimeout(id);
|
|
75
|
+
autoDisappearTimeoutRef.current = null;
|
|
76
|
+
}
|
|
77
|
+
}, []); // Cleanup any auto dismiss after dismiss
|
|
78
|
+
|
|
79
|
+
useEffect(function () {
|
|
80
|
+
return function unmount() {
|
|
81
|
+
tryClearTimeout();
|
|
82
|
+
tryDismiss(DismissTrigger.Unmount);
|
|
83
|
+
};
|
|
84
|
+
}, [tryClearTimeout, tryDismiss]);
|
|
85
|
+
var onSurveySubmit = useCallback( /*#__PURE__*/function () {
|
|
86
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(formValues, form) {
|
|
87
|
+
var callback,
|
|
88
|
+
userHasAnswered,
|
|
89
|
+
_args = arguments;
|
|
90
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
91
|
+
while (1) {
|
|
92
|
+
switch (_context.prev = _context.next) {
|
|
93
|
+
case 0:
|
|
94
|
+
callback = _args.length > 2 && _args[2] !== undefined ? _args[2] : function () {};
|
|
95
|
+
_context.next = 3;
|
|
96
|
+
return onSubmit(formValues);
|
|
97
|
+
|
|
98
|
+
case 3:
|
|
99
|
+
if (!isDismissedRef.current) {
|
|
100
|
+
_context.next = 6;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
callback();
|
|
105
|
+
return _context.abrupt("return");
|
|
106
|
+
|
|
107
|
+
case 6:
|
|
108
|
+
if (formValues.canContact) {
|
|
109
|
+
_context.next = 10;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
callback();
|
|
114
|
+
trySetCurrentStep('POST_SURVEY_NO_CONSENT');
|
|
115
|
+
return _context.abrupt("return");
|
|
116
|
+
|
|
117
|
+
case 10:
|
|
118
|
+
_context.next = 12;
|
|
119
|
+
return getUserHasAnsweredMailingList();
|
|
120
|
+
|
|
121
|
+
case 12:
|
|
122
|
+
userHasAnswered = _context.sent;
|
|
123
|
+
callback(); // Not entering phase 2: user has already answered this question
|
|
124
|
+
|
|
125
|
+
if (!userHasAnswered) {
|
|
126
|
+
_context.next = 17;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
trySetCurrentStep('POST_SURVEY_HAS_SIGN_UP');
|
|
131
|
+
return _context.abrupt("return");
|
|
132
|
+
|
|
133
|
+
case 17:
|
|
134
|
+
// Enter phase 2
|
|
135
|
+
trySetCurrentStep('SIGN_UP_PROMPT');
|
|
136
|
+
|
|
137
|
+
case 18:
|
|
138
|
+
case "end":
|
|
139
|
+
return _context.stop();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}, _callee);
|
|
143
|
+
}));
|
|
144
|
+
|
|
145
|
+
return function (_x, _x2) {
|
|
146
|
+
return _ref2.apply(this, arguments);
|
|
147
|
+
};
|
|
148
|
+
}(), [getUserHasAnsweredMailingList, onSubmit, trySetCurrentStep]);
|
|
149
|
+
var onMailingListResponse = useCallback( /*#__PURE__*/function () {
|
|
150
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(answer) {
|
|
151
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
152
|
+
while (1) {
|
|
153
|
+
switch (_context2.prev = _context2.next) {
|
|
154
|
+
case 0:
|
|
155
|
+
_context2.next = 2;
|
|
156
|
+
return onMailingListAnswer(answer);
|
|
157
|
+
|
|
158
|
+
case 2:
|
|
159
|
+
if (!answer) {
|
|
160
|
+
_context2.next = 5;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
trySetCurrentStep('SIGN_UP_SUCCESS');
|
|
165
|
+
return _context2.abrupt("return");
|
|
166
|
+
|
|
167
|
+
case 5:
|
|
168
|
+
// We have already thanked to user, we can simply close
|
|
169
|
+
tryDismiss(DismissTrigger.Finished);
|
|
170
|
+
|
|
171
|
+
case 6:
|
|
172
|
+
case "end":
|
|
173
|
+
return _context2.stop();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}, _callee2);
|
|
177
|
+
}));
|
|
178
|
+
|
|
179
|
+
return function (_x3) {
|
|
180
|
+
return _ref3.apply(this, arguments);
|
|
181
|
+
};
|
|
182
|
+
}(), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
183
|
+
[tryDismiss, trySetCurrentStep]); // Start the auto disappear when we are finished
|
|
184
|
+
|
|
185
|
+
useEffect(function () {
|
|
186
|
+
// Already dismissed
|
|
187
|
+
if (isDismissedRef.current) {
|
|
188
|
+
return;
|
|
189
|
+
} // Timeout already scheduled
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
if (autoDisappearTimeoutRef.current) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (['SIGN_UP_SUCCESS', 'POST_SURVEY_NO_CONSENT', 'POST_SURVEY_HAS_SIGN_UP'].includes(currentStep)) {
|
|
197
|
+
autoDisappearTimeoutRef.current = window.setTimeout(function () {
|
|
198
|
+
return tryDismiss(DismissTrigger.AutoDismiss);
|
|
199
|
+
}, AUTO_DISAPPEAR_DURATION);
|
|
200
|
+
}
|
|
201
|
+
}, [currentStep, tryDismiss]);
|
|
202
|
+
useEscapeToDismiss({
|
|
203
|
+
onDismiss: function onDismiss() {
|
|
204
|
+
return tryDismiss(DismissTrigger.Manual);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
var content = function () {
|
|
209
|
+
if (currentStep === 'SURVEY') {
|
|
210
|
+
return /*#__PURE__*/React.createElement(SurveyForm, {
|
|
211
|
+
question: question,
|
|
212
|
+
statement: statement,
|
|
213
|
+
textLabel: textLabel,
|
|
214
|
+
textPlaceholder: textPlaceholder,
|
|
215
|
+
onSubmit: onSurveySubmit
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (currentStep === 'SIGN_UP_PROMPT') {
|
|
220
|
+
return /*#__PURE__*/React.createElement(SignUpPrompt, {
|
|
221
|
+
onAnswer: onMailingListResponse
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (currentStep === 'SIGN_UP_SUCCESS') {
|
|
226
|
+
return /*#__PURE__*/React.createElement(SignUpSuccess, null);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (currentStep === 'POST_SURVEY_NO_CONSENT' || currentStep === 'POST_SURVEY_HAS_SIGN_UP') {
|
|
230
|
+
return /*#__PURE__*/React.createElement(FeedbackAcknowledgement, null);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return null;
|
|
234
|
+
}();
|
|
235
|
+
|
|
236
|
+
var manualDismiss = useCallback(function () {
|
|
237
|
+
// clear any pending timers
|
|
238
|
+
tryClearTimeout();
|
|
239
|
+
tryDismiss(DismissTrigger.Manual);
|
|
240
|
+
}, [tryDismiss, tryClearTimeout]);
|
|
241
|
+
return /*#__PURE__*/React.createElement(SurveyContainer, {
|
|
242
|
+
onDismiss: manualDismiss
|
|
243
|
+
}, content);
|
|
244
|
+
});
|