Skip to content
Snippets Groups Projects
Verified Commit 75c7daa5 authored by Defendi Alberto's avatar Defendi Alberto
Browse files

Move TextInput to InputField

parent c6202a26
No related branches found
No related tags found
2 merge requests!17Axios,!13Basic form api and implement cookie entrypoint
Pipeline #11632 failed
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}
/>
);
};
import React, { FC } from 'react'; 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 { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
import { TextField, Button } from '@material-ui/core'; import { TextField, Button } from '@material-ui/core';
import { DevTool } from '@hookform/devtools'; import { DevTool } from '@hookform/devtools';
import { InputField } from './InputField';
const useStyles = makeStyles((theme: Theme) => const useStyles = makeStyles((theme: Theme) =>
createStyles({ createStyles({
...@@ -20,6 +21,7 @@ const useStyles = makeStyles((theme: Theme) => ...@@ -20,6 +21,7 @@ const useStyles = makeStyles((theme: Theme) =>
}, },
}), }),
); );
// TODO: real time form validation // TODO: real time form validation
export const SignInForm: FC = () => { export const SignInForm: FC = () => {
interface FormData { interface FormData {
...@@ -57,18 +59,11 @@ export const SignInForm: FC = () => { ...@@ -57,18 +59,11 @@ export const SignInForm: FC = () => {
required: { value: true, message: 'You must enter your email' }, required: { value: true, message: 'You must enter your email' },
}} }}
render={() => ( render={() => (
<TextField <InputField
variant="outlined"
margin="normal"
required
fullWidth
id="email" id="email"
label="Email Address" label="Email Address"
name="email"
autoComplete="email"
autoFocus
error={Boolean(errors.email)} error={Boolean(errors.email)}
helperText={errors.email && 'Incorrect entry.'} errorMessage="Incorrect entry."
/> />
)} )}
/> />
...@@ -83,19 +78,11 @@ export const SignInForm: FC = () => { ...@@ -83,19 +78,11 @@ export const SignInForm: FC = () => {
required: { value: true, message: 'You must enter your name' }, required: { value: true, message: 'You must enter your name' },
}} }}
render={() => ( render={() => (
<TextField <InputField
variant="outlined"
margin="normal"
required
fullWidth
name="password"
label="Password"
type="password"
id="password" id="password"
autoComplete="password" label="Password"
autoFocus
error={Boolean(errors.password)} error={Boolean(errors.password)}
helperText={errors.password && 'Incorrect entry.'} errorMessage="Incorrect entry."
/> />
)} )}
/> />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment