@@ -17,24 +17,24 @@ import {
17
17
View
18
18
} from 'react-native' ;
19
19
20
- import { NATIVE } from './. ./wrapper' ;
20
+ import { NATIVE } from '../wrapper' ;
21
21
import { sentryLogo } from './branding' ;
22
22
import { defaultConfiguration } from './defaults' ;
23
- import defaultStyles from './FeedbackForm .styles' ;
24
- import type { FeedbackFormProps , FeedbackFormState , FeedbackFormStyles , FeedbackGeneralConfiguration , FeedbackTextConfiguration , ImagePickerConfiguration } from './FeedbackForm .types' ;
23
+ import defaultStyles from './FeedbackWidget .styles' ;
24
+ import type { FeedbackGeneralConfiguration , FeedbackTextConfiguration , FeedbackWidgetProps , FeedbackWidgetState , FeedbackWidgetStyles , ImagePickerConfiguration } from './FeedbackWidget .types' ;
25
25
import { isValidEmail } from './utils' ;
26
26
27
27
/**
28
28
* @beta
29
29
* Implements a feedback form screen that sends feedback to Sentry using Sentry.captureFeedback.
30
30
*/
31
- export class FeedbackForm extends React . Component < FeedbackFormProps , FeedbackFormState > {
32
- public static defaultProps : Partial < FeedbackFormProps > = {
31
+ export class FeedbackWidget extends React . Component < FeedbackWidgetProps , FeedbackWidgetState > {
32
+ public static defaultProps : Partial < FeedbackWidgetProps > = {
33
33
...defaultConfiguration
34
34
}
35
35
36
- private static _savedState : FeedbackFormState = {
37
- isVisible : false ,
36
+ private static _didSubmitForm : boolean = false ;
37
+ private static _savedState : Omit < FeedbackWidgetState , 'isVisible' > = {
38
38
name : '' ,
39
39
email : '' ,
40
40
description : '' ,
@@ -43,7 +43,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
43
43
attachmentUri : undefined ,
44
44
} ;
45
45
46
- public constructor ( props : FeedbackFormProps ) {
46
+ public constructor ( props : FeedbackWidgetProps ) {
47
47
super ( props ) ;
48
48
49
49
const currentUser = {
@@ -55,12 +55,12 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
55
55
56
56
this . state = {
57
57
isVisible : true ,
58
- name : FeedbackForm . _savedState . name || currentUser . useSentryUser . name ,
59
- email : FeedbackForm . _savedState . email || currentUser . useSentryUser . email ,
60
- description : FeedbackForm . _savedState . description || '' ,
61
- filename : FeedbackForm . _savedState . filename || undefined ,
62
- attachment : FeedbackForm . _savedState . attachment || undefined ,
63
- attachmentUri : FeedbackForm . _savedState . attachmentUri || undefined ,
58
+ name : FeedbackWidget . _savedState . name || currentUser . useSentryUser . name ,
59
+ email : FeedbackWidget . _savedState . email || currentUser . useSentryUser . email ,
60
+ description : FeedbackWidget . _savedState . description || '' ,
61
+ filename : FeedbackWidget . _savedState . filename || undefined ,
62
+ attachment : FeedbackWidget . _savedState . attachment || undefined ,
63
+ attachmentUri : FeedbackWidget . _savedState . attachmentUri || undefined ,
64
64
} ;
65
65
}
66
66
@@ -103,10 +103,10 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
103
103
try {
104
104
this . setState ( { isVisible : false } ) ;
105
105
captureFeedback ( userFeedback , attachments ? { attachments } : undefined ) ;
106
- onSubmitSuccess ( { name : trimmedName , email : trimmedEmail , message : trimmedDescription , attachments : undefined } ) ;
106
+ onSubmitSuccess ( { name : trimmedName , email : trimmedEmail , message : trimmedDescription , attachments : attachments } ) ;
107
107
Alert . alert ( text . successMessageText ) ;
108
108
onFormSubmitted ( ) ;
109
- this . _clearFormState ( ) ;
109
+ FeedbackWidget . _didSubmitForm = true ;
110
110
} catch ( error ) {
111
111
const errorString = `Feedback form submission failed: ${ error } ` ;
112
112
onSubmitError ( new Error ( errorString ) ) ;
@@ -143,25 +143,37 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
143
143
const imageUri = result . assets [ 0 ] . uri ;
144
144
NATIVE . getDataFromUri ( imageUri ) . then ( ( data ) => {
145
145
if ( data != null ) {
146
- this . setState ( { filename, attachment : data , attachmentUri : imageUri } , this . _saveFormState ) ;
146
+ this . setState ( { filename, attachment : data , attachmentUri : imageUri } ) ;
147
147
} else {
148
148
logger . error ( 'Failed to read image data from uri:' , imageUri ) ;
149
149
}
150
150
} )
151
- . catch ( ( error ) => {
152
- logger . error ( 'Failed to read image data from uri:' , imageUri , 'error: ' , error ) ;
153
- } ) ;
151
+ . catch ( ( error ) => {
152
+ logger . error ( 'Failed to read image data from uri:' , imageUri , 'error: ' , error ) ;
153
+ } ) ;
154
154
}
155
155
} else {
156
156
// Defaulting to the onAddScreenshot callback
157
157
const { onAddScreenshot } = { ...defaultConfiguration , ...this . props } ;
158
158
onAddScreenshot ( ( filename : string , attachement : Uint8Array ) => {
159
159
// TODO: Add support for image uri when using onAddScreenshot
160
- this . setState ( { filename, attachment : attachement , attachmentUri : undefined } , this . _saveFormState ) ;
160
+ this . setState ( { filename, attachment : attachement , attachmentUri : undefined } ) ;
161
161
} ) ;
162
162
}
163
163
} else {
164
- this . setState ( { filename : undefined , attachment : undefined , attachmentUri : undefined } , this . _saveFormState ) ;
164
+ this . setState ( { filename : undefined , attachment : undefined , attachmentUri : undefined } ) ;
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Save the state before unmounting the component.
170
+ */
171
+ public componentWillUnmount ( ) : void {
172
+ if ( FeedbackWidget . _didSubmitForm ) {
173
+ this . _clearFormState ( ) ;
174
+ FeedbackWidget . _didSubmitForm = false ;
175
+ } else {
176
+ this . _saveFormState ( ) ;
165
177
}
166
178
}
167
179
@@ -174,7 +186,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
174
186
const config : FeedbackGeneralConfiguration = this . props ;
175
187
const imagePickerConfiguration : ImagePickerConfiguration = this . props ;
176
188
const text : FeedbackTextConfiguration = this . props ;
177
- const styles : FeedbackFormStyles = { ...defaultStyles , ...this . props . styles } ;
189
+ const styles : FeedbackWidgetStyles = { ...defaultStyles , ...this . props . styles } ;
178
190
const onCancel = ( ) : void => {
179
191
onFormClose ( ) ;
180
192
this . setState ( { isVisible : false } ) ;
@@ -214,7 +226,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
214
226
style = { styles . input }
215
227
placeholder = { text . namePlaceholder }
216
228
value = { name }
217
- onChangeText = { ( value ) => this . setState ( { name : value } , this . _saveFormState ) }
229
+ onChangeText = { ( value ) => this . setState ( { name : value } ) }
218
230
/>
219
231
</ >
220
232
) }
@@ -230,7 +242,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
230
242
placeholder = { text . emailPlaceholder }
231
243
keyboardType = { 'email-address' as KeyboardTypeOptions }
232
244
value = { email }
233
- onChangeText = { ( value ) => this . setState ( { email : value } , this . _saveFormState ) }
245
+ onChangeText = { ( value ) => this . setState ( { email : value } ) }
234
246
/>
235
247
</ >
236
248
) }
@@ -243,7 +255,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
243
255
style = { [ styles . input , styles . textArea ] }
244
256
placeholder = { text . messagePlaceholder }
245
257
value = { description }
246
- onChangeText = { ( value ) => this . setState ( { description : value } , this . _saveFormState ) }
258
+ onChangeText = { ( value ) => this . setState ( { description : value } ) }
247
259
multiline
248
260
/>
249
261
{ ( config . enableScreenshot || imagePickerConfiguration . imagePicker ) && (
@@ -279,12 +291,11 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
279
291
}
280
292
281
293
private _saveFormState = ( ) : void => {
282
- FeedbackForm . _savedState = { ...this . state } ;
294
+ FeedbackWidget . _savedState = { ...this . state } ;
283
295
} ;
284
296
285
297
private _clearFormState = ( ) : void => {
286
- FeedbackForm . _savedState = {
287
- isVisible : false ,
298
+ FeedbackWidget . _savedState = {
288
299
name : '' ,
289
300
email : '' ,
290
301
description : '' ,
0 commit comments