Sync with Server

This commit is contained in:
rotimi-best
2021-08-18 19:47:02 +03:00
parent e8c74de9ce
commit 60f06d6ab1
77 changed files with 2989 additions and 7610 deletions
+67
View File
@@ -0,0 +1,67 @@
import { validateEmail } from '../../utils/functions/validateEmail';
export function validateForm(fields) {
let hasError = false;
const { students = '', tutors = '', title, description } = fields;
const fieldErrors = {
tutors: '',
students: '',
title: '',
description: '',
};
const _tutors =
tutors.length < 5
? []
: tutors.split(',').map((_email) => {
const email = _email.trim();
if (!validateEmail(email)) {
hasError = true;
fieldErrors.tutors += !fieldErrors.tutors.length
? `Not valid email: ${email}`
: `, ${email}`;
}
return email;
});
const _students =
students.length < 5
? []
: students.split(',').map((_email) => {
const email = _email.trim();
if (!validateEmail(email)) {
hasError = true;
fieldErrors.students += !fieldErrors.students.length
? `Not valid email: ${email}`
: `, ${email}`;
}
return email;
});
if (!title) {
fieldErrors.title = 'Title is required';
return {
hasError: true,
fieldErrors,
};
}
if (!description) {
fieldErrors.description = 'Description is required';
return {
hasError: true,
fieldErrors,
};
}
return {
hasError,
fieldErrors,
tutors: _tutors,
students: _students,
};
}