-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,12 @@ function retrieveStringValue(formData: FormData, key: string): string { | |
return ''; | ||
} | ||
|
||
function waitForSec(seconds: number): Promise<void> { | ||
return new Promise(resolve => { | ||
setTimeout(resolve, seconds * 1000); | ||
}); | ||
} | ||
|
||
export function Form({ | ||
options, | ||
defaultEmail, | ||
|
@@ -61,6 +67,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); | ||
|
||
|
@@ -97,6 +104,7 @@ export function Form({ | |
|
||
const handleSubmit = useCallback( | ||
async (e: JSX.TargetedSubmitEvent<HTMLFormElement>) => { | ||
setIsSubmitting(true); | ||
try { | ||
e.preventDefault(); | ||
if (!(e.target instanceof HTMLFormElement)) { | ||
|
@@ -112,6 +120,8 @@ export function Form({ | |
attachments: attachment ? [attachment] : undefined, | ||
}; | ||
|
||
await waitForSec(5); | ||
|
||
if (!hasAllRequiredFields(data)) { | ||
return; | ||
} | ||
|
@@ -133,8 +143,8 @@ export function Form({ | |
setError(error as string); | ||
onSubmitError(error as Error); | ||
} | ||
} catch { | ||
// pass | ||
} finally { | ||
setIsSubmitting(false); | ||
} | ||
}, | ||
[screenshotInput && showScreenshotInput, onSubmitSuccess, onSubmitError], | ||
|
@@ -146,7 +156,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}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does fieldset do? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 It's not applying to our |
||
<div class="form__top"> | ||
{error ? <div class="form__error-container">{error}</div> : null} | ||
|
||
|
@@ -201,6 +211,7 @@ export function Form({ | |
<label for="screenshot" class="form__label"> | ||
<button | ||
class="btn btn--default" | ||
disabled={isSubmitting} | ||
type="button" | ||
onClick={() => { | ||
setScreenshotError(null); | ||
|
@@ -214,14 +225,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> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d'oh
for testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
speedup loop