Skip to content
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

[launch week] Add submission form on the UI #3491

Closed
wants to merge 1 commit into from

Conversation

drguthals
Copy link
Collaborator

This PR adds a form that validates user input.

@drguthals
Copy link
Collaborator Author

@codecov-ai-reviewer review

Copy link

codecov bot commented Nov 13, 2024

❌ We are unable to process any of the uploaded JUnit XML files. Please ensure your files are in the right format.

2 similar comments
@codecov-staging
Copy link

❌ We are unable to process any of the uploaded JUnit XML files. Please ensure your files are in the right format.

@codecov-qa
Copy link

codecov-qa bot commented Nov 13, 2024

❌ We are unable to process any of the uploaded JUnit XML files. Please ensure your files are in the right format.

Comment on lines +7 to +28
const handleSubmit = (event: Event): void => {
event.preventDefault()

const form = event.target as HTMLFormElement
const formData: CustomFormData = {
name: (form.elements.namedItem('name') as HTMLInputElement).value,
email: (form.elements.namedItem('email') as HTMLInputElement).value,
phoneNumber: (form.elements.namedItem('phone') as HTMLInputElement).value,
}

const errors = validateFormData(formData)

if (errors.length > 0) {
displayErrors(errors)
} else {
submitForm(formData)
displaySuccessMessage('Form submitted successfully!')
}
} catch (error) {
displayErrorMessage('Failed to submit the form.')
}
}
Copy link

Choose a reason for hiding this comment

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

The handleSubmit function should be wrapped in a try-catch block to handle any unexpected errors during form submission.

Suggested change
const handleSubmit = (event: Event): void => {
event.preventDefault()
const form = event.target as HTMLFormElement
const formData: CustomFormData = {
name: (form.elements.namedItem('name') as HTMLInputElement).value,
email: (form.elements.namedItem('email') as HTMLInputElement).value,
phoneNumber: (form.elements.namedItem('phone') as HTMLInputElement).value,
}
const errors = validateFormData(formData)
if (errors.length > 0) {
displayErrors(errors)
} else {
submitForm(formData)
displaySuccessMessage('Form submitted successfully!')
}
} catch (error) {
displayErrorMessage('Failed to submit the form.')
}
}
dHJ5IHsKICAgIGV2ZW50LnByZXZlbnREZWZhdWx0KCk7CgogICAgY29uc3QgZm9ybSA9IGV2ZW50LnRhcmdldCBhcyBIVE1MRm9ybUVsZW1lbnQ7CiAgICBjb25zdCBmb3JtRGF0YTogQ3VzdG9tRm9ybURhdGEgPSB7CiAgICAgIG5hbWU6IChmb3JtLmVsZW1lbnRzLm5hbWVkSXRlbSgnbmFtZScpIGFzIEhUTUxJbnB1dEVsZW1lbnQpLnZhbHVlLAogICAgICBlbWFpbDogKGZvcm0uZWxlbWVudHMubmFtZWRJdGVtKCdlbWFpbCcpIGFzIEhUTUxJbnB1dEVsZW1lbnQpLnZhbHVlLAogICAgICBwaG9uZU51bWJlcjogKGZvcm0uZWxlbWVudHMubmFtZWRJdGVtKCdwaG9uZScpIGFzIEhUTUxJbnB1dEVsZW1lbnQpLnZhbHVlLAogICAgfTsKCiAgICBjb25zdCBlcnJvcnMgPSB2YWxpZGF0ZUZvcm1EYXRhKGZvcm1EYXRhKTsKCiAgICBpZiAoZXJyb3JzLmxlbmd0aCA+IDApIHsKICAgICAgZGlzcGxheUVycm9ycyhlcnJvcnMpOwogICAgfSBlbHNlIHsKICAgICAgc3VibWl0Rm9ybShmb3JtRGF0YSk7CiAgICAgIGRpc3BsYXlTdWNjZXNzTWVzc2FnZSgnRm9ybSBzdWJtaXR0ZWQgc3VjY2Vzc2Z1bGx5IScpOwogICAgfQogIH0gY2F0Y2ggKGVycm9yKSB7CiAgICBkaXNwbGF5RXJyb3JNZXNzYWdlKCdGYWlsZWQgdG8gc3VibWl0IHRoZSBmb3JtLicpOwogIH0KfTs=

console.error(message)
}

const form = document.querySelector('form')
Copy link

Choose a reason for hiding this comment

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

Instead of querying the form element directly in the global scope, consider using a React ref to manage the form element. This approach is more in line with React best practices.

@drguthals drguthals closed this Nov 14, 2024
@drguthals drguthals deleted the add-submission-form branch November 15, 2024 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant