Created
April 23, 2019 02:47
-
-
Save adrianolsk/56c1a046fe4de8828a6e38a49da0495f to your computer and use it in GitHub Desktop.
teste
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { | |
DialogActionsDefault, | |
DialogContent, | |
DialogTitle, | |
} from '../../components/ModalDialog'; | |
import { Formik, Form } from 'formik'; | |
import { Grid } from '@material-ui/core'; | |
import Dialog from '@material-ui/core/Dialog'; | |
import * as Yup from 'yup'; | |
import FormTextField from '../../components/FormTextField'; | |
import { ERROR_MESSAGES } from '../../shared/constants'; | |
const initialValues = { | |
nome: '', | |
email: '', | |
}; | |
const validationSchema = Yup.object({ | |
nome: Yup.string() | |
.required(ERROR_MESSAGES.REQUIRED) | |
.min(3, ERROR_MESSAGES.MIN_LENGHT(3)), | |
email: Yup.string() | |
.required(ERROR_MESSAGES.REQUIRED) | |
.email(ERROR_MESSAGES.EMAIL), | |
}); | |
interface IProps { | |
open: boolean; | |
handleClose: () => void; | |
onSubmit: (values: any, actions: any) => void; | |
} | |
const ModalUsuario = ({ handleClose, open }: IProps) => { | |
const onSubmit = (values: any, actions: any) => { | |
actions.setSubmitting(false); | |
console.log(values); | |
}; | |
return ( | |
<Dialog fullWidth={true} onClose={handleClose} open={open}> | |
<DialogTitle onClose={handleClose}>Cadastro de usuário</DialogTitle> | |
<Formik | |
initialValues={initialValues} | |
validationSchema={validationSchema} | |
onSubmit={onSubmit} | |
> | |
{({ isSubmitting }) => { | |
return ( | |
<Form noValidate> | |
<DialogContent> | |
<Grid container spacing={8}> | |
<Grid xs={12} item> | |
<FormTextField name="nome" label="Nome" /> | |
</Grid> | |
<Grid xs={12} item> | |
<FormTextField name="email" label="Email" /> | |
</Grid> | |
</Grid> | |
</DialogContent> | |
<DialogActionsDefault | |
cancelText="Cancelar" | |
submitText="Salvar" | |
handleClose={handleClose} | |
disabled={isSubmitting} | |
/> | |
</Form> | |
); | |
}} | |
</Formik> | |
</Dialog> | |
); | |
}; | |
export default ModalUsuario; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment