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

dev: Remove yup and convert to zod #3060

Merged
merged 1 commit into from
Jul 26, 2024
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
"semver": "7.5.2",
"tailwind-merge": "^2.3.0",
"victory": "^37.0.2",
"yup": "^0.32.11",
"zod": "^3.21.4"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { yupResolver } from '@hookform/resolvers/yup'
import { zodResolver } from '@hookform/resolvers/zod'
import PropTypes from 'prop-types'
import { useForm } from 'react-hook-form'
import * as yup from 'yup'
import { z } from 'zod'

import Card from 'old_ui/Card'
import { useAddNotification } from 'services/toastNotification'
Expand All @@ -10,19 +10,19 @@ import Button from 'ui/Button'
import TextInput from 'ui/TextInput'

function getSchema() {
return yup.object().shape({
name: yup.string().required('Name is required'),
email: yup
return z.object({
name: z.string().min(1, { message: 'Name is required' }),
email: z
.string()
.email('Not a valid email')
.required('Email is required'),
.min(1, { message: 'Email is required' }),
})
}

function NameEmailCard({ currentUser, provider }) {
const addToast = useAddNotification()
const { register, handleSubmit, formState, reset } = useForm({
resolver: yupResolver(getSchema()),
resolver: zodResolver(getSchema()),
defaultValues: {
email: currentUser?.email,
name: currentUser?.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ describe('NameEmailCard', () => {
})
await user.click(button)

const emailRequired = await screen.findByText('Email is required')
expect(emailRequired).toBeInTheDocument()
const notValidEmail = await screen.findByText('Not a valid email')
expect(notValidEmail).toBeInTheDocument()
})
})

Expand Down
48 changes: 2 additions & 46 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/runtime@npm:^7.1.2, @babel/runtime@npm:^7.11.2, @babel/runtime@npm:^7.12.13, @babel/runtime@npm:^7.12.5, @babel/runtime@npm:^7.13.10, @babel/runtime@npm:^7.14.8, @babel/runtime@npm:^7.15.4, @babel/runtime@npm:^7.16.3, @babel/runtime@npm:^7.17.8, @babel/runtime@npm:^7.21.0, @babel/runtime@npm:^7.7.6, @babel/runtime@npm:^7.8.4, @babel/runtime@npm:^7.9.2":
"@babel/runtime@npm:^7.1.2, @babel/runtime@npm:^7.11.2, @babel/runtime@npm:^7.12.13, @babel/runtime@npm:^7.12.5, @babel/runtime@npm:^7.13.10, @babel/runtime@npm:^7.14.8, @babel/runtime@npm:^7.16.3, @babel/runtime@npm:^7.17.8, @babel/runtime@npm:^7.21.0, @babel/runtime@npm:^7.7.6, @babel/runtime@npm:^7.8.4, @babel/runtime@npm:^7.9.2":
version: 7.24.8
resolution: "@babel/runtime@npm:7.24.8"
dependencies:
Expand Down Expand Up @@ -6406,7 +6406,7 @@ __metadata:
languageName: node
linkType: hard

"@types/lodash@npm:4.17.6, @types/lodash@npm:^4.14.167, @types/lodash@npm:^4.14.175":
"@types/lodash@npm:4.17.6, @types/lodash@npm:^4.14.167":
version: 4.17.6
resolution: "@types/lodash@npm:4.17.6"
checksum: 10c0/3b197ac47af9443fee8c4719c5ffde527d7febc018b827d44a6bc2523c728c7adfdd25196fdcfe3eed827993e0c41a917d0da6e78938b18b2be94164789f1117
Expand Down Expand Up @@ -11819,7 +11819,6 @@ __metadata:
victory: "npm:^37.0.2"
webpack: "npm:^5.84.1"
webpackbar: "npm:^6.0.1"
yup: "npm:^0.32.11"
zod: "npm:^3.21.4"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -14579,13 +14578,6 @@ __metadata:
languageName: node
linkType: hard

"lodash-es@npm:^4.17.21":
version: 4.17.21
resolution: "lodash-es@npm:4.17.21"
checksum: 10c0/fb407355f7e6cd523a9383e76e6b455321f0f153a6c9625e21a8827d10c54c2a2341bd2ae8d034358b60e07325e1330c14c224ff582d04612a46a4f0479ff2f2
languageName: node
linkType: hard

"lodash.camelcase@npm:^4.3.0":
version: 4.3.0
resolution: "lodash.camelcase@npm:4.3.0"
Expand Down Expand Up @@ -15849,13 +15841,6 @@ __metadata:
languageName: node
linkType: hard

"nanoclone@npm:^0.2.1":
version: 0.2.1
resolution: "nanoclone@npm:0.2.1"
checksum: 10c0/760b569ea841c9678fdf8d763c6d7bb093f0889150087f82d86c536a318b302939c82ce35cdaec999d0f687789d0d79d0f3f75a272d7a98dfac7a067c0b47053
languageName: node
linkType: hard

"nanoid@npm:^3.3.7":
version: 3.3.7
resolution: "nanoid@npm:3.3.7"
Expand Down Expand Up @@ -17769,13 +17754,6 @@ __metadata:
languageName: node
linkType: hard

"property-expr@npm:^2.0.4":
version: 2.0.6
resolution: "property-expr@npm:2.0.6"
checksum: 10c0/69b7da15038a1146d6447c69c445306f66a33c425271235bb20507f1846dbf9577a8f9dfafe8acbfcb66f924b270157f155248308f026a68758f35fc72265b3c
languageName: node
linkType: hard

"proxy-addr@npm:~2.0.7":
version: 2.0.7
resolution: "proxy-addr@npm:2.0.7"
Expand Down Expand Up @@ -20600,13 +20578,6 @@ __metadata:
languageName: node
linkType: hard

"toposort@npm:^2.0.2":
version: 2.0.2
resolution: "toposort@npm:2.0.2"
checksum: 10c0/ab9ca91fce4b972ccae9e2f539d755bf799a0c7eb60da07fd985fce0f14c159ed1e92305ff55697693b5bc13e300f5417db90e2593b127d421c9f6c440950222
languageName: node
linkType: hard

"tough-cookie@npm:^4.0.0":
version: 4.1.4
resolution: "tough-cookie@npm:4.1.4"
Expand Down Expand Up @@ -22861,21 +22832,6 @@ __metadata:
languageName: node
linkType: hard

"yup@npm:^0.32.11":
version: 0.32.11
resolution: "yup@npm:0.32.11"
dependencies:
"@babel/runtime": "npm:^7.15.4"
"@types/lodash": "npm:^4.14.175"
lodash: "npm:^4.17.21"
lodash-es: "npm:^4.17.21"
nanoclone: "npm:^0.2.1"
property-expr: "npm:^2.0.4"
toposort: "npm:^2.0.2"
checksum: 10c0/f0802798dc64b49f313886b983a9bea5f283e2094ee2aa1197587b84f50ac5b5d03af99857c313139e63dc02558fac3aaa343503bdbffa96f70006b39d1f59c9
languageName: node
linkType: hard

"zod@npm:^3.21.4, zod@npm:^3.22.4":
version: 3.23.8
resolution: "zod@npm:3.23.8"
Expand Down
Loading