1
- import { Trans } from "gatsby-plugin-react-i18next" ;
1
+ import { Trans , useTranslation } from "gatsby-plugin-react-i18next" ;
2
2
import {
3
3
Box ,
4
4
Stack ,
7
7
RadioGroup ,
8
8
Radio ,
9
9
FormControlLabel ,
10
+ TextField ,
10
11
} from "@mui/material" ;
11
12
import { ThumbUpOutlined , ThumbDownOutlined } from "@mui/icons-material" ;
12
13
import { Locale } from "shared/interface" ;
@@ -26,10 +27,18 @@ interface FeedbackSectionProps {
26
27
locale : Locale ;
27
28
}
28
29
30
+ const contactOtherVal = ( val : string , otherVal : string ) => {
31
+ if ( val === "other" ) {
32
+ return `${ val } : ${ otherVal } ` ;
33
+ }
34
+ return val ;
35
+ } ;
36
+
29
37
export function FeedbackSection ( { title, locale } : FeedbackSectionProps ) {
30
38
const [ thumbVisible , setThumbVisible ] = useState ( true ) ;
31
39
const [ helpful , setHelpful ] = useState < boolean > ( ) ;
32
40
const [ surveyVisible , setSurverVisible ] = useState ( false ) ;
41
+ const { t } = useTranslation ( ) ;
33
42
34
43
const onThumbClick = ( helpful : boolean ) => {
35
44
trackCustomEvent ( {
@@ -49,13 +58,17 @@ export function FeedbackSection({ title, locale }: FeedbackSectionProps) {
49
58
} ;
50
59
51
60
const [ positiveVal , setPositiveVal ] = useState < string > ( "" ) ;
61
+ const [ positiveOtherVal , setPositiveOtherVal ] = useState < string > ( "" ) ;
52
62
const onPositiveChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
53
63
setPositiveVal ( ( event . target as HTMLInputElement ) . value ) ;
64
+ setPositiveOtherVal ( "" ) ;
54
65
} ;
55
66
56
67
const [ negativeVal , setNegativeVal ] = useState < string > ( "" ) ;
68
+ const [ negativeOtherVal , setNegativeOtherVal ] = useState < string > ( "" ) ;
57
69
const onNegativeChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
58
70
setNegativeVal ( ( event . target as HTMLInputElement ) . value ) ;
71
+ setNegativeOtherVal ( "" ) ;
59
72
} ;
60
73
61
74
const [ submitted , setSubmitted ] = useState ( false ) ;
@@ -64,7 +77,7 @@ export function FeedbackSection({ title, locale }: FeedbackSectionProps) {
64
77
submitFeedbackDetail ( {
65
78
locale,
66
79
category : FeedbackCategory . Positive ,
67
- reason : positiveVal ,
80
+ reason : contactOtherVal ( positiveVal , positiveOtherVal ) ,
68
81
} ) ;
69
82
setSurverVisible ( false ) ;
70
83
setSubmitted ( true ) ;
@@ -73,7 +86,7 @@ export function FeedbackSection({ title, locale }: FeedbackSectionProps) {
73
86
submitFeedbackDetail ( {
74
87
locale,
75
88
category : FeedbackCategory . Negative ,
76
- reason : negativeVal ,
89
+ reason : contactOtherVal ( negativeVal , negativeOtherVal ) ,
77
90
} ) ;
78
91
setSurverVisible ( false ) ;
79
92
setSubmitted ( true ) ;
@@ -82,7 +95,9 @@ export function FeedbackSection({ title, locale }: FeedbackSectionProps) {
82
95
const onSkip = ( ) => {
83
96
setSurverVisible ( false ) ;
84
97
setPositiveVal ( "" ) ;
98
+ setPositiveOtherVal ( "" ) ;
85
99
setNegativeVal ( "" ) ;
100
+ setNegativeOtherVal ( "" ) ;
86
101
setSubmitted ( true ) ;
87
102
} ;
88
103
@@ -129,51 +144,65 @@ export function FeedbackSection({ title, locale }: FeedbackSectionProps) {
129
144
) }
130
145
{ surveyVisible && helpful && (
131
146
< Box >
132
- < FormControl >
133
- < Typography variant = "body1" color = "website.f1" fontWeight = { 500 } >
134
- < Trans i18nKey = "docFeedbackSurvey.positive.title" />
135
- </ Typography >
136
- < RadioGroup
137
- aria-labelledby = "doc-positive-feedback-survey"
138
- name = "doc-positive-feedback-survey-radio-group"
139
- value = { positiveVal }
140
- onChange = { onPositiveChange }
141
- sx = { { my : "6px" } }
142
- >
143
- < FormControlLabel
144
- value = "easy"
145
- label = { < Trans i18nKey = "docFeedbackSurvey.positive.easy" /> }
146
- control = { < Radio size = "small" sx = { radioSx } /> }
147
- componentsProps = { labelProps }
148
- sx = { controlLabelSx }
149
- />
150
- < FormControlLabel
151
- value = "solvedProblem"
152
- label = {
153
- < Trans i18nKey = "docFeedbackSurvey.positive.solvedProblem" />
154
- }
155
- control = { < Radio size = "small" sx = { radioSx } /> }
156
- componentsProps = { labelProps }
157
- sx = { controlLabelSx }
158
- />
159
- < FormControlLabel
160
- value = "helpToDecide"
161
- label = {
162
- < Trans i18nKey = "docFeedbackSurvey.positive.helpToDecide" />
163
- }
164
- control = { < Radio size = "small" sx = { radioSx } /> }
165
- componentsProps = { labelProps }
166
- sx = { controlLabelSx }
167
- />
168
- < FormControlLabel
169
- value = "other"
170
- label = { < Trans i18nKey = "docFeedbackSurvey.positive.other" /> }
171
- control = { < Radio size = "small" sx = { radioSx } /> }
172
- componentsProps = { labelProps }
173
- sx = { controlLabelSx }
147
+ < Stack >
148
+ < FormControl >
149
+ < Typography variant = "body1" color = "website.f1" fontWeight = { 500 } >
150
+ < Trans i18nKey = "docFeedbackSurvey.positive.title" />
151
+ </ Typography >
152
+ < RadioGroup
153
+ aria-labelledby = "doc-positive-feedback-survey"
154
+ name = "doc-positive-feedback-survey-radio-group"
155
+ value = { positiveVal }
156
+ onChange = { onPositiveChange }
157
+ sx = { { my : "6px" } }
158
+ >
159
+ < FormControlLabel
160
+ value = "easy"
161
+ label = { < Trans i18nKey = "docFeedbackSurvey.positive.easy" /> }
162
+ control = { < Radio size = "small" sx = { radioSx } /> }
163
+ componentsProps = { labelProps }
164
+ sx = { controlLabelSx }
165
+ />
166
+ < FormControlLabel
167
+ value = "solvedProblem"
168
+ label = {
169
+ < Trans i18nKey = "docFeedbackSurvey.positive.solvedProblem" />
170
+ }
171
+ control = { < Radio size = "small" sx = { radioSx } /> }
172
+ componentsProps = { labelProps }
173
+ sx = { controlLabelSx }
174
+ />
175
+ < FormControlLabel
176
+ value = "helpToDecide"
177
+ label = {
178
+ < Trans i18nKey = "docFeedbackSurvey.positive.helpToDecide" />
179
+ }
180
+ control = { < Radio size = "small" sx = { radioSx } /> }
181
+ componentsProps = { labelProps }
182
+ sx = { controlLabelSx }
183
+ />
184
+ < FormControlLabel
185
+ value = "other"
186
+ label = { < Trans i18nKey = "docFeedbackSurvey.positive.other" /> }
187
+ control = { < Radio size = "small" sx = { radioSx } /> }
188
+ componentsProps = { labelProps }
189
+ sx = { controlLabelSx }
190
+ />
191
+ </ RadioGroup >
192
+ </ FormControl >
193
+
194
+ { positiveVal === "other" && (
195
+ < TextField
196
+ multiline
197
+ rows = { 2 }
198
+ sx = { { paddingLeft : "32px" , maxWidth : "500px" } }
199
+ value = { positiveOtherVal }
200
+ onChange = { ( event ) => setPositiveOtherVal ( event . target . value ) }
201
+ placeholder = { t ( "docFeedbackSurvey.positive.otherPlaceholder" ) }
174
202
/>
175
- </ RadioGroup >
176
- </ FormControl >
203
+ ) }
204
+ </ Stack >
205
+
177
206
< Stack direction = "row" spacing = { 2 } mt = "12px" mb = "24px" >
178
207
< ActionButton
179
208
variant = "outlined"
@@ -191,60 +220,74 @@ export function FeedbackSection({ title, locale }: FeedbackSectionProps) {
191
220
) }
192
221
{ surveyVisible && ! helpful && (
193
222
< Box >
194
- < FormControl >
195
- < Typography variant = "body1" color = "website.f1" fontWeight = { 500 } >
196
- < Trans i18nKey = "docFeedbackSurvey.negative.title" />
197
- </ Typography >
198
- < RadioGroup
199
- aria-labelledby = "doc-negative-feedback-survey"
200
- name = "doc-negative-feedback-survey-radio-group"
201
- value = { negativeVal }
202
- onChange = { onNegativeChange }
203
- sx = { { my : "6px" } }
204
- >
205
- < FormControlLabel
206
- value = "hard"
207
- label = { < Trans i18nKey = "docFeedbackSurvey.negative.hard" /> }
208
- control = { < Radio size = "small" sx = { radioSx } /> }
209
- componentsProps = { labelProps }
210
- sx = { controlLabelSx }
211
- />
212
- < FormControlLabel
213
- value = "nothingFound"
214
- label = {
215
- < Trans i18nKey = "docFeedbackSurvey.negative.nothingFound" />
216
- }
217
- control = { < Radio size = "small" sx = { radioSx } /> }
218
- componentsProps = { labelProps }
219
- sx = { controlLabelSx }
220
- />
221
- < FormControlLabel
222
- value = "inaccurate"
223
- label = {
224
- < Trans i18nKey = "docFeedbackSurvey.negative.inaccurate" />
225
- }
226
- control = { < Radio size = "small" sx = { radioSx } /> }
227
- componentsProps = { labelProps }
228
- sx = { controlLabelSx }
229
- />
230
- < FormControlLabel
231
- value = "sampleError"
232
- label = {
233
- < Trans i18nKey = "docFeedbackSurvey.negative.sampleError" />
234
- }
235
- control = { < Radio size = "small" sx = { radioSx } /> }
236
- componentsProps = { labelProps }
237
- sx = { controlLabelSx }
238
- />
239
- < FormControlLabel
240
- value = "other"
241
- label = { < Trans i18nKey = "docFeedbackSurvey.negative.other" /> }
242
- control = { < Radio size = "small" sx = { radioSx } /> }
243
- componentsProps = { labelProps }
244
- sx = { controlLabelSx }
223
+ < Stack >
224
+ < FormControl >
225
+ < Typography variant = "body1" color = "website.f1" fontWeight = { 500 } >
226
+ < Trans i18nKey = "docFeedbackSurvey.negative.title" />
227
+ </ Typography >
228
+ < RadioGroup
229
+ aria-labelledby = "doc-negative-feedback-survey"
230
+ name = "doc-negative-feedback-survey-radio-group"
231
+ value = { negativeVal }
232
+ onChange = { onNegativeChange }
233
+ sx = { { my : "6px" } }
234
+ >
235
+ < FormControlLabel
236
+ value = "hard"
237
+ label = { < Trans i18nKey = "docFeedbackSurvey.negative.hard" /> }
238
+ control = { < Radio size = "small" sx = { radioSx } /> }
239
+ componentsProps = { labelProps }
240
+ sx = { controlLabelSx }
241
+ />
242
+ < FormControlLabel
243
+ value = "nothingFound"
244
+ label = {
245
+ < Trans i18nKey = "docFeedbackSurvey.negative.nothingFound" />
246
+ }
247
+ control = { < Radio size = "small" sx = { radioSx } /> }
248
+ componentsProps = { labelProps }
249
+ sx = { controlLabelSx }
250
+ />
251
+ < FormControlLabel
252
+ value = "inaccurate"
253
+ label = {
254
+ < Trans i18nKey = "docFeedbackSurvey.negative.inaccurate" />
255
+ }
256
+ control = { < Radio size = "small" sx = { radioSx } /> }
257
+ componentsProps = { labelProps }
258
+ sx = { controlLabelSx }
259
+ />
260
+ < FormControlLabel
261
+ value = "sampleError"
262
+ label = {
263
+ < Trans i18nKey = "docFeedbackSurvey.negative.sampleError" />
264
+ }
265
+ control = { < Radio size = "small" sx = { radioSx } /> }
266
+ componentsProps = { labelProps }
267
+ sx = { controlLabelSx }
268
+ />
269
+ < FormControlLabel
270
+ value = "other"
271
+ label = { < Trans i18nKey = "docFeedbackSurvey.negative.other" /> }
272
+ control = { < Radio size = "small" sx = { radioSx } /> }
273
+ componentsProps = { labelProps }
274
+ sx = { controlLabelSx }
275
+ />
276
+ </ RadioGroup >
277
+ </ FormControl >
278
+
279
+ { negativeVal === "other" && (
280
+ < TextField
281
+ multiline
282
+ rows = { 2 }
283
+ sx = { { paddingLeft : "32px" , maxWidth : "500px" } }
284
+ value = { negativeOtherVal }
285
+ onChange = { ( event ) => setNegativeOtherVal ( event . target . value ) }
286
+ placeholder = { t ( "docFeedbackSurvey.negative.otherPlaceholder" ) }
245
287
/>
246
- </ RadioGroup >
247
- </ FormControl >
288
+ ) }
289
+ </ Stack >
290
+
248
291
< Stack direction = "row" spacing = { 2 } mt = "12px" mb = "24px" >
249
292
< ActionButton
250
293
variant = "outlined"
0 commit comments