refactor: rename base validator to sample validator in source and documentation
This commit is contained in:
@@ -258,10 +258,10 @@ To prevent over-engineering and package fatigue, we house the validation layer d
|
||||
### Writing a Centralized Validator
|
||||
|
||||
```tsx
|
||||
// packages/ui/src/validators/base.validator.ts
|
||||
// packages/ui/src/validators/sample.validator.ts
|
||||
import { z } from 'zod';
|
||||
|
||||
export const baseValidator = z.object({
|
||||
export const sampleValidator = z.object({
|
||||
email: z.string().email({
|
||||
message: JSON.stringify({ key: 'validation:invalid_email' }),
|
||||
}),
|
||||
@@ -273,7 +273,7 @@ export const baseValidator = z.object({
|
||||
}),
|
||||
});
|
||||
|
||||
export type BaseValidatorType = z.infer<typeof baseValidator>;
|
||||
export type SampleValidatorType = z.infer<typeof sampleValidator>;
|
||||
```
|
||||
|
||||
### Applying the Validator
|
||||
@@ -284,15 +284,15 @@ When consuming these validators, use the `zodResolver` exported from `@repo/ui/f
|
||||
import { useForm, type SubmitHandler } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { FieldTextInput } from '@repo/ui/form';
|
||||
import { baseValidator, type BaseValidatorType } from '@repo/ui/validators';
|
||||
import { sampleValidator, type SampleValidatorType } from '@repo/ui/validators';
|
||||
|
||||
function ExampleForm() {
|
||||
const { control, handleSubmit } = useForm<BaseValidatorType>({
|
||||
resolver: zodResolver(baseValidator),
|
||||
const { control, handleSubmit } = useForm<SampleValidatorType>({
|
||||
resolver: zodResolver(sampleValidator),
|
||||
defaultValues: { email: '', name: '' },
|
||||
});
|
||||
|
||||
const onSubmit: SubmitHandler<BaseValidatorType> = (data) => console.log(data);
|
||||
const onSubmit: SubmitHandler<SampleValidatorType> = (data) => console.log(data);
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
|
||||
Reference in New Issue
Block a user