Skip to content

Commit 7934756

Browse files
committed
Extract default text to constants
1 parent 1bc1e4c commit 7934756

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

packages/core/src/js/feedback/FeedbackForm.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ import { Alert, Text, TextInput, TouchableOpacity, View } from 'react-native';
77
import defaultStyles from './FeedbackForm.styles';
88
import type { FeedbackFormProps, FeedbackFormState } from './FeedbackForm.types';
99

10+
const defaultFormTitle = 'Feedback Form';
11+
const defaultNamePlaceholder ='Name';
12+
const defaultEmailPlaceholder = 'Email';
13+
const defaultDescriptionPlaceholder = 'Description (required)';
14+
const defaultSubmitButton = 'Send Feedback';
15+
const defaultCancelButton = 'Cancel';
16+
const defaultErrorTitle = 'Error';
17+
const defaultFormError = 'Please fill out all required fields.';
18+
const defaultEmailError = 'Please enter a valid email address.';
19+
1020
/**
1121
* @beta
1222
* Implements a feedback form screen that sends feedback to Sentry using Sentry.captureFeedback.
@@ -30,14 +40,14 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
3040
const trimmedDescription = description?.trim();
3141

3242
if (!trimmedName || !trimmedEmail || !trimmedDescription) {
33-
const errorMessage = text?.formError || 'Please fill out all required fields.';
34-
Alert.alert(text?.errorTitle || 'Error', errorMessage);
43+
const errorMessage = text?.formError || defaultFormError;
44+
Alert.alert(text?.errorTitle || defaultErrorTitle, errorMessage);
3545
return;
3646
}
3747

3848
if (!this._isValidEmail(trimmedEmail)) {
39-
const errorMessage = text?.emailError || 'Please enter a valid email address.';
40-
Alert.alert(text?.errorTitle || 'Error', errorMessage);
49+
const errorMessage = text?.emailError || defaultEmailError;
50+
Alert.alert(text?.errorTitle || defaultErrorTitle, errorMessage);
4151
return;
4252
}
4353

@@ -60,37 +70,37 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
6070

6171
return (
6272
<View style={styles?.container || defaultStyles.container}>
63-
<Text style={styles?.title || defaultStyles.title}>{text?.formTitle || 'Feedback Form'}</Text>
73+
<Text style={styles?.title || defaultStyles.title}>{text?.formTitle || defaultFormTitle}</Text>
6474

6575
<TextInput
6676
style={styles?.input || defaultStyles.input}
67-
placeholder={text?.namePlaceholder || 'Name'}
77+
placeholder={text?.namePlaceholder || defaultNamePlaceholder}
6878
value={name}
6979
onChangeText={(value) => this.setState({ name: value })}
7080
/>
7181

7282
<TextInput
7383
style={styles?.input || defaultStyles.input}
74-
placeholder={text?.emailPlaceholder || 'Email'}
84+
placeholder={text?.emailPlaceholder || defaultEmailPlaceholder}
7585
keyboardType={'email-address' as KeyboardTypeOptions}
7686
value={email}
7787
onChangeText={(value) => this.setState({ email: value })}
7888
/>
7989

8090
<TextInput
8191
style={[styles?.input || defaultStyles.input, styles?.textArea || defaultStyles.textArea]}
82-
placeholder={text?.descriptionPlaceholder || 'Description (required)'}
92+
placeholder={text?.descriptionPlaceholder || defaultDescriptionPlaceholder}
8393
value={description}
8494
onChangeText={(value) => this.setState({ description: value })}
8595
multiline
8696
/>
8797

8898
<TouchableOpacity style={styles?.submitButton || defaultStyles.submitButton} onPress={this.handleFeedbackSubmit}>
89-
<Text style={styles?.submitText || defaultStyles.submitText}>{text?.submitButton || 'Send Feedback'}</Text>
99+
<Text style={styles?.submitText || defaultStyles.submitText}>{text?.submitButton || defaultSubmitButton}</Text>
90100
</TouchableOpacity>
91101

92102
<TouchableOpacity style={styles?.cancelButton || defaultStyles.cancelButton} onPress={closeScreen}>
93-
<Text style={styles?.cancelText || defaultStyles.cancelText}>{text?.cancelButton || 'Cancel'}</Text>
103+
<Text style={styles?.cancelText || defaultStyles.cancelText}>{text?.cancelButton || defaultCancelButton}</Text>
94104
</TouchableOpacity>
95105
</View>
96106
);

0 commit comments

Comments
 (0)