Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/src/js/feedback/FeedbackFormManager.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import { Modal, View } from 'react-native';
import { FeedbackForm } from './FeedbackForm';
import defaultStyles from './FeedbackForm.styles';
import type { FeedbackFormStyles } from './FeedbackForm.types';
import { getFeedbackOptions } from './integration';
import { isModalSupported } from './utils';

class FeedbackFormManager {
Expand DownExpand Up@@ -70,7 +71,7 @@ class FeedbackFormProvider extends React.Component<FeedbackFormProviderProps> {
<View>
<Modal visible={isVisible} transparent animationType="slide" onRequestClose={this._handleClose} testID="feedback-form-modal">
<View style={styles.modalBackground}>
<FeedbackForm
<FeedbackForm {...getFeedbackOptions()}
onFormClose={this._handleClose}
onFormSubmitted={this._handleClose}
/>
Expand Down
22 changes: 22 additions & 0 deletions packages/core/src/js/feedback/integration.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import type { Integration } from '@sentry/core';

import type { FeedbackFormProps } from './FeedbackForm.types';

export const FEEDBACK_FORM_INTEGRATION_NAME = 'MobileFeedback';

type FeedbackIntegration = Integration & {
options: Partial<FeedbackFormProps>;
};

let savedOptions: Partial<FeedbackFormProps> = {};

export const feedbackIntegration = (initOptions: FeedbackFormProps = {}): FeedbackIntegration => {
savedOptions = initOptions;

return {
name: FEEDBACK_FORM_INTEGRATION_NAME,
options: savedOptions,
};
};

export const getFeedbackOptions = (): Partial<FeedbackFormProps> => savedOptions;
1 change: 1 addition & 0 deletions packages/core/src/js/integrations/exports.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ export { viewHierarchyIntegration } from './viewhierarchy';
export { expoContextIntegration } from './expocontext';
export { spotlightIntegration } from './spotlight';
export { mobileReplayIntegration } from '../replay/mobilereplay';
export { feedbackIntegration } from '../feedback/integration';
export { browserReplayIntegration } from '../replay/browserReplay';
export { appStartIntegration } from '../tracing/integrations/appStart';
export { nativeFramesIntegration, createNativeFramesIntegrations } from '../tracing/integrations/nativeFrames';
Expand Down
40 changes: 40 additions & 0 deletions packages/core/test/feedback/FeedbackFormManager.test.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,9 @@ import { render } from '@testing-library/react-native';
import * as React from 'react';
import { Text } from 'react-native';

import { defaultConfiguration } from '../../src/js/feedback/defaults';
import { FeedbackFormProvider, showFeedbackForm } from '../../src/js/feedback/FeedbackFormManager';
import { feedbackIntegration } from '../../src/js/feedback/integration';
import { isModalSupported } from '../../src/js/feedback/utils';

jest.mock('../../src/js/feedback/utils', () => ({
Expand DownExpand Up@@ -53,4 +55,42 @@ describe('FeedbackFormManager', () => {
showFeedbackForm();
}).not.toThrow();
});

it('showFeedbackForm displays the form with the feedbackIntegration options', () => {
mockedIsModalSupported.mockReturnValue(true);
const { getByPlaceholderText, getByText } = render(
<FeedbackFormProvider>
<Text>App Components</Text>
</FeedbackFormProvider>
);

feedbackIntegration({
messagePlaceholder: 'Custom Message Placeholder',
submitButtonLabel: 'Custom Submit Button',
});

showFeedbackForm();

expect(getByPlaceholderText('Custom Message Placeholder')).toBeTruthy();
expect(getByText('Custom Submit Button')).toBeTruthy();
});

it('showFeedbackForm displays the form with the feedbackIntegration options merged with the defaults', () => {
mockedIsModalSupported.mockReturnValue(true);
const { getByPlaceholderText, getByText, queryByText } = render(
<FeedbackFormProvider>
<Text>App Components</Text>
</FeedbackFormProvider>
);

feedbackIntegration({
submitButtonLabel: 'Custom Submit Button',
}),

showFeedbackForm();

expect(queryByText(defaultConfiguration.submitButtonLabel)).toBeFalsy(); // overridden value
expect(getByText('Custom Submit Button')).toBeTruthy(); // overridden value
expect(getByPlaceholderText(defaultConfiguration.messagePlaceholder)).toBeTruthy(); // default configuration value
});
});
12 changes: 12 additions & 0 deletions samples/react-native/src/App.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,6 +106,18 @@ Sentry.init({
? false
: true,
}),
Sentry.feedbackIntegration({
styles:{
submitButton: {
backgroundColor: '#6a1b9a',
paddingVertical: 15,
borderRadius: 5,
alignItems: 'center',
marginBottom: 10,
},
},
namePlaceholder: 'Fullname',
}),
);
return integrations.filter(i => i.name !== 'Dedupe');
},
Expand Down