import React, { Fragment } from 'react';
import { Trans } from 'react-i18next';
import { R_IPV4 } from '../helpers/constants';
export const renderField = ({
input, id, className, placeholder, type, disabled, meta: { touched, error },
}) => (
{!disabled && touched && (error && {error})}
);
export const renderSelectField = ({
input, placeholder, disabled, meta: { touched, error },
}) => (
{!disabled && touched && (error && {error})}
);
export const required = (value) => {
if (value || value === 0) {
return false;
}
return form_error_required;
};
export const ipv4 = (value) => {
if (value && !new RegExp(R_IPV4).test(value)) {
return form_error_ip_format;
}
return false;
};
export const isPositive = (value) => {
if ((value || value === 0) && (value <= 0)) {
return form_error_positive;
}
return false;
};
export const port = (value) => {
if (value && (value < 80 || value > 65535)) {
return form_error_port_range;
}
return false;
};
export const toNumber = value => value && parseInt(value, 10);