freemium-survey-components 0.16.4 → 0.16.5

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/README.md CHANGED
@@ -19,59 +19,78 @@ Make sure you have the below installed in your app.
19
19
 
20
20
  - Survey : SurveyProps
21
21
  - WebInAppSurvey : WebInAppSurveyProps
22
- - NPS : NPSProps
22
+ - Range : RangeProps
23
23
 
24
24
  ### Types
25
25
  ```
26
26
  type SurveyProps {
27
27
  survey: SurveyType
28
+ answers: SurveyResponseType | null
28
29
  surveyStyle?: 'standard' | 'card'
29
30
  placeholders?: {
30
31
  [key: string]: string
31
32
  }
32
- npsValue?: number
33
+ initialPivotAnswer?: number
33
34
  onSubmit: (
34
- data: { [key: string]: string | number | Array<string | number> | null | {[key : string] : string } },
35
- callback: Function
35
+ data: {
36
+ [key: string]:
37
+ | string
38
+ | number
39
+ | Array<string | number>
40
+ | { [key: string]: string }
41
+ | null
42
+ },
43
+ callback: Function,
44
+ status: AnswerStatus,
36
45
  ) => void
37
46
  preview?: boolean
38
47
  mobilePreview?: boolean
48
+ closePreview?: () => void
49
+ onAnsweringPrompt: (id: number) => void
39
50
  }
40
51
  ```
41
52
  ```
42
53
  type WidgetProps = {
43
54
  survey: SurveyType
44
- surveyType: 'default' | 'compact' | 'cozy'
55
+ answers: SurveyResponseType | null
56
+ preview?: boolean
45
57
  placeholders: {
46
58
  [key: string]: string
47
59
  }
48
60
  onSubmit: (
49
- data: { [key: string]: string | number | Array<string | number> | null | {[key : string] : string } },
61
+ data: { [key: string]: string | number | Array<string | number> | null },
50
62
  callback: Function,
63
+ status: AnswerStatus,
51
64
  ) => void
52
- preview?: boolean
53
65
  onDismiss: () => void
54
66
  onClose?: () => void
67
+ surveyType: 'default' | 'compact' | 'cozy'
55
68
  unsubscribeUrl?: string
56
69
  isSurveyCompleted: boolean
57
- children: React.ReactNode | null
70
+ children: React.ReactNode
71
+ onAnsweringPrompt: (id: number) => void
58
72
  }
59
73
  ```
60
74
  ```
61
- type NPSProps = {
75
+ type RangeProps = {
62
76
  type_info: {
63
- linear_scale: {
64
- button_shape: 'rounded' | 'square' | 'curved'
65
- button_style: 'standard' | 'highlighted'
66
- }
67
- validation: {
68
- min: number
77
+ type_variant: 'NUMBER' | 'TEXT' | 'EMOJI' | 'STAR'
78
+ scale_properties?: {
79
+ order: 'ascending' | 'descending'
80
+ button_style: {
81
+ shape: ButtonShapeType
82
+ type: 'standard' | 'highlighted'
83
+ }
84
+ range: ScalePropertiesRangeType[]
85
+ labels: {
86
+ values: string[]
87
+ preference: 'edges' | 'all' | null
88
+ }
69
89
  }
70
- rating_presets: { start?: string; end?: string }
71
90
  footer_text: string
72
91
  }
73
92
  onChangeHandler: (value: number) => void
74
- npsValue?: number
93
+ value?: number
75
94
  }
76
95
  ```
77
96
 
@@ -84,16 +103,20 @@ const WebSurveyPreview = () => {
84
103
  return <Survey
85
104
  survey={surveyObjectFromSurveyServ}
86
105
  surveyStyle="card"
87
- onSubmit = {async (data : surveyFormData,callback) => {
106
+ onSubmit = {async (data : surveyFormData,callback,status : 'PARTIAL' | 'COMPLETE') => {
107
+ // this will get called for every answer selection with status = 'PARTIAL'
88
108
  await saveToDb(surveyFormData)
109
+ if(status === 'COMPETE')
89
110
  callback?.() // callback should be executed in the caller once the save is done.
90
111
  }}
91
112
  placeholders = {{
92
113
  '{{account.company_name}}': 'Freshworks',
93
114
  '{{account.account_name}}': 'Freshworks Account',
94
- }} // placeholders to resolve against any such placeholder in surveyObj
115
+ }} // placeholders to resolve against any such placeholder in question's text
95
116
  preview = {true} // preview true will not save the response
96
- npsvalue={null} // pass a number if nps qn needed to be prefilled by default
117
+ initialPivotAnswer={null} // pass a number if pivot qn needed to be prefilled by default
118
+ onAnsweringPrompt={(id) =>
119
+ console.log(`Prompt ${id ? 'accepted' : 'rejected'}`)}
97
120
  />
98
121
  }
99
122
  ```
@@ -105,8 +128,9 @@ const Widget = () => {
105
128
  survey={surveyObjectFromSurveyServ}
106
129
  surveyType="compact"
107
130
  placeholders={null}
108
- onSubmit={(data, callback) => {
109
- console.log(data, callback?.())
131
+ onSubmit={(data, callback,status) => {
132
+ if(status === 'COMPLETE')
133
+ callback?.()
110
134
  setIsSurveyCompleted(true)
111
135
  }}
112
136
  onDismiss={() => {
@@ -115,29 +139,66 @@ const Widget = () => {
115
139
  }}
116
140
  unsubscribeUrl={'#'}
117
141
  isSurveyCompleted={isSurveyCompleted}
118
- children={null} // if we want render with respect to the widget's fixed position
142
+ children={null} // if we want render with respect to the widget's fixed onAnsweringPrompt={(id) =>
143
+ console.log(`Prompt ${id ? 'accepted' : 'rejected'}`)
144
+ }
119
145
  />
120
146
  }
121
147
  ```
122
148
  ```
123
- import {NPS} from 'freemium-survey-components'
124
- const NPSPreview = () => {
125
- return <NPS
149
+ import {Range} from 'freemium-survey-components'
150
+ const RangePreview = () => {
151
+ return <Range
126
152
  type_info={{
127
- linear_scale : {
128
- button_shape : 'rounded',
129
- button_style : 'highlighted'
153
+ type_variant: 'TEXT',
154
+ scale_properties: {
155
+ order: 'ascending',
156
+ range: [
157
+ {
158
+ id: '1',
159
+ label: 'detractor',
160
+ min: 1,
161
+ max: 2,
130
162
  },
131
- validation : {
132
- min : 0
163
+ {
164
+ id: '2',
165
+ label: 'passive',
166
+ min: 3,
167
+ max: 4,
133
168
  },
134
- rating_presets : {
135
- start : 'Very unlikely',
136
- end : 'Very likely'
169
+ {
170
+ id: '3',
171
+ label: 'promoter',
172
+ min: 5,
173
+ max: 10,
137
174
  },
138
- footer_text : 'We look forward to act on your feedback',
139
- onChangeHandler : (value) => console.log(value)
140
- }}
175
+ ],
176
+ button_style: {
177
+ shape: 'rounded',
178
+ type: 'highlighted',
179
+ },
180
+ labels: {
181
+ preference: 'edges',
182
+ values: [
183
+ 'Very dissatisfied',
184
+ 'Very dissatisfied',
185
+ 'Dissatisfied',
186
+ 'Neutral',
187
+ 'Satisfied',
188
+ 'Dissatisfied',
189
+ 'Neutral',
190
+ 'Satisfied',
191
+ 'Dissatisfied',
192
+ 'Satisfied',
193
+ ],
194
+ },
195
+ },
196
+ footer_text: 'We look forward to your feedback.',
197
+ }}
198
+ value={value}
199
+ onChangeHandler={(value: any) => {
200
+ setValue(value)
201
+ }}
141
202
  />
142
203
  }
143
204
  ```