1- import { getCurrentScope } from '@sentry/core' ;
2- import type { Integration , IntegrationFn } from '@sentry/types' ;
3- import { isBrowser } from '@sentry/utils' ;
1+ import { convertIntegrationFnToClass , defineIntegration , getCurrentScope } from '@sentry/core' ;
2+ import type { Integration , IntegrationClass , IntegrationFn , IntegrationFnResult } from '@sentry/types' ;
43import { h } from 'preact' ;
54import type { sendFeedback as sendFeedbackFn } from '../core/sendFeedback' ;
6- import type { Feedback2Screenshot } from '../screenshot/integration' ;
5+ import type { IFeedback2ScreenshotIntegration } from '../screenshot/integration' ;
76import type { FeedbackFormData , FeedbackInternalOptions } from '../types' ;
87import { Dialog } from './components/Dialog' ;
98import type { DialogComponent } from './components/Dialog' ;
@@ -22,110 +21,86 @@ interface CreateDialogProps {
2221 */
2322 onDone : ( ) => void ;
2423
25- // eslint-disable-next-line deprecation/deprecation
26- screenshotIntegration : Feedback2Screenshot | undefined ;
24+ screenshotIntegration : IFeedback2ScreenshotIntegration | undefined ;
2725}
2826
29- export const feedback2ModalIntegration = ( ( ) => {
30- // eslint-disable-next-line deprecation/deprecation
31- return new Feedback2Modal ( ) ;
32- } ) satisfies IntegrationFn ;
27+ interface PublicFeedback2ModalIntegration {
28+ createDialog : ( props : CreateDialogProps ) => DialogComponent ;
29+ }
3330
34- /**
35- * TODO
36- *
37- * @deprecated Use `feedbackIntegration()` instead.
38- */
39- export class Feedback2Modal implements Integration {
40- /**
41- * @inheritDoc
42- */
43- public static id : string = 'Feedback2Modal' ;
31+ export type IFeedback2ModalIntegration = IntegrationFnResult & PublicFeedback2ModalIntegration ;
4432
45- /**
46- * @inheritDoc
47- */
48- public name : string ;
33+ export const _feedback2ModalIntegration = ( ( ) => {
34+ return {
35+ name : 'Feedback2Modal' ,
36+ // eslint-disable-next-line @typescript-eslint/no-empty-function
37+ setupOnce ( ) { } ,
38+ createDialog ( { shadow, sendFeedback, options, onDone, screenshotIntegration } : CreateDialogProps ) : DialogComponent {
39+ const userKey = options . useSentryUser ;
40+ const scope = getCurrentScope ( ) ;
41+ const user = scope && scope . getUser ( ) ;
4942
50- public constructor ( ) {
51- // eslint-disable-next-line deprecation/deprecation
52- this . name = Feedback2Modal . id ;
53- }
43+ const screenshotWidget = screenshotIntegration && screenshotIntegration . createWidget ( h ) ;
5444
55- /**
56- * Setup and initialize feedback container
57- */
58- public setupOnce ( ) : void {
59- if ( ! isBrowser ( ) ) {
60- return ;
61- }
45+ const dialog = Dialog ( {
46+ screenshotWidget,
47+ colorScheme : options . colorScheme ,
48+ showBranding : options . showBranding ,
49+ showName : options . showName || options . isNameRequired ,
50+ showEmail : options . showEmail || options . isEmailRequired ,
51+ isNameRequired : options . isNameRequired ,
52+ isEmailRequired : options . isEmailRequired ,
53+ formTitle : options . formTitle ,
54+ cancelButtonLabel : options . cancelButtonLabel ,
55+ submitButtonLabel : options . submitButtonLabel ,
56+ emailLabel : options . emailLabel ,
57+ emailPlaceholder : options . emailPlaceholder ,
58+ messageLabel : options . messageLabel ,
59+ messagePlaceholder : options . messagePlaceholder ,
60+ nameLabel : options . nameLabel ,
61+ namePlaceholder : options . namePlaceholder ,
62+ defaultName : ( userKey && user && user [ userKey . name ] ) || '' ,
63+ defaultEmail : ( userKey && user && user [ userKey . email ] ) || '' ,
64+ successMessageText : options . successMessageText ,
65+ onFormClose : ( ) => {
66+ shadow . removeChild ( dialog . el ) ;
67+ shadow . removeChild ( dialog . style ) ;
68+ screenshotWidget && shadow . removeChild ( screenshotWidget . style ) ;
69+ onDone ( ) ;
70+ options . onFormClose && options . onFormClose ( ) ;
71+ } ,
72+ onSubmit : sendFeedback ,
73+ onSubmitSuccess : ( data : FeedbackFormData ) => {
74+ options . onSubmitSuccess && options . onSubmitSuccess ( data ) ;
75+ } ,
76+ onSubmitError : ( error : Error ) => {
77+ options . onSubmitError && options . onSubmitError ( error ) ;
78+ } ,
79+ onFormSubmitted : ( ) => {
80+ shadow . removeChild ( dialog . el ) ;
81+ shadow . removeChild ( dialog . style ) ;
82+ screenshotWidget && shadow . removeChild ( screenshotWidget . style ) ;
83+ onDone ( ) ;
84+ options . onFormSubmitted && options . onFormSubmitted ( ) ;
85+ } ,
86+ } ) ;
87+ shadow . appendChild ( dialog . style ) ;
88+ screenshotWidget && shadow . appendChild ( screenshotWidget . style ) ;
89+ shadow . appendChild ( dialog . el ) ;
90+ options . onFormOpen && options . onFormOpen ( ) ;
6291
63- // Nothing?
64- }
65-
66- /**
67- *
68- */
69- public createDialog ( {
70- shadow,
71- sendFeedback,
72- options,
73- onDone,
74- screenshotIntegration,
75- } : CreateDialogProps ) : DialogComponent {
76- const userKey = options . useSentryUser ;
77- const scope = getCurrentScope ( ) ;
78- const user = scope && scope . getUser ( ) ;
79-
80- const screenshotWidget = screenshotIntegration && screenshotIntegration . createWidget ( h ) ;
92+ return dialog ;
93+ } ,
94+ } ;
95+ } ) satisfies IntegrationFn ;
8196
82- const dialog = Dialog ( {
83- screenshotWidget,
84- colorScheme : options . colorScheme ,
85- showBranding : options . showBranding ,
86- showName : options . showName || options . isNameRequired ,
87- showEmail : options . showEmail || options . isEmailRequired ,
88- isNameRequired : options . isNameRequired ,
89- isEmailRequired : options . isEmailRequired ,
90- formTitle : options . formTitle ,
91- cancelButtonLabel : options . cancelButtonLabel ,
92- submitButtonLabel : options . submitButtonLabel ,
93- emailLabel : options . emailLabel ,
94- emailPlaceholder : options . emailPlaceholder ,
95- messageLabel : options . messageLabel ,
96- messagePlaceholder : options . messagePlaceholder ,
97- nameLabel : options . nameLabel ,
98- namePlaceholder : options . namePlaceholder ,
99- defaultName : ( userKey && user && user [ userKey . name ] ) || '' ,
100- defaultEmail : ( userKey && user && user [ userKey . email ] ) || '' ,
101- successMessageText : options . successMessageText ,
102- onFormClose : ( ) => {
103- shadow . removeChild ( dialog . el ) ;
104- shadow . removeChild ( dialog . style ) ;
105- screenshotWidget && shadow . removeChild ( screenshotWidget . style ) ;
106- onDone ( ) ;
107- options . onFormClose && options . onFormClose ( ) ;
108- } ,
109- onSubmit : sendFeedback ,
110- onSubmitSuccess : ( data : FeedbackFormData ) => {
111- options . onSubmitSuccess && options . onSubmitSuccess ( data ) ;
112- } ,
113- onSubmitError : ( error : Error ) => {
114- options . onSubmitError && options . onSubmitError ( error ) ;
115- } ,
116- onFormSubmitted : ( ) => {
117- shadow . removeChild ( dialog . el ) ;
118- shadow . removeChild ( dialog . style ) ;
119- screenshotWidget && shadow . removeChild ( screenshotWidget . style ) ;
120- onDone ( ) ;
121- options . onFormSubmitted && options . onFormSubmitted ( ) ;
122- } ,
123- } ) ;
124- shadow . appendChild ( dialog . style ) ;
125- screenshotWidget && shadow . appendChild ( screenshotWidget . style ) ;
126- shadow . appendChild ( dialog . el ) ;
127- options . onFormOpen && options . onFormOpen ( ) ;
97+ export const feedback2ModalIntegration = defineIntegration ( _feedback2ModalIntegration ) ;
12898
129- return dialog ;
130- }
131- }
99+ /**
100+ * @deprecated Use `feedback2ModalIntegration()` instead
101+ */
102+ // eslint-disable-next-line deprecation/deprecation
103+ export const Feedback2Modal = convertIntegrationFnToClass (
104+ 'Feedback2Modal' ,
105+ feedback2ModalIntegration ,
106+ ) as IntegrationClass < Integration & PublicFeedback2ModalIntegration > ;
0 commit comments