Created
August 10, 2021 19:24
-
-
Save pedroribeirodev/9453dcbf7a795b6c3e0a478d9d8d87f2 to your computer and use it in GitHub Desktop.
exemplo código com select nativo
This file contains 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 { useForm } from 'react-hook-form'; | |
import PropTypes from 'prop-types'; | |
import { yupResolver } from '@hookform/resolvers/yup'; | |
import { Button } from '@material-ui/core'; | |
import { MASKS, TYPE_EDITAL } from 'helpers/constants'; | |
import Form from 'components/Form'; | |
import Input from 'components/Input'; | |
import Modal from 'components/Modal'; | |
import Select from 'components/Select'; | |
import { schema } from './schema'; | |
import { AgroupButtons, AgroupInput } from './styles'; | |
function ModalEdital({ | |
openModal, | |
handleModal, | |
onSubmit, | |
edit, | |
dataEditEdital | |
}) { | |
const formMethods = useForm({ | |
resolver: yupResolver(schema) | |
}); | |
const { errors } = formMethods; | |
return ( | |
<Modal openModal={openModal} closeModal={handleModal}> | |
<Form formMethods={formMethods} onSubmit={onSubmit}> | |
<h2>{edit ? 'Alterar Edital' : 'Cadastrar Edital'}</h2> | |
<Input | |
label="Título do Edital" | |
formMethods={formMethods} | |
mt="30px" | |
name="title" | |
error={errors.title} | |
defaultValue={dataEditEdital.title} | |
/> | |
<AgroupInput> | |
<Input | |
label="Ano de Referência" | |
formMethods={formMethods} | |
mr="20px" | |
name="year" | |
error={errors.year} | |
mask={MASKS.YEAR} | |
defaultValue={dataEditEdital.year} | |
/> | |
<Select | |
defaultValue={dataEditEdital.type} | |
label="Tipo do Edital" | |
options={TYPE_EDITAL} | |
name="type" | |
register={formMethods.register} | |
mr="20px" | |
/> | |
<Input | |
label="Número do Edital" | |
formMethods={formMethods} | |
name="number" | |
error={errors.number} | |
defaultValue={dataEditEdital.number} | |
/> | |
</AgroupInput> | |
<AgroupButtons> | |
<Button variant="outlined" onClick={handleModal}> | |
Cancelar | |
</Button> | |
<Button type="submit" style={{ marginLeft: '15px' }}> | |
{edit ? 'Alterar' : 'Cadastrar'} | |
</Button> | |
</AgroupButtons> | |
</Form> | |
</Modal> | |
); | |
} | |
ModalEdital.defaultProps = { | |
dataEditEdital: {}, | |
edit: false | |
}; | |
ModalEdital.propTypes = { | |
openModal: PropTypes.bool.isRequired, | |
handleModal: PropTypes.func.isRequired, | |
onSubmit: PropTypes.func.isRequired, | |
edit: PropTypes.bool, | |
dataEditEdital: PropTypes.objectOf(PropTypes.string) | |
}; | |
export default ModalEdital; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment