Skip to content

Commit

Permalink
fea(feedback): Add reason argument to onFormClose callback
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan953 committed Jul 8, 2024
1 parent c49c9f3 commit d916488
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/migration/feedback.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ For example, `attachTo()` is a convenience wrapper over the lifecycle methods. Y
function attachTo(button: HTMLElement) {
const handleClick = () => {
const widget = feedbackInstance.createWidget({
onFormClose: () => {
onFormClose: ({ reason }) => {
widget.close();
},
onFormSubmited: () => {
Expand Down
15 changes: 15 additions & 0 deletions packages/feedback/rollup.bundle.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ export default [
},
}),
),
...makeBundleConfigVariants(
makeBaseBundleConfig({
bundleType: 'addon',
entrypoints: ['src/core/integration.ts'],
jsVersion: 'es6',
licenseTitle: '@sentry-internal/feedback-core',
outputFileBase: () => 'bundles/feedback-core',
sucrase: {
// The feedback widget is using preact so we need different pragmas and jsx runtimes
jsxPragma: 'h',
jsxFragmentPragma: 'Fragment',
jsxRuntime: 'classic',
},
}),
),
...makeBundleConfigVariants(
makeBaseBundleConfig({
bundleType: 'addon',
Expand Down
4 changes: 2 additions & 2 deletions packages/feedback/src/core/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ export const buildFeedbackIntegration = ({
if (!dialog) {
dialog = await _loadAndRenderDialog({
...mergedOptions,
onFormClose: () => {
onFormClose: ({ reason }) => {
dialog && dialog.close();
mergedOptions.onFormClose && mergedOptions.onFormClose();
mergedOptions.onFormClose && mergedOptions.onFormClose({ reason });
},
onFormSubmitted: () => {
dialog && dialog.removeFromDom();
Expand Down
6 changes: 5 additions & 1 deletion packages/feedback/src/modal/components/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode {
</div>
</div>
) : (
<dialog class="dialog" onClick={options.onFormClose} open={open}>
<dialog
class="dialog"
onClick={() => options.onFormClose && options.onFormClose({ reason: 'dialog-dismissed' })}
open={open}
>
<div class="dialog__position">
<div
class="dialog__content"
Expand Down
4 changes: 2 additions & 2 deletions packages/feedback/src/modal/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface Props extends Pick<FeedbackInternalOptions, 'showEmail' | 'show
options: FeedbackInternalOptions;
defaultEmail: string;
defaultName: string;
onFormClose: () => void;
onFormClose: (args: { reason: 'dialog-dismissed' | 'form-cancelled' }) => void;
onSubmit: SendFeedback;
onSubmitSuccess: (data: FeedbackFormData) => void;
onSubmitError: (error: Error) => void;
Expand Down Expand Up @@ -217,7 +217,7 @@ export function Form({
<button class="btn btn--primary" type="submit">
{submitButtonLabel}
</button>
<button class="btn btn--default" type="button" onClick={onFormClose}>
<button class="btn btn--default" type="button" onClick={() => onFormClose({ reason: 'form-cancelled' })}>
{cancelButtonLabel}
</button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/feedback/src/modal/integration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => {
showEmail={options.showEmail || options.isEmailRequired}
defaultName={(userKey && user && user[userKey.name]) || ''}
defaultEmail={(userKey && user && user[userKey.email]) || ''}
onFormClose={() => {
onFormClose={({ reason }) => {
renderContent(false);
options.onFormClose && options.onFormClose();
options.onFormClose && options.onFormClose({ reason });
}}
onSubmit={sendFeedback}
onSubmitSuccess={(data: FeedbackFormData) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/feedback/src/screenshot/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const feedbackScreenshotIntegration = ((): FeedbackScreenshotIntegration
const attachment: Attachment = {
data,
filename: 'screenshot.png',
contentType: 'application/png',
// contentType: 'application/png',
// attachmentType?: string;
};
return attachment;
Expand Down
6 changes: 3 additions & 3 deletions packages/feedback/src/util/mergeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export function mergeOptions(
optionOverrides.onFormOpen && optionOverrides.onFormOpen();
defaultOptions.onFormOpen && defaultOptions.onFormOpen();
},
onFormClose: () => {
optionOverrides.onFormClose && optionOverrides.onFormClose();
defaultOptions.onFormClose && defaultOptions.onFormClose();
onFormClose: (...args) => {
optionOverrides.onFormClose && optionOverrides.onFormClose(...args);
defaultOptions.onFormClose && defaultOptions.onFormClose(...args);
},
onSubmitSuccess: (data: FeedbackFormData) => {
optionOverrides.onSubmitSuccess && optionOverrides.onSubmitSuccess(data);
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-shims/src/Feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Integration } from '@sentry/types';
import { consoleSandbox } from '@sentry/utils';
import { FAKE_FUNCTION } from './common';

const FEEDBACK_INTEGRATION_METHODS = ['attachTo', 'createWidget', 'remove'] as const;
const FEEDBACK_INTEGRATION_METHODS = ['attachTo', 'createForm', 'createWidget', 'remove'] as const;

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

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/feedback/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export interface FeedbackCallbacks {
/**
* Callback when form is closed and not submitted
*/
onFormClose?: () => void;
onFormClose?: (args: { reason: 'dialog-dismissed' | 'form-cancelled' }) => void;

/**
* Callback when feedback is successfully submitted
Expand Down

0 comments on commit d916488

Please sign in to comment.