@kindly/react-chat 2.35.2 → 2.36.1
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/.storybook/main.js +72 -0
- package/.storybook/preview.js +48 -0
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +26 -12
- package/stories/assets/settingsJson.js +449 -0
- package/stories/decorators/withContainer.js +13 -0
- package/stories/decorators/withProvider.js +22 -0
- package/stories/screens.stories/Chat.stories.jsx +602 -0
- package/stories/screens.stories/ClosedButton.stories.jsx +87 -0
- package/stories/screens.stories/Feedback.stories.jsx +109 -0
- package/stories/screens.stories/Nudge.stories.jsx +125 -0
- package/stories/screens.stories/Options.stories.jsx +126 -0
- package/stories/screens.stories/StartChat.stories.jsx +109 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
+
/* eslint-disable react/prop-types */
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import withFetchMock from 'storybook-addon-mock';
|
|
5
|
+
|
|
6
|
+
import { feedbackFormTypes } from 'app/constants';
|
|
7
|
+
|
|
8
|
+
import KindlyChatButton from '../../src/features/KindlyChatButton/KindlyChatButton';
|
|
9
|
+
import settingsJSON from '../assets/settingsJson';
|
|
10
|
+
import withContainer from '../decorators/withContainer';
|
|
11
|
+
import withMockProvider from '../decorators/withProvider';
|
|
12
|
+
|
|
13
|
+
const defaultBotSettings = {
|
|
14
|
+
welcomePage: settingsJSON.welcome_page,
|
|
15
|
+
feedbackForm: settingsJSON.feedback_form,
|
|
16
|
+
maintenanceAlert: settingsJSON.maintenance_alert,
|
|
17
|
+
...settingsJSON.settings,
|
|
18
|
+
...settingsJSON,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const Template = (args, context) => {
|
|
22
|
+
return <KindlyChatButton {...args} {...context} />;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
title: 'Screen/Feedback',
|
|
27
|
+
component: KindlyChatButton,
|
|
28
|
+
decorators: [withFetchMock, withContainer, withMockProvider],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const Emojis = Template.bind({});
|
|
32
|
+
Emojis.parameters = {
|
|
33
|
+
botSettings: {
|
|
34
|
+
...defaultBotSettings,
|
|
35
|
+
feedbackForm: {
|
|
36
|
+
...defaultBotSettings.feedbackForm,
|
|
37
|
+
type: feedbackFormTypes.EMOJIS,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
initialStateModifier: {
|
|
41
|
+
chatbubble: {
|
|
42
|
+
active: false,
|
|
43
|
+
currentLanguage: 'en',
|
|
44
|
+
},
|
|
45
|
+
feedback: {
|
|
46
|
+
feedbackFormOpen: true,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const Binary = Template.bind({});
|
|
52
|
+
Binary.parameters = {
|
|
53
|
+
botSettings: {
|
|
54
|
+
...defaultBotSettings,
|
|
55
|
+
feedbackForm: {
|
|
56
|
+
...defaultBotSettings.feedbackForm,
|
|
57
|
+
type: feedbackFormTypes.BINARY,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
initialStateModifier: {
|
|
61
|
+
chatbubble: {
|
|
62
|
+
active: false,
|
|
63
|
+
currentLanguage: 'en',
|
|
64
|
+
},
|
|
65
|
+
feedback: {
|
|
66
|
+
feedbackFormOpen: true,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const HappyOrNot = Template.bind({});
|
|
72
|
+
HappyOrNot.parameters = {
|
|
73
|
+
botSettings: {
|
|
74
|
+
...defaultBotSettings,
|
|
75
|
+
feedbackForm: {
|
|
76
|
+
...defaultBotSettings.feedbackForm,
|
|
77
|
+
type: feedbackFormTypes.HAPPY_OR_NOT,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
initialStateModifier: {
|
|
81
|
+
chatbubble: {
|
|
82
|
+
active: false,
|
|
83
|
+
currentLanguage: 'en',
|
|
84
|
+
},
|
|
85
|
+
feedback: {
|
|
86
|
+
feedbackFormOpen: true,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const ExternalLink = Template.bind({});
|
|
92
|
+
ExternalLink.parameters = {
|
|
93
|
+
botSettings: {
|
|
94
|
+
...defaultBotSettings,
|
|
95
|
+
feedbackForm: {
|
|
96
|
+
...defaultBotSettings.feedbackForm,
|
|
97
|
+
type: feedbackFormTypes.EXTERNAL_LINK,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
initialStateModifier: {
|
|
101
|
+
chatbubble: {
|
|
102
|
+
active: false,
|
|
103
|
+
currentLanguage: 'en',
|
|
104
|
+
},
|
|
105
|
+
feedback: {
|
|
106
|
+
feedbackFormOpen: true,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/* eslint-disable react/prop-types */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import withMock from 'storybook-addon-mock';
|
|
4
|
+
|
|
5
|
+
import KindlyChat from '../../src/KindlyChat';
|
|
6
|
+
import settings from '../assets/settingsJson';
|
|
7
|
+
|
|
8
|
+
const mockSettings = (response = settings) => ({
|
|
9
|
+
mockData: [
|
|
10
|
+
{
|
|
11
|
+
url: 'https://example.com/mockme/settings/1234.json?version=:version&kindly-chat-browser-id=:browserId',
|
|
12
|
+
method: 'GET',
|
|
13
|
+
status: 200,
|
|
14
|
+
response,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const Template = ({ slug, nudgeLayout, trackEvent, options, ...args }) => {
|
|
20
|
+
return (
|
|
21
|
+
<KindlyChat
|
|
22
|
+
botKey={'1234'}
|
|
23
|
+
options={options || {}}
|
|
24
|
+
{...args}
|
|
25
|
+
setKindlyChatRef={(api) => {
|
|
26
|
+
api?.showNudge({
|
|
27
|
+
slug,
|
|
28
|
+
nudgeLayout,
|
|
29
|
+
trackEvent,
|
|
30
|
+
});
|
|
31
|
+
}}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default {
|
|
37
|
+
title: 'Screen/Nudges',
|
|
38
|
+
component: KindlyChat,
|
|
39
|
+
decorators: [withMock],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const Product = Template.bind({});
|
|
43
|
+
Product.parameters = mockSettings();
|
|
44
|
+
Product.args = {
|
|
45
|
+
slug: settings.nudges.product_nudges[0].slug,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const Form = Template.bind({});
|
|
49
|
+
Form.parameters = mockSettings();
|
|
50
|
+
Form.args = {
|
|
51
|
+
slug: settings.nudges.form_nudges[0].slug,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const MultipleChoice = Template.bind({});
|
|
55
|
+
MultipleChoice.parameters = mockSettings();
|
|
56
|
+
MultipleChoice.args = {
|
|
57
|
+
slug: settings.nudges.multiple_choice_nudges[0].slug,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const TextNudge = Template.bind({});
|
|
61
|
+
TextNudge.parameters = mockSettings();
|
|
62
|
+
TextNudge.args = {
|
|
63
|
+
slug: settings.nudges.text_nudges[0].slug,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const FullCustom = Template.bind({});
|
|
67
|
+
FullCustom.parameters = mockSettings();
|
|
68
|
+
FullCustom.args = {
|
|
69
|
+
nudgeLayout: {
|
|
70
|
+
sections: [
|
|
71
|
+
{
|
|
72
|
+
html: () => `
|
|
73
|
+
<style>
|
|
74
|
+
.nudge-text {
|
|
75
|
+
width: 50%;
|
|
76
|
+
font-weight: bold;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
p {
|
|
80
|
+
color: #333;
|
|
81
|
+
font-size: 14px;
|
|
82
|
+
}
|
|
83
|
+
</style>
|
|
84
|
+
<div class="nudge-wrapper">
|
|
85
|
+
<div class="nudge-text">
|
|
86
|
+
<p>Full Custom</p>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
`,
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const Custom = Template.bind({});
|
|
96
|
+
Custom.parameters = mockSettings();
|
|
97
|
+
Custom.args = {
|
|
98
|
+
slug: settings.nudges.custom_nudges[0].slug,
|
|
99
|
+
nudgeLayout: {
|
|
100
|
+
sections: [
|
|
101
|
+
{
|
|
102
|
+
html: (textContent) => `
|
|
103
|
+
<style>
|
|
104
|
+
.nudge-text {
|
|
105
|
+
width: 50%;
|
|
106
|
+
font-weight: bold;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
p {
|
|
110
|
+
color: #333;
|
|
111
|
+
font-size: 14px;
|
|
112
|
+
}
|
|
113
|
+
</style>
|
|
114
|
+
<div class="nudge-wrapper">
|
|
115
|
+
<div class="nudge-text">
|
|
116
|
+
<p>${textContent.text}</p>
|
|
117
|
+
<p>${textContent.text2}</p>
|
|
118
|
+
<p>${textContent.text3}</p>
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
`,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
+
/* eslint-disable react/prop-types */
|
|
3
|
+
import { screen, userEvent } from '@storybook/testing-library';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import withFetchMock from 'storybook-addon-mock';
|
|
6
|
+
|
|
7
|
+
import KindlyChatButton from '../../src/features/KindlyChatButton/KindlyChatButton';
|
|
8
|
+
|
|
9
|
+
import settingsJSON from '../assets/settingsJson';
|
|
10
|
+
import withContainer from '../decorators/withContainer';
|
|
11
|
+
import withMockProvider from '../decorators/withProvider';
|
|
12
|
+
|
|
13
|
+
const defaultBotSettings = {
|
|
14
|
+
welcomePage: settingsJSON.welcome_page,
|
|
15
|
+
feedbackForm: settingsJSON.feedback_form,
|
|
16
|
+
maintenanceAlert: settingsJSON.maintenance_alert,
|
|
17
|
+
...settingsJSON.settings,
|
|
18
|
+
...settingsJSON,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const Template = (args, context) => {
|
|
22
|
+
return <KindlyChatButton {...args} {...context} />;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
title: 'Screen/Options',
|
|
27
|
+
component: KindlyChatButton,
|
|
28
|
+
decorators: [withFetchMock, withContainer, withMockProvider],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const Regular = Template.bind({});
|
|
32
|
+
Regular.parameters = {
|
|
33
|
+
botSettings: defaultBotSettings,
|
|
34
|
+
initialStateModifier: {
|
|
35
|
+
chatbubble: {
|
|
36
|
+
active: true,
|
|
37
|
+
chatHasStarted: true,
|
|
38
|
+
currentLanguage: 'en',
|
|
39
|
+
optionsScreenOpen: true,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const WithLanguageChoice = Template.bind({});
|
|
45
|
+
WithLanguageChoice.parameters = {
|
|
46
|
+
botSettings: {
|
|
47
|
+
...defaultBotSettings,
|
|
48
|
+
languages: [
|
|
49
|
+
{
|
|
50
|
+
code: 'en',
|
|
51
|
+
name: 'English',
|
|
52
|
+
active: true,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
code: 'nb',
|
|
56
|
+
name: 'Norsk (bokmål)',
|
|
57
|
+
active: true,
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
initialStateModifier: {
|
|
62
|
+
chatbubble: {
|
|
63
|
+
active: true,
|
|
64
|
+
chatHasStarted: true,
|
|
65
|
+
currentLanguage: 'en',
|
|
66
|
+
optionsScreenOpen: true,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const LanguageChoice = Template.bind({});
|
|
72
|
+
LanguageChoice.parameters = WithLanguageChoice.parameters;
|
|
73
|
+
LanguageChoice.play = async () => {
|
|
74
|
+
const languageButton = await screen.findByText(defaultBotSettings.text.change_language_button.en);
|
|
75
|
+
await userEvent.click(languageButton);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const LanguageChoiceConfirm = Template.bind({});
|
|
79
|
+
LanguageChoiceConfirm.parameters = WithLanguageChoice.parameters;
|
|
80
|
+
LanguageChoiceConfirm.play = async () => {
|
|
81
|
+
const languageButton = await screen.findByText(defaultBotSettings.text.change_language_button.en);
|
|
82
|
+
await userEvent.click(languageButton);
|
|
83
|
+
const norskButton = await screen.findByText(LanguageChoiceConfirm.parameters.botSettings.languages[1].name);
|
|
84
|
+
await userEvent.click(norskButton);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const DeleteConfirmation = Template.bind({});
|
|
88
|
+
DeleteConfirmation.parameters = Regular.parameters;
|
|
89
|
+
DeleteConfirmation.play = async () => {
|
|
90
|
+
const deleteButton = await screen.findByText(defaultBotSettings.text.delete_button.en);
|
|
91
|
+
await userEvent.click(deleteButton);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const DeleteSuccess = Template.bind({});
|
|
95
|
+
DeleteSuccess.parameters = {
|
|
96
|
+
...Regular.parameters,
|
|
97
|
+
initialStateModifier: {
|
|
98
|
+
...Regular.parameters.initialStateModifier,
|
|
99
|
+
privacy: {
|
|
100
|
+
chatDeleted: true,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const DownloadChat = Template.bind({});
|
|
106
|
+
DownloadChat.parameters = Regular.parameters;
|
|
107
|
+
DownloadChat.play = async () => {
|
|
108
|
+
const downloadButton = await screen.findByText(defaultBotSettings.text.download_button.en);
|
|
109
|
+
await userEvent.click(downloadButton);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const QuitChat = Template.bind({});
|
|
113
|
+
QuitChat.parameters = {
|
|
114
|
+
...Regular.parameters,
|
|
115
|
+
initialStateModifier: {
|
|
116
|
+
chatbubble: {
|
|
117
|
+
active: true,
|
|
118
|
+
chatHasStarted: true,
|
|
119
|
+
currentLanguage: 'en',
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
QuitChat.play = async () => {
|
|
124
|
+
const deleteButton = await screen.findByTestId('end-chat-button');
|
|
125
|
+
await userEvent.click(deleteButton);
|
|
126
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
+
/* eslint-disable react/prop-types */
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
import KindlyChatButton from '../../src/features/KindlyChatButton/KindlyChatButton';
|
|
6
|
+
import settingsJSON from '../assets/settingsJson';
|
|
7
|
+
import withContainer from '../decorators/withContainer';
|
|
8
|
+
import withMockProvider from '../decorators/withProvider';
|
|
9
|
+
|
|
10
|
+
const defaultBotSettings = {
|
|
11
|
+
welcomePage: settingsJSON.welcome_page,
|
|
12
|
+
feedbackForm: settingsJSON.feedback_form,
|
|
13
|
+
maintenanceAlert: settingsJSON.maintenance_alert,
|
|
14
|
+
...settingsJSON.settings,
|
|
15
|
+
...settingsJSON,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const Template = (args, context) => {
|
|
19
|
+
return <KindlyChatButton {...args} {...context} />;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
title: 'Screen/StartChat',
|
|
24
|
+
component: KindlyChatButton,
|
|
25
|
+
decorators: [withContainer, withMockProvider],
|
|
26
|
+
parameters: {
|
|
27
|
+
botSettings: defaultBotSettings,
|
|
28
|
+
initialStateModifier: {
|
|
29
|
+
chatbubble: {
|
|
30
|
+
active: true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const Regular = Template.bind({});
|
|
37
|
+
|
|
38
|
+
export const WithLanguageChoice = Template.bind({});
|
|
39
|
+
WithLanguageChoice.parameters = {
|
|
40
|
+
botSettings: {
|
|
41
|
+
...defaultBotSettings,
|
|
42
|
+
languages: [
|
|
43
|
+
{
|
|
44
|
+
code: 'en',
|
|
45
|
+
name: 'English',
|
|
46
|
+
active: true,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
code: 'nb',
|
|
50
|
+
name: 'Norsk (bokmål)',
|
|
51
|
+
active: true,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
initialStateModifier: {
|
|
56
|
+
chatbubble: {
|
|
57
|
+
active: true,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const WithPicture = Template.bind({});
|
|
63
|
+
WithPicture.parameters = {
|
|
64
|
+
botSettings: {
|
|
65
|
+
...defaultBotSettings,
|
|
66
|
+
welcomePage: {
|
|
67
|
+
...defaultBotSettings.welcomePage,
|
|
68
|
+
image: 'https://i.imgur.com/wcfVY0C.png',
|
|
69
|
+
type: 'PICTURE',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
initialStateModifier: {
|
|
73
|
+
chatbubble: {
|
|
74
|
+
active: true,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const TextLeftToRight = Template.bind({});
|
|
80
|
+
TextLeftToRight.parameters = {
|
|
81
|
+
botSettings: {
|
|
82
|
+
...defaultBotSettings,
|
|
83
|
+
text_right_to_left: true,
|
|
84
|
+
languages: [
|
|
85
|
+
{
|
|
86
|
+
code: 'ar',
|
|
87
|
+
name: 'Arabic',
|
|
88
|
+
active: true,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
welcomePage: {
|
|
92
|
+
...defaultBotSettings.welcomePage,
|
|
93
|
+
header: {
|
|
94
|
+
en: 'مرحبا ، مرحبا بكم في chatbot لدينا!',
|
|
95
|
+
},
|
|
96
|
+
text: {
|
|
97
|
+
en: '<p>تم تدريب chatbot الخاص بنا على الإجابة عن الأسئلة المتعلقة بمنتجنا ، ولكنه يتعلم باستمرار. حاول أن تجعل أسئلتك دقيقة قدر الإمكان. لا تزود برنامج الدردشة الآلي بأي معلومات شخصية.</p>',
|
|
98
|
+
},
|
|
99
|
+
start_button: {
|
|
100
|
+
en: 'ابدأ الدردشة',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
initialStateModifier: {
|
|
105
|
+
chatbubble: {
|
|
106
|
+
active: true,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
};
|