Skip to content

Commit

Permalink
Use AddScreenshot naming
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis committed Jan 10, 2025
1 parent fe23346 commit a1cb828
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/js/feedback/FeedbackForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
Alert.alert(text.successMessageText);
};

public addRemoveAttachment: () => void = () => {
public addRemoveScreenshot: () => void = () => {
if (!this.state.filename && !this.state.attachment) {
const { onFileChosen } = { ...defaultConfiguration, ...this.props };
onFileChosen((filename: string, attachement: string | Uint8Array) => {
const { onAddScreenshot } = { ...defaultConfiguration, ...this.props };
onAddScreenshot((filename: string, attachement: string | Uint8Array) => {
this.setState({ filename, attachment: attachement });
});
} else {
Expand Down Expand Up @@ -183,7 +183,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
multiline
/>
{config.enableScreenshot && (
<TouchableOpacity style={styles.screenshotButton} onPress={this.addRemoveAttachment}>
<TouchableOpacity style={styles.screenshotButton} onPress={this.addRemoveScreenshot}>
<Text style={styles.screenshotText}>
{!this.state.filename && !this.state.attachment
? text.addScreenshotButtonLabel
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/js/feedback/FeedbackForm.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ export interface FeedbackCallbacks {
onFormClose?: () => void;

/**
* Callback when a file is chosen for attachment
* Callback when a screenshot is added
*/
onFileChosen?: (attachFile: (filename: string, base64Attachment: string | Uint8Array) => void) => void;
onAddScreenshot?: (attachFile: (filename: string, base64Attachment: string | Uint8Array) => void) => void;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/js/feedback/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export const defaultConfiguration: Partial<FeedbackFormProps> = {
);
}
},
onFileChosen: (_: (filename: string, base64Attachment: string | Uint8Array) => void) => {
onAddScreenshot: (_: (filename: string, base64Attachment: string | Uint8Array) => void) => {
if (__DEV__) {
Alert.alert('Development note', 'onFileChosen callback is not implemented.');
Alert.alert('Development note', 'onAddScreenshot callback is not implemented.');
}
},

Expand Down
8 changes: 4 additions & 4 deletions packages/core/test/feedback/FeedbackForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FeedbackForm } from '../../src/js/feedback/FeedbackForm';
import type { FeedbackFormProps } from '../../src/js/feedback/FeedbackForm.types';

const mockOnFormClose = jest.fn();
const mockOnFileChosen = jest.fn();
const mockOnAddScreenshot = jest.fn();
const mockGetUser = jest.fn(() => ({
email: '[email protected]',
name: 'Test User',
Expand All @@ -25,7 +25,7 @@ jest.mock('@sentry/core', () => ({

const defaultProps: FeedbackFormProps = {
onFormClose: mockOnFormClose,
onFileChosen: mockOnFileChosen,
onAddScreenshot: mockOnAddScreenshot,
addScreenshotButtonLabel: 'Add Screenshot',
formTitle: 'Feedback Form',
nameLabel: 'Name',
Expand Down Expand Up @@ -168,13 +168,13 @@ describe('FeedbackForm', () => {
});
});

it('calls onFileChosen when the screenshot button is pressed', async () => {
it('calls onAddScreenshot when the screenshot button is pressed', async () => {
const { getByText } = render(<FeedbackForm {...defaultProps} enableScreenshot={true} />);

fireEvent.press(getByText(defaultProps.addScreenshotButtonLabel));

await waitFor(() => {
expect(mockOnFileChosen).toHaveBeenCalled();
expect(mockOnAddScreenshot).toHaveBeenCalled();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>C617.1</string>
<string>3B52.1</string>
</array>
</dict>
<dict>
Expand Down
4 changes: 2 additions & 2 deletions samples/react-native/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const Stack = isMobileOs
: createStackNavigator();
const Tab = createBottomTabNavigator();

const handleChooseFile = (attachFile: (filename: string, base64Attachment: string | Uint8Array) => void): void => {
const handleChooseImage = (attachFile: (filename: string, base64Attachment: string | Uint8Array) => void): void => {
launchImageLibrary({ mediaType: 'photo', includeBase64: true }, (response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
Expand Down Expand Up @@ -176,7 +176,7 @@ const ErrorsTabNavigator = Sentry.withProfiler(
<FeedbackForm
{...props}
enableScreenshot={true}
onFileChosen={handleChooseFile}
onAddScreenshot={handleChooseImage}
onFormClose={props.navigation.goBack}
styles={{
submitButton: {
Expand Down

0 comments on commit a1cb828

Please sign in to comment.