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

[WIP] Upgrade conform version #2

Merged
merged 8 commits into from
Jul 20, 2023

Conversation

edmundhung
Copy link
Contributor

Resolve #1

Copy link
Contributor Author

@edmundhung edmundhung left a comment

Choose a reason for hiding this comment

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

I will double check all the changes tomorrow and ping you when it is ready :)

Comment on lines 18 to 21
email: z.string({ required_error: 'Email is required' }).email('Email is invalid'),
password: z.string({ required_error: 'Password is required' }),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Conform now strips empty string to undefined to utilize zod required validation and there is no need to set min(1) anymore. Should I apply the same change to the NoteEditorSchema?

// Instead of this
const NoteEditorSchema = z.object({
	title: z.string().min(titleMinLength).max(titleMaxLength),
	content: z.string().min(contentMinLength).max(contentMaxLength),
})

// Change it to this?
const NoteEditorSchema = z.object({
	title: z.string().max(titleMaxLength),
	content: z.string().max(contentMaxLength),
})

Copy link
Member

Choose a reason for hiding this comment

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

Yes please!

@@ -14,7 +14,7 @@
"content": ""
},
"error": {
"content": "String must contain at least 1 character(s)"
"content": "Required"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because Conform is utilizing the zod required check now.

@@ -200,7 +200,7 @@ function ImageChooser({
const [altText, setAltText] = useState(fields.altText.defaultValue ?? '')

return (
<fieldset ref={ref}>
<fieldset ref={ref} {...conform.fieldset(config)}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was it intentional to omit the aria attributes?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, just because I didn't want it to distract from things. It's great that those are added automatically now so we don't need to worry about it. This change is perfect 👍

@edmundhung
Copy link
Contributor Author

We might need to update the README on exercise 4 as well. Since Conform does type coercion now, there is no need to check if the file is empty.

// Before
const schema = z.object({
    profile: z
        .instanceof(File)
        // When browser constructs a form data from an empty file input, a default file
        // entry would be created. we can validate this by checking the filename and size.
        .refine(file => file.name !== '' && file.size !== 0, 'Profile is required'),
})

// Now
const schema = z.object({
    profile: z.instanceof(File, { message: 'Profile is required' }),
});

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

This looks awesome to me! Thank you so much for getting these changes implemented, published, and making this PR!

Comment on lines 18 to 21
email: z.string({ required_error: 'Email is required' }).email('Email is invalid'),
password: z.string({ required_error: 'Password is required' }),
Copy link
Member

Choose a reason for hiding this comment

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

Yes please!

@@ -200,7 +200,7 @@ function ImageChooser({
const [altText, setAltText] = useState(fields.altText.defaultValue ?? '')

return (
<fieldset ref={ref}>
<fieldset ref={ref} {...conform.fieldset(config)}>
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, just because I didn't want it to distract from things. It's great that those are added automatically now so we don't need to worry about it. This change is perfect 👍

@kentcdodds
Copy link
Member

We might need to update the README on exercise 4 as well

That's awesome. Yes, let's make that update too 👍 Thanks!

@edmundhung edmundhung force-pushed the upgrade-conform branch 2 times, most recently from 9563042 to ffa2e43 Compare July 20, 2023 23:01
@edmundhung edmundhung marked this pull request as ready for review July 20, 2023 23:06
@edmundhung
Copy link
Contributor Author

This is ready @kentcdodds! The changes are huge so it might be easier to check the commit one by one. Please be aware that the impact for removing the min check is huge, let me know if you want to revert it :)

@edmundhung
Copy link
Contributor Author

edmundhung commented Jul 20, 2023

Also, I kept this message in the file as the new report helper isn't helpful for the way you are using it still 😅

@kentcdodds
Copy link
Member

@edmundhung, thank you so much for doing this. It's an enormous help at a time where I'm really pressed for time getting all these workshops prepared. I really appreciate it!

Also, I kept this message in the file as the new report helper isn't helpful for the way you are using it still 😅

The diff is so big that it's not auto-focusing that, I don't know what message you're talking about. But I'll review everything post-merge 👍 Thanks a ton!

@kentcdodds kentcdodds merged commit 7110162 into epicweb-dev:main Jul 20, 2023
4 checks passed
@edmundhung edmundhung deleted the upgrade-conform branch July 20, 2023 23:34
@edmundhung
Copy link
Contributor Author

Happy to help anytime! 🤓

The diff is so big that it's not auto-focusing that, I don't know what message you're talking about. But I'll review everything post-merge +1 Thanks a ton!

I meant this message.

@kentcdodds
Copy link
Member

Ah, gotcha. Yeah, that's fine :) Thanks!

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.

Upgrade to conform 0.8.0-pre.0
2 participants