2020-02-23 05:07:56 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { FormikErrors, FormikTouched } from 'formik';
|
2020-07-05 00:19:46 +02:00
|
|
|
import tw from 'twin.macro';
|
2020-07-05 06:46:49 +02:00
|
|
|
import { capitalize } from '@/helpers';
|
2020-02-23 05:07:56 +01:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
errors: FormikErrors<any>;
|
|
|
|
touched: FormikTouched<any>;
|
|
|
|
name: string;
|
2020-07-05 00:19:46 +02:00
|
|
|
children?: string | number | null | undefined;
|
2020-02-23 05:07:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const InputError = ({ errors, touched, name, children }: Props) => (
|
|
|
|
touched[name] && errors[name] ?
|
2020-07-05 00:19:46 +02:00
|
|
|
<p css={tw`text-xs text-red-400 pt-2`}>
|
2020-02-23 05:07:56 +01:00
|
|
|
{typeof errors[name] === 'string' ?
|
|
|
|
capitalize(errors[name] as string)
|
|
|
|
:
|
|
|
|
capitalize((errors[name] as unknown as string[])[0])
|
|
|
|
}
|
|
|
|
</p>
|
|
|
|
:
|
2020-07-05 00:19:46 +02:00
|
|
|
<>
|
|
|
|
{children ? <p css={tw`text-xs text-neutral-400 pt-2`}>{children}</p> : null}
|
|
|
|
</>
|
2020-02-23 05:07:56 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
export default InputError;
|