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
|
### Writing a Centralized Validator
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
// packages/ui/src/validators/base.validator.ts
|
// packages/ui/src/validators/sample.validator.ts
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
export const baseValidator = z.object({
|
export const sampleValidator = z.object({
|
||||||
email: z.string().email({
|
email: z.string().email({
|
||||||
message: JSON.stringify({ key: 'validation:invalid_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
|
### 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 { useForm, type SubmitHandler } from 'react-hook-form';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { FieldTextInput } from '@repo/ui/form';
|
import { FieldTextInput } from '@repo/ui/form';
|
||||||
import { baseValidator, type BaseValidatorType } from '@repo/ui/validators';
|
import { sampleValidator, type SampleValidatorType } from '@repo/ui/validators';
|
||||||
|
|
||||||
function ExampleForm() {
|
function ExampleForm() {
|
||||||
const { control, handleSubmit } = useForm<BaseValidatorType>({
|
const { control, handleSubmit } = useForm<SampleValidatorType>({
|
||||||
resolver: zodResolver(baseValidator),
|
resolver: zodResolver(sampleValidator),
|
||||||
defaultValues: { email: '', name: '' },
|
defaultValues: { email: '', name: '' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSubmit: SubmitHandler<BaseValidatorType> = (data) => console.log(data);
|
const onSubmit: SubmitHandler<SampleValidatorType> = (data) => console.log(data);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export * from './base.validator';
|
export * from './sample.validator';
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
export const baseValidator = z.object({
|
export const sampleValidator = z.object({
|
||||||
email: z.string().email({
|
email: z.string().email({
|
||||||
message: JSON.stringify({ key: 'validation:invalid_email' }),
|
message: JSON.stringify({ key: 'validation:invalid_email' }),
|
||||||
}),
|
}),
|
||||||
@@ -12,4 +12,4 @@ export const baseValidator = z.object({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type BaseValidatorType = z.infer<typeof baseValidator>;
|
export type SampleValidatorType = z.infer<typeof sampleValidator>;
|
||||||
Reference in New Issue
Block a user