misc_pterodactyl-panel/resources/scripts/components/elements/InputError.tsx

28 lines
776 B
TypeScript
Raw Normal View History

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