2020-02-23 04:07:56 +00:00
|
|
|
import { FormikErrors, FormikTouched } from 'formik';
|
2020-07-04 22:19:46 +00:00
|
|
|
import tw from 'twin.macro';
|
2022-06-26 18:34:09 +00:00
|
|
|
import { capitalize } from '@/lib/strings';
|
2020-02-23 04:07:56 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
errors: FormikErrors<any>;
|
|
|
|
touched: FormikTouched<any>;
|
|
|
|
name: string;
|
2020-07-04 22:19:46 +00:00
|
|
|
children?: string | number | null | undefined;
|
2020-02-23 04:07:56 +00:00
|
|
|
}
|
|
|
|
|
2022-06-26 19:13:52 +00:00
|
|
|
const InputError = ({ errors, touched, name, children }: Props) =>
|
|
|
|
touched[name] && errors[name] ? (
|
2020-07-04 22:19:46 +00:00
|
|
|
<p css={tw`text-xs text-red-400 pt-2`}>
|
2022-06-26 19:13:52 +00:00
|
|
|
{typeof errors[name] === 'string'
|
|
|
|
? capitalize(errors[name] as string)
|
2022-11-25 20:25:03 +00:00
|
|
|
: capitalize((errors[name] as unknown as string[])[0] ?? '')}
|
2020-02-23 04:07:56 +00:00
|
|
|
</p>
|
2022-06-26 19:13:52 +00:00
|
|
|
) : (
|
|
|
|
<>{children ? <p css={tw`text-xs text-neutral-400 pt-2`}>{children}</p> : null}</>
|
|
|
|
);
|
2020-02-23 04:07:56 +00:00
|
|
|
|
|
|
|
export default InputError;
|