Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 5x 5x 5x 5x 5x 5x | import { object, string, array, ref } from 'yup';
/**
* HABIT
*/
const habit = {
name: string().required('Title is required.'),
description: string().notRequired(),
frequency: array().required('You have to select at least one day.'),
};
// Habit schema
const habitSchema = object().shape({
name: habit.name,
description: habit.description,
frequency: habit.frequency,
});
/**
* USER
*/
const user = {
email: string()
.email('Email address is invalid')
.required('Email address is required.'),
password: string()
.min(6, 'Password must be at least 6 characters.')
.required('You have to enter the password.'),
passwordConfirmation: string()
.min(6, 'Password must be at least 6 characters.')
.oneOf([ref('password'), null], `Passwords don't match.`)
.required('You have to enter the password confirmation.'),
};
// Sign in schema
const signInSchema = object().shape({
email: user.email,
password: user.password,
});
// Sign up schema
const signUpSchema = object().shape({
email: user.email,
password: user.password,
passwordConfirmation: user.passwordConfirmation,
});
// Reset password schema
const resetPasswordSchema = object().shape({
email: user.email,
});
export { habitSchema, signInSchema, signUpSchema, resetPasswordSchema };
|