Skip to content

feat(feedback): Disable Feedback submit & cancel buttons while submitting #15408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/feedback/src/modal/components/Dialog.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ const FORM = `
flex: 1 0;
}

.form fieldset {
border: none;
margin: 0;
padding: 0;
}

.form__right {
flex: 0 0 auto;
display: flex;
Expand Down
15 changes: 9 additions & 6 deletions packages/feedback/src/modal/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function Form({
submitButtonLabel,
isRequiredLabel,
} = options;
const [isSubmitting, setIsSubmitting] = useState<boolean>(false);
// TODO: set a ref on the form, and whenever an input changes call processForm() and setError()
const [error, setError] = useState<null | string>(null);

Expand Down Expand Up @@ -97,6 +98,7 @@ export function Form({

const handleSubmit = useCallback(
async (e: JSX.TargetedSubmitEvent<HTMLFormElement>) => {
setIsSubmitting(true);
try {
e.preventDefault();
if (!(e.target instanceof HTMLFormElement)) {
Expand Down Expand Up @@ -133,8 +135,8 @@ export function Form({
setError(error as string);
onSubmitError(error as Error);
}
} catch {
// pass
} finally {
setIsSubmitting(false);
}
},
[screenshotInput && showScreenshotInput, onSubmitSuccess, onSubmitError],
Expand All @@ -146,7 +148,7 @@ export function Form({
<ScreenshotInputComponent onError={onScreenshotError} />
) : null}

<div class="form__right" data-sentry-feedback={true}>
<fieldset class="form__right" data-sentry-feedback={true} disabled={isSubmitting}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does fieldset do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a container for form controls. it's got some default padding&margin and a border too.

the reason that i brought it in is because it supports disabled which will prevent the text boxes from accepting input.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/fieldset#attributes

It's not applying to our <button> inside the form tho, so i had to do those manually. I suspect, but didn't test, that it would automatically disable <input type="button"> or ` if we were using those instead. But i don't wanna change it all over.

<div class="form__top">
{error ? <div class="form__error-container">{error}</div> : null}

Expand Down Expand Up @@ -201,6 +203,7 @@ export function Form({
<label for="screenshot" class="form__label">
<button
class="btn btn--default"
disabled={isSubmitting}
type="button"
onClick={() => {
setScreenshotError(null);
Expand All @@ -214,14 +217,14 @@ export function Form({
) : null}
</div>
<div class="btn-group">
<button class="btn btn--primary" type="submit">
<button class="btn btn--primary" disabled={isSubmitting} type="submit">
{submitButtonLabel}
</button>
<button class="btn btn--default" type="button" onClick={onFormClose}>
<button class="btn btn--default" disabled={isSubmitting} type="button" onClick={onFormClose}>
{cancelButtonLabel}
</button>
</div>
</div>
</fieldset>
</form>
);
}
Expand Down
Loading