-
Notifications
You must be signed in to change notification settings - Fork 1k
fix[angular-gen2]: Better error handling on form submissions #4031
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
fix[angular-gen2]: Better error handling on form submissions #4031
Conversation
🦋 Changeset detectedLatest commit: 92a354e The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
View your CI Pipeline Execution ↗ for commit 7e08c64.
☁️ Nx Cloud last updated this comment at |
if ( | ||
props.sendSubmissionsTo === 'email' && | ||
(props.sendSubmissionsToEmail === 'your@email.com' || | ||
props.sendSubmissionsToEmail === '') |
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 if sendSubmissionsToEmail is null or undefined
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.
Handled it now
state.responseData = body; | ||
state.formState = 'error'; | ||
|
||
let message = props.errorMessagePath |
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.
Can we create a small function to get the message?
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.
This code is not repeated anywhere, why do we need a function.
@anaghav2023 Would it be possible to write a test for this? |
if ( | ||
props.sendSubmissionsTo === 'email' && | ||
(props.sendSubmissionsToEmail === 'your@email.com' || | ||
props.sendSubmissionsToEmail === '') |
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.
props.sendSubmissionsToEmail === '') | |
!props.sendSubmissionsToEmail) |
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.
pushed changes
if ( | ||
props.sendSubmissionsTo === 'email' && | ||
(props.sendSubmissionsToEmail === 'your@email.com' || | ||
props.sendSubmissionsToEmail === '') |
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.
Asking out of curiosity
Are we also responsible to validate if emails are temp emails or an actual email?
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.
No, we are not doing that here. The API will send error response
@@ -187,6 +187,21 @@ export default function FormComponent(props: FormProps) { | |||
|
|||
state.formState = 'sending'; | |||
|
|||
if ( | |||
props.sendSubmissionsTo === 'email' && | |||
(props.sendSubmissionsToEmail === 'your@email.com' || |
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.
(props.sendSubmissionsToEmail === 'your@email.com' || | |
const isInvalidEmailConfig = () => | |
props.sendSubmissionsTo === 'email' && | |
(!props.sendSubmissionsToEmail || props.sendSubmissionsToEmail === 'your@email.com'); |
we can create a function which can validate input emails
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.
@yash-builder This is actually not the email which comes from the form input. This is the email that users set when creating the form. Since this code is not repeating, I'll let it be
@clyde-builderio I added a test to check the console errors |
test.skip( | ||
excludeTestFor({ reactNative: true, rsc: true }, sdk), | ||
'Form not implemented in React Native and NextJS SDKs.' | ||
); |
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.
instead of the current test.skip()
try
test.skip(sdk !== 'angular'));
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.
is your change only for angular?
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.
@clyde-builderio this change is to address issue in angular SDK. But I think the form.lite.tsx
is common for all sdks and I want it to work everywhere.
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.
Then instead of test.skip(sdk !== 'angular');
we can do
test.skip(excludeGen1(sdk));
this will make sure the Gen 1 React SDK tests get skipped
I'll check if there is way to make sure the other Gen 2 tests do not fail
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.
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.
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.
For the qwik-city failure....looks like a flaky test. Maybe re-running the GitHub check should resolve it
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.
@clyde-builderio Thanks. Thats right for solid sdks somehow the error doesn't get printed on console but shows up on screen. I have updated the test to handle that separately for the solid SDK
@anaghav2023 Tried using Cursors AI to figure why it's not working The below test is passing...don't see a major difference except the test.only('form submission', async ({ page, sdk }) => {
test.skip(
excludeTestFor({ reactNative: true, rsc: true }, sdk),
'Form not implemented in React Native and NextJS SDKs.'
);
test.skip(excludeGen1(sdk));
// Create console listener before clicking submit
const consoleMessages: string[] = [];
page.on('console', async msg => {
// Get all args and convert them to strings
const args = await Promise.all(msg.args().map(arg => arg.jsonValue()));
const messageText = args.join(' ');
consoleMessages.push(messageText);
});
await page.goto('/form');
const form = page.locator('form');
await expect(form).toHaveCount(1);
const inputs = await form.locator('input').all();
await inputs[0].fill('Test Name');
await inputs[1].fill('test@example.com');
await page.locator('select').selectOption('20-30');
await page.locator('textarea').fill('Test message');
// Submit the form
await form.locator('button').click();
// Wait for any console messages to be processed
await page.waitForTimeout(100);
// Verify error message was logged
if (sdk === 'solid') {
await expect(page.locator('.builder-text').nth(3)).toHaveText(
'SubmissionsToEmail is required when sendSubmissionsTo is set to email'
);
} else {
expect(
consoleMessages.some(msg =>
msg.includes('SubmissionsToEmail is required when sendSubmissionsTo is set to email')
)
).toBeTruthy();
}
}); |
.changeset/orange-items-notice.md
Outdated
"@builder.io/sdk": patch | ||
"@builder.io/react": patch |
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.
These are Gen 1 SDKs. They can be removed from this file
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.
Removed them
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.
@sidmohanty11 just wanted to confirm with you if a patch update is okay for this change
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.
yup should be good!
Co-authored-by: Yash Wadhia <188822535+yash-builder@users.noreply.github.com>
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.
LGTM
Description
Form submissions are causing a lot of errors if the the API fails.
https://www.loom.com/share/6da637e8902b4a76855c45b2a3cb9e5f?sid=220b852b-6fe9-4a8e-a68c-d12672750bf3
Jira:
https://builder-io.atlassian.net/browse/ENG-8731
Loom showing the fix
https://www.loom.com/share/296e9205f60a44a9815b44cae5c08dbe