Skip to content

Commit

Permalink
Merge 2ae0ddb into d84ae63
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis authored Dec 18, 2024
2 parents d84ae63 + 2ae0ddb commit 279f59b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"react-native": ">=0.65.0"
},
"dependencies": {
"@sentry-internal/feedback": "8.45.1",
"@sentry/babel-plugin-component-annotate": "2.20.1",
"@sentry/browser": "8.46.0",
"@sentry/cli": "2.39.1",
Expand Down
29 changes: 22 additions & 7 deletions packages/core/src/js/feedback/FeedbackForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { SendFeedbackParams } from '@sentry/core';
import { captureFeedback, getCurrentScope, lastEventId, logger } from '@sentry/core';
import { sendFeedback } from '@sentry-internal/feedback';
import type { EventHint, SendFeedbackParams } from '@sentry/core';
import { getCurrentScope, lastEventId, logger } from '@sentry/core';
import * as React from 'react';
import type { KeyboardTypeOptions } from 'react-native';
import {
Expand All @@ -20,6 +21,15 @@ import defaultStyles from './FeedbackForm.styles';
import type { FeedbackFormProps, FeedbackFormState, FeedbackFormStyles,FeedbackGeneralConfiguration, FeedbackTextConfiguration } from './FeedbackForm.types';
import { checkInternetConnection, isValidEmail } from './utils';

const submitFeedback = async (feedbackParams: SendFeedbackParams, hint: EventHint, success: () => void, error: (e: string) => void): Promise<void> => {
try {
await sendFeedback(feedbackParams, hint);
success();
} catch (e) {
error(e.toString());
}
};

/**
* @beta
* Implements a feedback form screen that sends feedback to Sentry using Sentry.captureFeedback.
Expand Down Expand Up @@ -76,11 +86,16 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor

// eslint-disable-next-line @typescript-eslint/no-floating-promises
checkInternetConnection(() => { // onConnected
this.setState({ isVisible: false });
captureFeedback(userFeedback);
onSubmitSuccess({ name: trimmedName, email: trimmedEmail, message: trimmedDescription, attachments: undefined });
Alert.alert(text.successMessageText);
onFormSubmitted();
// eslint-disable-next-line @typescript-eslint/no-floating-promises
submitFeedback(userFeedback, undefined, () => { // success
this.setState({ isVisible: false });
onSubmitSuccess({ name: trimmedName, email: trimmedEmail, message: trimmedDescription, attachments: undefined });
Alert.alert(text.successMessageText);
onFormSubmitted();
}, (error: string) => { // error
Alert.alert(text.errorTitle, error);
logger.error(`Feedback form submission failed: ${error}`);
});
}, () => { // onDisconnected
Alert.alert(text.errorTitle, text.networkError);
logger.error(`Feedback form submission failed: ${text.networkError}`);
Expand Down
12 changes: 7 additions & 5 deletions packages/core/test/feedback/FeedbackForm.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { captureFeedback } from '@sentry/core';
import { sendFeedback } from '@sentry-internal/feedback';
import { fireEvent, render, waitFor } from '@testing-library/react-native';
import * as React from 'react';
import { Alert } from 'react-native';
Expand All @@ -20,7 +20,6 @@ jest.spyOn(Alert, 'alert');

jest.mock('@sentry/core', () => ({
...jest.requireActual('@sentry/core'),
captureFeedback: jest.fn(),
getCurrentScope: jest.fn(() => ({
getUser: mockGetUser,
})),
Expand All @@ -30,6 +29,9 @@ jest.mock('../../src/js/feedback/utils', () => ({
...jest.requireActual('../../src/js/feedback/utils'),
checkInternetConnection: jest.fn(),
}));
jest.mock('@sentry-internal/feedback', () => ({
sendFeedback: jest.fn(),
}));

const defaultProps: FeedbackFormProps = {
onFormClose: mockOnFormClose,
Expand Down Expand Up @@ -124,7 +126,7 @@ describe('FeedbackForm', () => {
});
});

it('calls captureFeedback when the form is submitted successfully', async () => {
it('calls sendFeedback when the form is submitted successfully', async () => {
const { getByPlaceholderText, getByText } = render(<FeedbackForm {...defaultProps} />);

fireEvent.changeText(getByPlaceholderText(defaultProps.namePlaceholder), 'John Doe');
Expand All @@ -134,11 +136,11 @@ describe('FeedbackForm', () => {
fireEvent.press(getByText(defaultProps.submitButtonLabel));

await waitFor(() => {
expect(captureFeedback).toHaveBeenCalledWith({
expect(sendFeedback).toHaveBeenCalledWith({
message: 'This is a feedback message.',
name: 'John Doe',
email: '[email protected]',
});
}, undefined);
});
});

Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7591,6 +7591,15 @@ __metadata:
languageName: node
linkType: hard

"@sentry-internal/feedback@npm:8.45.1":
version: 8.45.1
resolution: "@sentry-internal/feedback@npm:8.45.1"
dependencies:
"@sentry/core": 8.45.1
checksum: aa0d50078350dbfd3ebdfed448a0d4279324d624fb464bc411d3ec286d6895e52753bc9217bcdfe75a35e184d479588227d1e503bf766ea39bd5392103431b25
languageName: node
linkType: hard

"@sentry-internal/feedback@npm:8.46.0":
version: 8.46.0
resolution: "@sentry-internal/feedback@npm:8.46.0"
Expand Down Expand Up @@ -7779,6 +7788,13 @@ __metadata:
languageName: node
linkType: hard

"@sentry/core@npm:8.45.1":
version: 8.45.1
resolution: "@sentry/core@npm:8.45.1"
checksum: 81ed72485685d7baf246ed35c01428664a97eece445ab7b801b908e93dcb58652eaca588c2f9f80baa95419590eb78251305f9e5258ba8a1efee839cb40b15c8
languageName: node
linkType: hard

"@sentry/core@npm:8.46.0":
version: 8.46.0
resolution: "@sentry/core@npm:8.46.0"
Expand Down Expand Up @@ -7821,6 +7837,7 @@ __metadata:
"@react-native/babel-preset": 0.76.3
"@sentry-internal/eslint-config-sdk": 8.46.0
"@sentry-internal/eslint-plugin-sdk": 8.46.0
"@sentry-internal/feedback": 8.45.1
"@sentry-internal/typescript": 8.46.0
"@sentry/babel-plugin-component-annotate": 2.20.1
"@sentry/browser": 8.46.0
Expand Down

0 comments on commit 279f59b

Please sign in to comment.