Skip to content

Commit d916488

Browse files
committed
fea(feedback): Add reason argument to onFormClose callback
1 parent c49c9f3 commit d916488

File tree

10 files changed

+33
-14
lines changed

10 files changed

+33
-14
lines changed

docs/migration/feedback.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ For example, `attachTo()` is a convenience wrapper over the lifecycle methods. Y
8686
function attachTo(button: HTMLElement) {
8787
const handleClick = () => {
8888
const widget = feedbackInstance.createWidget({
89-
onFormClose: () => {
89+
onFormClose: ({ reason }) => {
9090
widget.close();
9191
},
9292
onFormSubmited: () => {

packages/feedback/rollup.bundle.config.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ export default [
1616
},
1717
}),
1818
),
19+
...makeBundleConfigVariants(
20+
makeBaseBundleConfig({
21+
bundleType: 'addon',
22+
entrypoints: ['src/core/integration.ts'],
23+
jsVersion: 'es6',
24+
licenseTitle: '@sentry-internal/feedback-core',
25+
outputFileBase: () => 'bundles/feedback-core',
26+
sucrase: {
27+
// The feedback widget is using preact so we need different pragmas and jsx runtimes
28+
jsxPragma: 'h',
29+
jsxFragmentPragma: 'Fragment',
30+
jsxRuntime: 'classic',
31+
},
32+
}),
33+
),
1934
...makeBundleConfigVariants(
2035
makeBaseBundleConfig({
2136
bundleType: 'addon',

packages/feedback/src/core/integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ export const buildFeedbackIntegration = ({
231231
if (!dialog) {
232232
dialog = await _loadAndRenderDialog({
233233
...mergedOptions,
234-
onFormClose: () => {
234+
onFormClose: ({ reason }) => {
235235
dialog && dialog.close();
236-
mergedOptions.onFormClose && mergedOptions.onFormClose();
236+
mergedOptions.onFormClose && mergedOptions.onFormClose({ reason });
237237
},
238238
onFormSubmitted: () => {
239239
dialog && dialog.removeFromDom();

packages/feedback/src/modal/components/Dialog.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode {
5454
</div>
5555
</div>
5656
) : (
57-
<dialog class="dialog" onClick={options.onFormClose} open={open}>
57+
<dialog
58+
class="dialog"
59+
onClick={() => options.onFormClose && options.onFormClose({ reason: 'dialog-dismissed' })}
60+
open={open}
61+
>
5862
<div class="dialog__position">
5963
<div
6064
class="dialog__content"

packages/feedback/src/modal/components/Form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface Props extends Pick<FeedbackInternalOptions, 'showEmail' | 'show
1717
options: FeedbackInternalOptions;
1818
defaultEmail: string;
1919
defaultName: string;
20-
onFormClose: () => void;
20+
onFormClose: (args: { reason: 'dialog-dismissed' | 'form-cancelled' }) => void;
2121
onSubmit: SendFeedback;
2222
onSubmitSuccess: (data: FeedbackFormData) => void;
2323
onSubmitError: (error: Error) => void;
@@ -217,7 +217,7 @@ export function Form({
217217
<button class="btn btn--primary" type="submit">
218218
{submitButtonLabel}
219219
</button>
220-
<button class="btn btn--default" type="button" onClick={onFormClose}>
220+
<button class="btn btn--default" type="button" onClick={() => onFormClose({ reason: 'form-cancelled' })}>
221221
{cancelButtonLabel}
222222
</button>
223223
</div>

packages/feedback/src/modal/integration.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => {
7171
showEmail={options.showEmail || options.isEmailRequired}
7272
defaultName={(userKey && user && user[userKey.name]) || ''}
7373
defaultEmail={(userKey && user && user[userKey.email]) || ''}
74-
onFormClose={() => {
74+
onFormClose={({ reason }) => {
7575
renderContent(false);
76-
options.onFormClose && options.onFormClose();
76+
options.onFormClose && options.onFormClose({ reason });
7777
}}
7878
onSubmit={sendFeedback}
7979
onSubmitSuccess={(data: FeedbackFormData) => {

packages/feedback/src/screenshot/integration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const feedbackScreenshotIntegration = ((): FeedbackScreenshotIntegration
3131
const attachment: Attachment = {
3232
data,
3333
filename: 'screenshot.png',
34-
contentType: 'application/png',
34+
// contentType: 'application/png',
3535
// attachmentType?: string;
3636
};
3737
return attachment;

packages/feedback/src/util/mergeOptions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export function mergeOptions(
1919
optionOverrides.onFormOpen && optionOverrides.onFormOpen();
2020
defaultOptions.onFormOpen && defaultOptions.onFormOpen();
2121
},
22-
onFormClose: () => {
23-
optionOverrides.onFormClose && optionOverrides.onFormClose();
24-
defaultOptions.onFormClose && defaultOptions.onFormClose();
22+
onFormClose: (...args) => {
23+
optionOverrides.onFormClose && optionOverrides.onFormClose(...args);
24+
defaultOptions.onFormClose && defaultOptions.onFormClose(...args);
2525
},
2626
onSubmitSuccess: (data: FeedbackFormData) => {
2727
optionOverrides.onSubmitSuccess && optionOverrides.onSubmitSuccess(data);

packages/integration-shims/src/Feedback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Integration } from '@sentry/types';
22
import { consoleSandbox } from '@sentry/utils';
33
import { FAKE_FUNCTION } from './common';
44

5-
const FEEDBACK_INTEGRATION_METHODS = ['attachTo', 'createWidget', 'remove'] as const;
5+
const FEEDBACK_INTEGRATION_METHODS = ['attachTo', 'createForm', 'createWidget', 'remove'] as const;
66

77
type FeedbackSpecificMethods = Record<(typeof FEEDBACK_INTEGRATION_METHODS)[number], () => void>;
88

packages/types/src/feedback/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export interface FeedbackCallbacks {
175175
/**
176176
* Callback when form is closed and not submitted
177177
*/
178-
onFormClose?: () => void;
178+
onFormClose?: (args: { reason: 'dialog-dismissed' | 'form-cancelled' }) => void;
179179

180180
/**
181181
* Callback when feedback is successfully submitted

0 commit comments

Comments
 (0)