Skip to content

Commit 50f89f1

Browse files
authored
feat(feedback): Disable Feedback submit & cancel buttons while submitting (#15408)
While submitting feedback the Submit and Cancel buttons previously remained active. So you could smash that submit many times and submit many duplicate feedbacks. This disabled the buttons while the network request is being fired off. The disabled buttons are slightly grayed out by the browser. So it depends on what custom color you've picked: ![SCR-20250213-kmpm](https://github.com/user-attachments/assets/883d4098-3f7f-4167-9506-4ff84b4e7e25)
1 parent b433821 commit 50f89f1

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

packages/feedback/src/modal/components/Dialog.css.ts

+6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ const FORM = `
115115
flex: 1 0;
116116
}
117117
118+
.form fieldset {
119+
border: none;
120+
margin: 0;
121+
padding: 0;
122+
}
123+
118124
.form__right {
119125
flex: 0 0 auto;
120126
display: flex;

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export function Form({
6161
submitButtonLabel,
6262
isRequiredLabel,
6363
} = options;
64+
const [isSubmitting, setIsSubmitting] = useState<boolean>(false);
6465
// TODO: set a ref on the form, and whenever an input changes call processForm() and setError()
6566
const [error, setError] = useState<null | string>(null);
6667

@@ -97,6 +98,7 @@ export function Form({
9798

9899
const handleSubmit = useCallback(
99100
async (e: JSX.TargetedSubmitEvent<HTMLFormElement>) => {
101+
setIsSubmitting(true);
100102
try {
101103
e.preventDefault();
102104
if (!(e.target instanceof HTMLFormElement)) {
@@ -133,8 +135,8 @@ export function Form({
133135
setError(error as string);
134136
onSubmitError(error as Error);
135137
}
136-
} catch {
137-
// pass
138+
} finally {
139+
setIsSubmitting(false);
138140
}
139141
},
140142
[screenshotInput && showScreenshotInput, onSubmitSuccess, onSubmitError],
@@ -146,7 +148,7 @@ export function Form({
146148
<ScreenshotInputComponent onError={onScreenshotError} />
147149
) : null}
148150

149-
<div class="form__right" data-sentry-feedback={true}>
151+
<fieldset class="form__right" data-sentry-feedback={true} disabled={isSubmitting}>
150152
<div class="form__top">
151153
{error ? <div class="form__error-container">{error}</div> : null}
152154

@@ -201,6 +203,7 @@ export function Form({
201203
<label for="screenshot" class="form__label">
202204
<button
203205
class="btn btn--default"
206+
disabled={isSubmitting}
204207
type="button"
205208
onClick={() => {
206209
setScreenshotError(null);
@@ -214,14 +217,14 @@ export function Form({
214217
) : null}
215218
</div>
216219
<div class="btn-group">
217-
<button class="btn btn--primary" type="submit">
220+
<button class="btn btn--primary" disabled={isSubmitting} type="submit">
218221
{submitButtonLabel}
219222
</button>
220-
<button class="btn btn--default" type="button" onClick={onFormClose}>
223+
<button class="btn btn--default" disabled={isSubmitting} type="button" onClick={onFormClose}>
221224
{cancelButtonLabel}
222225
</button>
223226
</div>
224-
</div>
227+
</fieldset>
225228
</form>
226229
);
227230
}

0 commit comments

Comments
 (0)