feat: Validate newsfeed post and comment with zod (#221)
* added Zod validation to the newsfeed post and comment * updated the error message
This commit is contained in:
@@ -4,9 +4,13 @@ import { validateEmail } from './validateEmail';
|
||||
|
||||
const getOrgNameValidation = () =>
|
||||
z.string().min(5, { message: 'Organization must contain 5 or more characters' });
|
||||
|
||||
const getSiteNameValidation = () =>
|
||||
z.string().min(5, { message: 'Site name must contain 5 or more characters' });
|
||||
|
||||
const getNewsfeedValidation = () =>
|
||||
z.string().min(5, { message: 'Field must contain 5 or more characters' });
|
||||
|
||||
const createQuizValidationSchema = z.object({
|
||||
title: z.string().min(6, {
|
||||
message: 'Must be 6 or more characters long',
|
||||
@@ -199,6 +203,24 @@ export const onboardingValidation = (fields = {}, step) => {
|
||||
// return processErrors(error);
|
||||
// };
|
||||
|
||||
export const createNewsfeedValidation = (newPost) => {
|
||||
const schema = z.object({
|
||||
newPost: getNewsfeedValidation()
|
||||
});
|
||||
const { error } = schema.safeParse({ newPost });
|
||||
|
||||
return processErrors(error);
|
||||
};
|
||||
|
||||
export const addNewsfeedCommentValidation = (newComment) => {
|
||||
const schema = z.object({
|
||||
newComment: getNewsfeedValidation()
|
||||
});
|
||||
const { error } = schema.safeParse({ newComment });
|
||||
|
||||
return processErrors(error);
|
||||
};
|
||||
|
||||
export const createOrgValidation = (fields = {}) => {
|
||||
const schema = z.object({
|
||||
orgName: getOrgNameValidation(),
|
||||
|
||||
Reference in New Issue
Block a user