misc_pterodactyl-panel/resources/scripts/components/elements/InputError.tsx
2021-07-25 17:14:55 -06:00

27 lines
776 B
TypeScript

import React from 'react';
import { FormikErrors, FormikTouched } from 'formik';
import { capitalize } from '@/helpers';
interface Props {
errors: FormikErrors<any>;
touched: FormikTouched<any>;
name: string;
children?: string | number | null | undefined;
}
const InputError = ({ errors, touched, name, children }: Props) => (
touched[name] && errors[name] ?
<p className={'input-help error'}>
{typeof errors[name] === 'string' ?
capitalize(errors[name] as string)
:
capitalize((errors[name] as unknown as string[])[0])
}
</p>
:
<>
{children ? <p className={'input-help'}>{children}</p> : null}
</>
);
export default InputError;