@@ -33,6 +33,15 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
33
33
...defaultConfiguration
34
34
}
35
35
36
+ private static _savedState : FeedbackFormState = {
37
+ isVisible : false ,
38
+ name : '' ,
39
+ email : '' ,
40
+ description : '' ,
41
+ filename : undefined ,
42
+ attachment : undefined ,
43
+ } ;
44
+
36
45
public constructor ( props : FeedbackFormProps ) {
37
46
super ( props ) ;
38
47
@@ -45,9 +54,11 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
45
54
46
55
this . state = {
47
56
isVisible : true ,
48
- name : currentUser . useSentryUser . name ,
49
- email : currentUser . useSentryUser . email ,
50
- description : '' ,
57
+ name : FeedbackForm . _savedState . name || currentUser . useSentryUser . name ,
58
+ email : FeedbackForm . _savedState . email || currentUser . useSentryUser . email ,
59
+ description : FeedbackForm . _savedState . description || '' ,
60
+ filename : FeedbackForm . _savedState . filename || undefined ,
61
+ attachment : FeedbackForm . _savedState . attachment || undefined ,
51
62
} ;
52
63
}
53
64
@@ -93,6 +104,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
93
104
onSubmitSuccess ( { name : trimmedName , email : trimmedEmail , message : trimmedDescription , attachments : undefined } ) ;
94
105
Alert . alert ( text . successMessageText ) ;
95
106
onFormSubmitted ( ) ;
107
+ this . _clearFormState ( ) ;
96
108
} catch ( error ) {
97
109
const errorString = `Feedback form submission failed: ${ error } ` ;
98
110
onSubmitError ( new Error ( errorString ) ) ;
@@ -129,7 +141,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
129
141
const imageUri = result . assets [ 0 ] . uri ;
130
142
NATIVE . getDataFromUri ( imageUri ) . then ( ( data ) => {
131
143
if ( data != null ) {
132
- this . setState ( { filename, attachment : data } ) ;
144
+ this . setState ( { filename, attachment : data } , this . _saveFormState ) ;
133
145
} else {
134
146
logger . error ( 'Failed to read image data from uri:' , imageUri ) ;
135
147
}
@@ -142,11 +154,11 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
142
154
// Defaulting to the onAddScreenshot callback
143
155
const { onAddScreenshot } = { ...defaultConfiguration , ...this . props } ;
144
156
onAddScreenshot ( ( filename : string , attachement : Uint8Array ) => {
145
- this . setState ( { filename, attachment : attachement } ) ;
157
+ this . setState ( { filename, attachment : attachement } , this . _saveFormState ) ;
146
158
} ) ;
147
159
}
148
160
} else {
149
- this . setState ( { filename : undefined , attachment : undefined } ) ;
161
+ this . setState ( { filename : undefined , attachment : undefined } , this . _saveFormState ) ;
150
162
}
151
163
}
152
164
@@ -199,7 +211,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
199
211
style = { styles . input }
200
212
placeholder = { text . namePlaceholder }
201
213
value = { name }
202
- onChangeText = { ( value ) => this . setState ( { name : value } ) }
214
+ onChangeText = { ( value ) => this . setState ( { name : value } , this . _saveFormState ) }
203
215
/>
204
216
</ >
205
217
) }
@@ -215,7 +227,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
215
227
placeholder = { text . emailPlaceholder }
216
228
keyboardType = { 'email-address' as KeyboardTypeOptions }
217
229
value = { email }
218
- onChangeText = { ( value ) => this . setState ( { email : value } ) }
230
+ onChangeText = { ( value ) => this . setState ( { email : value } , this . _saveFormState ) }
219
231
/>
220
232
</ >
221
233
) }
@@ -228,7 +240,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
228
240
style = { [ styles . input , styles . textArea ] }
229
241
placeholder = { text . messagePlaceholder }
230
242
value = { description }
231
- onChangeText = { ( value ) => this . setState ( { description : value } ) }
243
+ onChangeText = { ( value ) => this . setState ( { description : value } , this . _saveFormState ) }
232
244
multiline
233
245
/>
234
246
{ ( config . enableScreenshot || imagePickerConfiguration . imagePicker ) && (
@@ -254,4 +266,19 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
254
266
</ SafeAreaView >
255
267
) ;
256
268
}
269
+
270
+ private _saveFormState = ( ) : void => {
271
+ FeedbackForm . _savedState = { ...this . state } ;
272
+ } ;
273
+
274
+ private _clearFormState = ( ) : void => {
275
+ FeedbackForm . _savedState = {
276
+ isVisible : false ,
277
+ name : '' ,
278
+ email : '' ,
279
+ description : '' ,
280
+ filename : undefined ,
281
+ attachment : undefined ,
282
+ } ;
283
+ } ;
257
284
}
0 commit comments