react-native-my-survey-sdk 3.0.0 → 3.0.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.
Files changed (75) hide show
  1. package/dist/components/XeboDropdownView.d.ts +10 -0
  2. package/dist/components/XeboDropdownView.d.ts.map +1 -0
  3. package/dist/components/XeboDropdownView.js +190 -0
  4. package/dist/components/XeboIntroView.d.ts +9 -0
  5. package/dist/components/XeboIntroView.d.ts.map +1 -0
  6. package/dist/components/XeboIntroView.js +54 -0
  7. package/dist/components/XeboMultiNPSView.d.ts +10 -0
  8. package/dist/components/XeboMultiNPSView.d.ts.map +1 -0
  9. package/dist/components/XeboMultiNPSView.js +170 -0
  10. package/dist/components/XeboMultiRatingView.d.ts +10 -0
  11. package/dist/components/XeboMultiRatingView.d.ts.map +1 -0
  12. package/dist/components/XeboMultiRatingView.js +154 -0
  13. package/dist/components/XeboMultipleChoiceView.d.ts +10 -0
  14. package/dist/components/XeboMultipleChoiceView.d.ts.map +1 -0
  15. package/dist/components/XeboMultipleChoiceView.js +188 -0
  16. package/dist/components/XeboNPSView.d.ts +10 -0
  17. package/dist/components/XeboNPSView.d.ts.map +1 -0
  18. package/dist/components/XeboNPSView.js +269 -0
  19. package/dist/components/XeboRatingView.d.ts +10 -0
  20. package/dist/components/XeboRatingView.d.ts.map +1 -0
  21. package/dist/components/XeboRatingView.js +248 -0
  22. package/dist/components/XeboSingleChoiceView.d.ts +10 -0
  23. package/dist/components/XeboSingleChoiceView.d.ts.map +1 -0
  24. package/dist/components/XeboSingleChoiceView.js +172 -0
  25. package/dist/components/XeboSurveyModal.d.ts +3 -0
  26. package/dist/components/XeboSurveyModal.d.ts.map +1 -0
  27. package/dist/components/XeboSurveyModal.js +345 -0
  28. package/dist/components/XeboTextBoxView.d.ts +10 -0
  29. package/dist/components/XeboTextBoxView.d.ts.map +1 -0
  30. package/dist/components/XeboTextBoxView.js +176 -0
  31. package/dist/components/XeboThankYouView.d.ts +9 -0
  32. package/dist/components/XeboThankYouView.d.ts.map +1 -0
  33. package/dist/components/XeboThankYouView.js +115 -0
  34. package/dist/core/XeboNetworkService.d.ts +34 -0
  35. package/dist/core/XeboNetworkService.d.ts.map +1 -0
  36. package/dist/core/XeboNetworkService.js +367 -0
  37. package/dist/core/XeboOfflineQueue.d.ts +8 -0
  38. package/dist/core/XeboOfflineQueue.d.ts.map +1 -0
  39. package/dist/core/XeboOfflineQueue.js +35 -0
  40. package/dist/core/XeboSurveyManager.d.ts +59 -0
  41. package/dist/core/XeboSurveyManager.d.ts.map +1 -0
  42. package/dist/core/XeboSurveyManager.js +351 -0
  43. package/dist/index.d.ts +5 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +12 -0
  46. package/dist/models/XeboAPIModels.d.ts +82 -0
  47. package/dist/models/XeboAPIModels.d.ts.map +1 -0
  48. package/dist/models/XeboAPIModels.js +4 -0
  49. package/dist/models/XeboModels.d.ts +141 -0
  50. package/dist/models/XeboModels.d.ts.map +1 -0
  51. package/dist/models/XeboModels.js +17 -0
  52. package/dist/theme/XeboTheme.d.ts +11 -0
  53. package/dist/theme/XeboTheme.d.ts.map +1 -0
  54. package/dist/theme/XeboTheme.js +25 -0
  55. package/package.json +10 -3
  56. package/babel.config.js +0 -4
  57. package/src/components/XeboDropdownView.tsx +0 -197
  58. package/src/components/XeboIntroView.tsx +0 -68
  59. package/src/components/XeboMultiNPSView.tsx +0 -166
  60. package/src/components/XeboMultiRatingView.tsx +0 -165
  61. package/src/components/XeboMultipleChoiceView.tsx +0 -183
  62. package/src/components/XeboNPSView.tsx +0 -315
  63. package/src/components/XeboRatingView.tsx +0 -267
  64. package/src/components/XeboSingleChoiceView.tsx +0 -168
  65. package/src/components/XeboSurveyModal.tsx +0 -360
  66. package/src/components/XeboTextBoxView.tsx +0 -188
  67. package/src/components/XeboThankYouView.tsx +0 -100
  68. package/src/core/XeboNetworkService.ts +0 -476
  69. package/src/core/XeboOfflineQueue.ts +0 -33
  70. package/src/core/XeboSurveyManager.ts +0 -422
  71. package/src/index.ts +0 -23
  72. package/src/models/XeboAPIModels.ts +0 -80
  73. package/src/models/XeboModels.ts +0 -169
  74. package/src/theme/XeboTheme.ts +0 -33
  75. package/tsconfig.json +0 -17
@@ -1,183 +0,0 @@
1
- import React, { useRef, useState } from 'react';
2
- import {
3
- View,
4
- Text,
5
- TouchableOpacity,
6
- StyleSheet,
7
- ScrollView,
8
- Animated,
9
- } from 'react-native';
10
- import { XeboQuestion, XeboAnswer, XeboChoice } from '../models/XeboModels';
11
- import { getTheme } from '../theme/XeboTheme';
12
-
13
- interface Props {
14
- question: XeboQuestion;
15
- isLastQuestion: boolean;
16
- onAnswer: (answer: XeboAnswer) => void;
17
- }
18
-
19
- export const XeboMultipleChoiceView: React.FC<Props> = ({ question, isLastQuestion, onAnswer }) => {
20
- const theme = getTheme();
21
- const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
22
- const [error, setError] = useState('');
23
- const shakeAnim = useRef(new Animated.Value(0)).current;
24
-
25
- const shake = () => {
26
- Animated.sequence([
27
- Animated.timing(shakeAnim, { toValue: 8, duration: 60, useNativeDriver: true }),
28
- Animated.timing(shakeAnim, { toValue: -8, duration: 60, useNativeDriver: true }),
29
- Animated.timing(shakeAnim, { toValue: 6, duration: 60, useNativeDriver: true }),
30
- Animated.timing(shakeAnim, { toValue: 0, duration: 60, useNativeDriver: true }),
31
- ]).start();
32
- };
33
-
34
- const toggleChoice = (choice: XeboChoice) => {
35
- setSelectedIds(prev => {
36
- const next = new Set(prev);
37
- if (next.has(choice.id)) {
38
- next.delete(choice.id);
39
- } else {
40
- next.add(choice.id);
41
- }
42
- return next;
43
- });
44
- setError('');
45
- };
46
-
47
- const handleNext = () => {
48
- if (question.isRequired && selectedIds.size === 0) {
49
- setError('Please select at least one option.');
50
- shake();
51
- return;
52
- }
53
- onAnswer({
54
- questionId: question.id,
55
- value: Array.from(selectedIds).map(id => ({
56
- rowId: id,
57
- text: question.options?.find((o: XeboChoice) => o.id === id)?.text,
58
- })),
59
- });
60
- };
61
-
62
- return (
63
- <View style={styles.container}>
64
- <Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
65
- {question.title}
66
- </Text>
67
- {!!question.subtitle && (
68
- <Text style={[styles.subtitle, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
69
- {question.subtitle}
70
- </Text>
71
- )}
72
-
73
- <ScrollView style={styles.optionsList} showsVerticalScrollIndicator={false}>
74
- {(question.options ?? []).map((choice: XeboChoice) => {
75
- const selected = selectedIds.has(choice.id);
76
- return (
77
- <TouchableOpacity
78
- key={choice.id}
79
- style={[
80
- styles.optionRow,
81
- { borderColor: selected ? theme.primaryColor : '#E5E7EB' },
82
- ]}
83
- onPress={() => toggleChoice(choice)}
84
- activeOpacity={0.7}
85
- >
86
- <View
87
- style={[
88
- styles.checkbox,
89
- {
90
- borderColor: selected ? theme.primaryColor : '#9CA3AF',
91
- backgroundColor: selected ? theme.primaryColor : 'transparent',
92
- },
93
- ]}
94
- >
95
- {selected && <Text style={styles.checkmark}>✓</Text>}
96
- </View>
97
- <Text style={[styles.optionText, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
98
- {choice.text}
99
- </Text>
100
- </TouchableOpacity>
101
- );
102
- })}
103
- </ScrollView>
104
-
105
- {!!error && <Text style={styles.errorText}>{error}</Text>}
106
-
107
- <Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
108
- <TouchableOpacity
109
- style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius }]}
110
- onPress={handleNext}
111
- activeOpacity={0.8}
112
- >
113
- <Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
114
- {isLastQuestion ? 'Submit' : 'Next'}
115
- </Text>
116
- </TouchableOpacity>
117
- </Animated.View>
118
- </View>
119
- );
120
- };
121
-
122
- const styles = StyleSheet.create({
123
- container: {
124
- paddingHorizontal: 20,
125
- paddingTop: 16,
126
- paddingBottom: 24,
127
- },
128
- title: {
129
- fontSize: 18,
130
- fontWeight: '700',
131
- marginBottom: 16,
132
- },
133
- subtitle: {
134
- fontSize: 14,
135
- opacity: 0.6,
136
- marginBottom: 16,
137
- },
138
- optionsList: {
139
- maxHeight: 280,
140
- marginBottom: 12,
141
- },
142
- optionRow: {
143
- flexDirection: 'row',
144
- alignItems: 'center',
145
- borderWidth: 1.5,
146
- borderRadius: 10,
147
- padding: 14,
148
- marginBottom: 10,
149
- },
150
- checkbox: {
151
- width: 20,
152
- height: 20,
153
- borderRadius: 4,
154
- borderWidth: 2,
155
- alignItems: 'center',
156
- justifyContent: 'center',
157
- marginRight: 12,
158
- },
159
- checkmark: {
160
- color: '#FFFFFF',
161
- fontSize: 13,
162
- fontWeight: '700',
163
- },
164
- optionText: {
165
- fontSize: 15,
166
- flex: 1,
167
- },
168
- errorText: {
169
- color: '#EF4444',
170
- fontSize: 13,
171
- marginBottom: 8,
172
- },
173
- button: {
174
- paddingVertical: 14,
175
- alignItems: 'center',
176
- marginTop: 4,
177
- },
178
- buttonText: {
179
- color: '#FFFFFF',
180
- fontSize: 16,
181
- fontWeight: '600',
182
- },
183
- });
@@ -1,315 +0,0 @@
1
- import React, { useRef, useState } from 'react';
2
- import {
3
- View,
4
- Text,
5
- TouchableOpacity,
6
- StyleSheet,
7
- ScrollView,
8
- Animated,
9
- TextInput,
10
- Keyboard,
11
- } from 'react-native';
12
- import { XeboQuestion, XeboAnswer, XeboConditionalFollowUp, XeboQuestionType } from '../models/XeboModels';
13
- import { getTheme } from '../theme/XeboTheme';
14
-
15
- interface Props {
16
- question: XeboQuestion;
17
- isLastQuestion: boolean;
18
- onAnswer: (answer: XeboAnswer | XeboAnswer[]) => void;
19
- }
20
-
21
- // NPS zone colors — matches iOS SDK defaults
22
- const DETRACTOR_COLOR = '#F24236';
23
- const PASSIVE_COLOR = '#FFC208';
24
- const PROMOTER_COLOR = '#2ECC70';
25
-
26
- function npsColor(score: number, npsLabels?: XeboQuestion['npsLabels']): string {
27
- if (score <= 6) return npsLabels?.detractorColor ?? DETRACTOR_COLOR;
28
- if (score <= 8) return npsLabels?.passiveColor ?? PASSIVE_COLOR;
29
- return npsLabels?.promoterColor ?? PROMOTER_COLOR;
30
- }
31
-
32
- /** Returns true if the hex color is perceived as dark (use white text on top) */
33
- function isColorDark(hex: string): boolean {
34
- const m = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
35
- if (!m) return false;
36
- const r = parseInt(m[1], 16) / 255;
37
- const g = parseInt(m[2], 16) / 255;
38
- const b = parseInt(m[3], 16) / 255;
39
- return 0.299 * r + 0.587 * g + 0.114 * b < 0.5;
40
- }
41
-
42
- export const XeboNPSView: React.FC<Props> = ({ question, isLastQuestion, onAnswer }) => {
43
- const theme = getTheme();
44
- const [selectedScore, setSelectedScore] = useState<number | null>(null);
45
- const [followUpText, setFollowUpText] = useState('');
46
- const [followUpChoice, setFollowUpChoice] = useState<string | null>(null);
47
- const [error, setError] = useState('');
48
- const shakeAnim = useRef(new Animated.Value(0)).current;
49
- const scaleAnim = useRef<Animated.Value[]>(
50
- Array.from({ length: 11 }, () => new Animated.Value(1))
51
- ).current;
52
-
53
- const shake = () => {
54
- Animated.sequence([
55
- Animated.timing(shakeAnim, { toValue: 8, duration: 60, useNativeDriver: true }),
56
- Animated.timing(shakeAnim, { toValue: -8, duration: 60, useNativeDriver: true }),
57
- Animated.timing(shakeAnim, { toValue: 6, duration: 60, useNativeDriver: true }),
58
- Animated.timing(shakeAnim, { toValue: 0, duration: 60, useNativeDriver: true }),
59
- ]).start();
60
- };
61
-
62
- const handleScorePress = (score: number) => {
63
- setSelectedScore(score);
64
- setError('');
65
- setFollowUpText('');
66
- setFollowUpChoice(null);
67
- Animated.spring(scaleAnim[score], { toValue: 1.15, useNativeDriver: true }).start(() => {
68
- Animated.spring(scaleAnim[score], { toValue: 1, useNativeDriver: true }).start();
69
- });
70
- };
71
-
72
- // Find applicable conditional follow-up
73
- const activeFollowUp: XeboConditionalFollowUp | undefined =
74
- selectedScore !== null
75
- ? (question.conditionalFollowUps ?? []).find(
76
- f => selectedScore >= f.minRating && selectedScore <= f.maxRating
77
- )
78
- : undefined;
79
-
80
- const hasTextFollowUp = !!question.followUpQuestion && !activeFollowUp;
81
-
82
- const handleNext = () => {
83
- if (question.isRequired && selectedScore === null) {
84
- setError('Please select a score.');
85
- shake();
86
- return;
87
- }
88
-
89
- Keyboard.dismiss();
90
- const score = selectedScore ?? 0;
91
- const colId = question.columns?.[score]?.id ?? score.toString();
92
- const rowId = question.options?.[0]?.id ?? score.toString();
93
-
94
- // NPS Pro: conditional follow-up has its own questionId — submit as a separate answer entry
95
- if (activeFollowUp) {
96
- const answers: XeboAnswer[] = [
97
- { questionId: question.id, value: [{ rowId, colId }] },
98
- ];
99
-
100
- if (followUpChoice) {
101
- const selectedOption = activeFollowUp.followUpOptions.find(o => o.id === followUpChoice);
102
- answers.push({
103
- questionId: activeFollowUp.questionId,
104
- value: [{ rowId: followUpChoice, text: selectedOption?.text ?? '' }],
105
- });
106
- } else if (followUpText.trim()) {
107
- answers.push({
108
- questionId: activeFollowUp.questionId,
109
- value: [{ rowId: activeFollowUp.questionId, text: followUpText }],
110
- });
111
- }
112
-
113
- onAnswer(answers);
114
- return;
115
- }
116
-
117
- // Simple text follow-up
118
- onAnswer({
119
- questionId: question.id,
120
- value: [{ rowId, colId, text: hasTextFollowUp ? followUpText : undefined }],
121
- });
122
- };
123
-
124
- return (
125
- // Outer view fills modal content area; button pinned at bottom outside ScrollView
126
- <View style={styles.outer}>
127
- <ScrollView
128
- style={styles.scroll}
129
- contentContainerStyle={styles.scrollContent}
130
- showsVerticalScrollIndicator={false}
131
- keyboardShouldPersistTaps="handled"
132
- >
133
- <Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
134
- {question.title}
135
- </Text>
136
- {!!question.subtitle && (
137
- <Text style={[styles.subtitle, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
138
- {question.subtitle}
139
- </Text>
140
- )}
141
-
142
- {/* NPS Scale — single row, always-visible category colors */}
143
- <View style={styles.scaleRow}>
144
- {Array.from({ length: 11 }, (_, i) => {
145
- const selected = selectedScore === i;
146
- const color = npsColor(i, question.npsLabels);
147
- return (
148
- <Animated.View key={i} style={[styles.scoreCell, { transform: [{ scale: scaleAnim[i] }] }]}>
149
- <TouchableOpacity
150
- style={[
151
- styles.scoreButton,
152
- {
153
- backgroundColor: color,
154
- borderColor: selected ? '#000000' : color,
155
- borderWidth: selected ? 2.5 : 1.5,
156
- },
157
- ]}
158
- onPress={() => handleScorePress(i)}
159
- activeOpacity={0.8}
160
- >
161
- <Text style={[
162
- styles.scoreText,
163
- { color: isColorDark(color) ? '#FFFFFF' : selected ? '#111111' : '#444444' },
164
- ]}>
165
- {i}
166
- </Text>
167
- </TouchableOpacity>
168
- </Animated.View>
169
- );
170
- })}
171
- </View>
172
-
173
- {/* Lower / Upper labels */}
174
- {(question.npsLabels?.lower || question.npsLabels?.upper) && (
175
- <View style={styles.labelsRow}>
176
- <Text style={[styles.label, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
177
- {question.npsLabels?.lower ?? ''}
178
- </Text>
179
- <Text style={[styles.label, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
180
- {question.npsLabels?.upper ?? ''}
181
- </Text>
182
- </View>
183
- )}
184
-
185
- {/* Conditional follow-up (NPS Pro) */}
186
- {selectedScore !== null && activeFollowUp && (
187
- <View style={[styles.followUpCard, { borderColor: '#E5E7EB', borderRadius: theme.cornerRadius }]}>
188
- <Text style={[styles.followUpTitle, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
189
- {activeFollowUp.followUpQuestion}
190
- </Text>
191
- {activeFollowUp.followUpType === XeboQuestionType.singleChoice && activeFollowUp.followUpOptions.length > 0 ? (
192
- activeFollowUp.followUpOptions.map(opt => (
193
- <TouchableOpacity
194
- key={opt.id}
195
- style={[
196
- styles.followUpOption,
197
- followUpChoice === opt.id && { borderColor: theme.primaryColor },
198
- ]}
199
- onPress={() => setFollowUpChoice(opt.id)}
200
- activeOpacity={0.7}
201
- >
202
- <Text style={[styles.followUpOptionText, { color: theme.textColor }]}>{opt.text}</Text>
203
- </TouchableOpacity>
204
- ))
205
- ) : (
206
- <TextInput
207
- style={[styles.followUpInput, { borderColor: '#E5E7EB', color: theme.textColor, borderRadius: theme.cornerRadius }]}
208
- placeholder="Your comment..."
209
- placeholderTextColor="#9CA3AF"
210
- value={followUpText}
211
- onChangeText={setFollowUpText}
212
- multiline
213
- numberOfLines={3}
214
- textAlignVertical="top"
215
- />
216
- )}
217
- </View>
218
- )}
219
-
220
- {/* Simple text follow-up */}
221
- {selectedScore !== null && hasTextFollowUp && (
222
- <View style={[styles.followUpCard, { borderColor: '#E5E7EB', borderRadius: theme.cornerRadius }]}>
223
- <Text style={[styles.followUpTitle, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
224
- {question.followUpQuestion}
225
- </Text>
226
- <TextInput
227
- style={[styles.followUpInput, { borderColor: '#E5E7EB', color: theme.textColor, borderRadius: theme.cornerRadius }]}
228
- placeholder="Your comment..."
229
- placeholderTextColor="#9CA3AF"
230
- value={followUpText}
231
- onChangeText={setFollowUpText}
232
- multiline
233
- numberOfLines={3}
234
- textAlignVertical="top"
235
- />
236
- </View>
237
- )}
238
- </ScrollView>
239
-
240
- {/* Error + button always visible at bottom, outside scroll */}
241
- {!!error && <Text style={styles.errorText}>{error}</Text>}
242
- <Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
243
- <TouchableOpacity
244
- style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius, opacity: selectedScore === null ? 0.4 : 1 }]}
245
- onPress={handleNext}
246
- disabled={selectedScore === null}
247
- activeOpacity={0.8}
248
- >
249
- <Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
250
- {isLastQuestion ? 'Submit' : 'Next'}
251
- </Text>
252
- </TouchableOpacity>
253
- </Animated.View>
254
- </View>
255
- );
256
- };
257
-
258
- const styles = StyleSheet.create({
259
- outer: {
260
- flex: 1,
261
- paddingHorizontal: 20,
262
- paddingBottom: 16,
263
- },
264
- scroll: { flex: 1, minHeight: 0 },
265
- scrollContent: {
266
- paddingTop: 16,
267
- paddingBottom: 8,
268
- },
269
- title: { fontSize: 18, fontWeight: '700', marginBottom: 6 },
270
- subtitle: { fontSize: 14, opacity: 0.6, marginBottom: 16 },
271
- scaleRow: {
272
- flexDirection: 'row',
273
- gap: 3,
274
- marginBottom: 8,
275
- },
276
- scoreCell: {
277
- flex: 1,
278
- },
279
- scoreButton: {
280
- height: 44,
281
- borderRadius: 6,
282
- alignItems: 'center',
283
- justifyContent: 'center',
284
- },
285
- scoreText: { fontSize: 13, fontWeight: '700' },
286
- labelsRow: {
287
- flexDirection: 'row',
288
- justifyContent: 'space-between',
289
- marginBottom: 16,
290
- },
291
- label: { fontSize: 12, opacity: 0.6 },
292
- followUpCard: {
293
- borderWidth: 1.5,
294
- padding: 14,
295
- marginBottom: 16,
296
- },
297
- followUpTitle: { fontSize: 15, fontWeight: '600', marginBottom: 12 },
298
- followUpOption: {
299
- borderWidth: 1.5,
300
- borderColor: '#E5E7EB',
301
- borderRadius: 8,
302
- padding: 10,
303
- marginBottom: 8,
304
- },
305
- followUpOptionText: { fontSize: 14 },
306
- followUpInput: {
307
- borderWidth: 1.5,
308
- padding: 10,
309
- fontSize: 14,
310
- minHeight: 80,
311
- },
312
- errorText: { color: '#EF4444', fontSize: 13, marginBottom: 8 },
313
- button: { paddingVertical: 14, alignItems: 'center', marginTop: 8 },
314
- buttonText: { color: '#FFFFFF', fontSize: 16, fontWeight: '600' },
315
- });