From caa1237cf33f36e04f0b0d203855d2577009ef95 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Mon, 27 Jan 2025 16:57:54 +0200 Subject: [PATCH] Adds feedbackIntegration for configuring the feedback form --- .../src/js/feedback/FeedbackFormManager.tsx | 3 +- packages/core/src/js/feedback/integration.ts | 31 +++++++++++++++++++ packages/core/src/js/integrations/exports.ts | 1 + samples/react-native/src/App.tsx | 12 +++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 packages/core/src/js/feedback/integration.ts diff --git a/packages/core/src/js/feedback/FeedbackFormManager.tsx b/packages/core/src/js/feedback/FeedbackFormManager.tsx index e69ac11e6c..4676f90258 100644 --- a/packages/core/src/js/feedback/FeedbackFormManager.tsx +++ b/packages/core/src/js/feedback/FeedbackFormManager.tsx @@ -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 { @@ -70,7 +71,7 @@ class FeedbackFormProvider extends React.Component { - diff --git a/packages/core/src/js/feedback/integration.ts b/packages/core/src/js/feedback/integration.ts new file mode 100644 index 0000000000..33fd8d146d --- /dev/null +++ b/packages/core/src/js/feedback/integration.ts @@ -0,0 +1,31 @@ +import type { Integration } from '@sentry/core'; + +import { defaultConfiguration } from './defaults'; +import defaultStyles from './FeedbackForm.styles'; +import type { FeedbackFormProps } from './FeedbackForm.types'; + +export const FEEDBACK_FORM_INTEGRATION_NAME = 'Feedback Form'; + +type FeedbackIntegration = Integration & { + options: Partial; +}; + +let savedOptions: Partial = {}; + +export const feedbackIntegration = (initOptions: FeedbackFormProps = {}): FeedbackIntegration => { + savedOptions = { + ...defaultConfiguration, + ...initOptions, + styles: { + ...defaultStyles, + ...initOptions.styles, + }, + }; + + return { + name: FEEDBACK_FORM_INTEGRATION_NAME, + options: savedOptions, + }; +}; + +export const getFeedbackOptions = (): Partial => savedOptions; diff --git a/packages/core/src/js/integrations/exports.ts b/packages/core/src/js/integrations/exports.ts index dfc9e2c3e1..f5fabb397e 100644 --- a/packages/core/src/js/integrations/exports.ts +++ b/packages/core/src/js/integrations/exports.ts @@ -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'; diff --git a/samples/react-native/src/App.tsx b/samples/react-native/src/App.tsx index 2df2079c0b..a9e36e7fd5 100644 --- a/samples/react-native/src/App.tsx +++ b/samples/react-native/src/App.tsx @@ -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'); },