diff --git a/src/components/AuthUser/SignInForm/InputField.tsx b/src/components/AuthUser/SignInForm/InputField.tsx new file mode 100644 index 0000000000000000000000000000000000000000..a2dc677dcc785b87fc28e94d1cc1a40b6cc4c065 --- /dev/null +++ b/src/components/AuthUser/SignInForm/InputField.tsx @@ -0,0 +1,28 @@ +import React, { FC } from 'react'; +import { TextField } from '@material-ui/core'; + +type Props = { + id: string; + label: string; + error: boolean; + errorMessage: string; +}; + +export const InputField: FC<Props> = (props: Props) => { + const { id, label, error, errorMessage } = props; + return ( + <TextField + variant="outlined" + margin="normal" + required + fullWidth + id={id} + label={label} + name={id} + autoComplete={id} + autoFocus + error={error} + helperText={error && errorMessage} + /> + ); +}; diff --git a/src/components/AuthUser/SignInForm/SignInForm.tsx b/src/components/AuthUser/SignInForm/SignInForm.tsx index af58f727a7b04d54f7f64daeaeea3708e70ffc30..016e133c2f29e397458e0026879b4fa1e58c8126 100644 --- a/src/components/AuthUser/SignInForm/SignInForm.tsx +++ b/src/components/AuthUser/SignInForm/SignInForm.tsx @@ -1,8 +1,9 @@ import React, { FC } from 'react'; -import { useForm, Controller } from 'react-hook-form'; +import { useForm, Controller, appendErrors } from 'react-hook-form'; import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'; import { TextField, Button } from '@material-ui/core'; import { DevTool } from '@hookform/devtools'; +import { InputField } from './InputField'; const useStyles = makeStyles((theme: Theme) => createStyles({ @@ -20,6 +21,7 @@ const useStyles = makeStyles((theme: Theme) => }, }), ); + // TODO: real time form validation export const SignInForm: FC = () => { interface FormData { @@ -57,18 +59,11 @@ export const SignInForm: FC = () => { required: { value: true, message: 'You must enter your email' }, }} render={() => ( - <TextField - variant="outlined" - margin="normal" - required - fullWidth + <InputField id="email" label="Email Address" - name="email" - autoComplete="email" - autoFocus error={Boolean(errors.email)} - helperText={errors.email && 'Incorrect entry.'} + errorMessage="Incorrect entry." /> )} /> @@ -83,19 +78,11 @@ export const SignInForm: FC = () => { required: { value: true, message: 'You must enter your name' }, }} render={() => ( - <TextField - variant="outlined" - margin="normal" - required - fullWidth - name="password" - label="Password" - type="password" + <InputField id="password" - autoComplete="password" - autoFocus + label="Password" error={Boolean(errors.password)} - helperText={errors.password && 'Incorrect entry.'} + errorMessage="Incorrect entry." /> )} />