Skip to content

Commit

Permalink
Merge 8b9f4d5 into f8a82fd
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis authored Dec 13, 2024
2 parents f8a82fd + 8b9f4d5 commit 068e9ea
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
...
<FeedbackForm/>
```
or auto-inject it by calling the `showFeedbackForm`:
```jsx
import { showFeedbackForm } from '@sentry/react-native';
...
<Button
title="Show feedback form"
onPress={() => {
showFeedbackForm(_props.navigation);
}}
/>
```

- Export `Span` type from `@sentry/types` ([#4345](https://github.com/getsentry/sentry-react-native/pull/4345))

Expand Down
34 changes: 33 additions & 1 deletion packages/core/src/js/feedback/FeedbackForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { captureFeedback, lastEventId } from '@sentry/core';
import { captureFeedback, lastEventId, logger } from '@sentry/core';
import type { SendFeedbackParams } from '@sentry/types';
import * as React from 'react';
import type { KeyboardTypeOptions } from 'react-native';
Expand All @@ -8,6 +8,31 @@ import { defaultConfiguration } from './defaults';
import defaultStyles from './FeedbackForm.styles';
import type { FeedbackFormProps, FeedbackFormState, FeedbackFormStyles,FeedbackGeneralConfiguration, FeedbackTextConfiguration } from './FeedbackForm.types';

let feedbackFormHandler: (() => void) | null = null;

const setFeedbackFormHandler = (handler: () => void): void => {
feedbackFormHandler = handler;
};

const clearFeedbackFormHandler = (): void => {
feedbackFormHandler = null;
};

type Navigation = {
navigate: (screen: string, params?: Record<string, unknown>) => void;
};

export const showFeedbackForm = (navigation: Navigation): void => {
setFeedbackFormHandler(() => {
navigation?.navigate?.('FeedbackForm');
});
if (feedbackFormHandler) {
feedbackFormHandler();
} else {
logger.error('FeedbackForm handler is not set. Please ensure it is initialized.');
}
};

/**
* @beta
* Implements a feedback form screen that sends feedback to Sentry using Sentry.captureFeedback.
Expand All @@ -25,6 +50,13 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
};
}

/**
* Clear the handler when the component unmounts
*/
public componentWillUnmount(): void {
clearFeedbackFormHandler();
}

public handleFeedbackSubmit: () => void = () => {
const { name, email, description } = this.state;
const { onFormClose } = { ...defaultConfiguration, ...this.props };
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ export type { TimeToDisplayProps } from './tracing';

export { Mask, Unmask } from './replay/CustomMask';

export { FeedbackForm } from './feedback/FeedbackForm';
export { FeedbackForm, showFeedbackForm } from './feedback/FeedbackForm';
7 changes: 7 additions & 0 deletions samples/react-native/src/Screens/ErrorsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from 'react-native';

import * as Sentry from '@sentry/react-native';
import { showFeedbackForm } from '@sentry/react-native';

import { setScopeProperties } from '../setScopeProperties';
import { StackNavigationProp } from '@react-navigation/stack';
Expand Down Expand Up @@ -226,6 +227,12 @@ const ErrorsScreen = (_props: Props) => {
_props.navigation.navigate('FeedbackForm');
}}
/>
<Button
title="Feedback form (autoinject)"
onPress={() => {
showFeedbackForm(_props.navigation);
}}
/>
<Button
title="Send user feedback"
onPress={() => {
Expand Down

0 comments on commit 068e9ea

Please sign in to comment.