2016-11-16 18:12:36 +00:00
|
|
|
/* eslint-disable */
|
2020-08-13 10:12:02 +00:00
|
|
|
import i18n from 'i18next';
|
2016-11-16 18:12:36 +00:00
|
|
|
export const domOnlyProps = ({
|
|
|
|
initialValue,
|
|
|
|
autofill,
|
|
|
|
onUpdate,
|
|
|
|
valid,
|
|
|
|
invalid,
|
|
|
|
dirty,
|
|
|
|
pristine,
|
|
|
|
active,
|
|
|
|
touched,
|
|
|
|
visited,
|
|
|
|
autofilled,
|
|
|
|
error,
|
|
|
|
...domProps }) => domProps;
|
|
|
|
/* eslint-enable */
|
2017-03-16 22:25:12 +00:00
|
|
|
|
2019-07-23 18:16:05 +00:00
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
const EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i;
|
|
|
|
|
2017-03-16 22:25:12 +00:00
|
|
|
function validateNameEmail(formProps, errors) {
|
|
|
|
if (!formProps.username) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.username = i18n.t('ReduxFormUtils.errorEmptyUsername');
|
2017-03-16 22:25:12 +00:00
|
|
|
} else if (!formProps.username.match(/^.{1,20}$/)) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.username = i18n.t('ReduxFormUtils.errorLongUsername');
|
2017-03-16 22:25:12 +00:00
|
|
|
} else if (!formProps.username.match(/^[a-zA-Z0-9._-]{1,20}$/)) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.username = i18n.t('ReduxFormUtils.errorValidUsername');
|
2017-03-16 22:25:12 +00:00
|
|
|
}
|
|
|
|
|
2021-01-27 21:14:21 +00:00
|
|
|
// if (!formProps.email) {
|
|
|
|
// errors.email = i18n.t('ReduxFormUtils.errorEmptyEmail');
|
|
|
|
// } else
|
|
|
|
if (
|
|
|
|
formProps.email &&
|
2017-06-06 02:33:32 +00:00
|
|
|
// eslint-disable-next-line max-len
|
2019-07-23 18:16:05 +00:00
|
|
|
!formProps.email.match(EMAIL_REGEX)) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.email = i18n.t('ReduxFormUtils.errorInvalidEmail');
|
2017-03-16 22:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function validateSettings(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
|
|
|
|
validateNameEmail(formProps, errors);
|
|
|
|
|
|
|
|
if (formProps.currentPassword && !formProps.newPassword) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.newPassword = i18n.t('ReduxFormUtils.errorNewPassword');
|
2017-03-16 22:25:12 +00:00
|
|
|
}
|
2019-10-17 16:53:11 +00:00
|
|
|
if (formProps.newPassword && formProps.newPassword.length < 6) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.newPassword = i18n.t('ReduxFormUtils.errorShortPassword');
|
2019-10-17 16:53:11 +00:00
|
|
|
}
|
2017-03-16 22:25:12 +00:00
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function validateLogin(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
if (!formProps.email) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.email = i18n.t('ReduxFormUtils.errorEmptyEmail');
|
2017-03-16 22:25:12 +00:00
|
|
|
}
|
|
|
|
if (!formProps.password) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.password = i18n.t('ReduxFormUtils.errorEmptyPassword');
|
2017-03-16 22:25:12 +00:00
|
|
|
}
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function validateSignup(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
|
|
|
|
validateNameEmail(formProps, errors);
|
|
|
|
|
|
|
|
if (!formProps.password) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.password = i18n.t('ReduxFormUtils.errorEmptyPassword');
|
2017-03-16 22:25:12 +00:00
|
|
|
}
|
2019-10-17 16:53:11 +00:00
|
|
|
if (formProps.password && formProps.password.length < 6) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.password = i18n.t('ReduxFormUtils.errorShortPassword');
|
2019-03-15 21:35:48 +00:00
|
|
|
}
|
2017-03-16 22:25:12 +00:00
|
|
|
if (!formProps.confirmPassword) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.confirmPassword = i18n.t('ReduxFormUtils.errorConfirmPassword');
|
2017-03-16 22:25:12 +00:00
|
|
|
}
|
|
|
|
|
2019-03-20 21:53:03 +00:00
|
|
|
if (formProps.password !== formProps.confirmPassword && formProps.confirmPassword) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.confirmPassword = i18n.t('ReduxFormUtils.errorPasswordMismatch');
|
2017-03-16 22:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
2019-07-23 18:16:05 +00:00
|
|
|
export function validateResetPassword(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
if (!formProps.email) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.email = i18n.t('ReduxFormUtils.errorEmptyEmail');
|
2019-07-23 18:16:05 +00:00
|
|
|
} else if (
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
!formProps.email.match(EMAIL_REGEX)) {
|
2020-08-13 10:12:02 +00:00
|
|
|
errors.email = i18n.t('ReduxFormUtils.errorInvalidEmail');
|
2019-07-23 18:16:05 +00:00
|
|
|
}
|
|
|
|
return errors;
|
|
|
|
}
|