Skip to content
Snippets Groups Projects

Branch do lucas

Merged Lucas Eduardo Schoenfelder requested to merge branchDoLucas into Develop
8 files
+ 51
47
Compare changes
  • Side-by-side
  • Inline
Files
8
@@ -11,7 +11,6 @@ import Divider from '@material-ui/core/Divider';
import {ButtonCancelar} from './PartTwo.js'
import axios from 'axios'
import FormInput from '../FormInput.js'
import {simcaqAPIurl} from '../../env'
export function sortDict (dict) {
const newDict = dict.sort((a, b) => (a.name) > (b.name) ? 1 : -1)
@@ -19,6 +18,18 @@ export function sortDict (dict) {
}
const extractUFInfo = (ufs, name) => {
var id = ''
var abbreviation = ''
for (const obj of ufs) {
if (obj.name === name) {
id = obj.id
abbreviation = obj.abbreviation
}
}
return {id : id, abbreviation : abbreviation}
}
export default function PartOne (props) {
//stores initial get response (list of states, sorted alphabetically)
const [ufList, setStates] = useState([])
@@ -32,7 +43,6 @@ export default function PartOne (props) {
const [uf, setUF] = useState(
{
algumFoiEscolhido : false,
selected : '', //id
name : '',
abbreviation : ''
}
@@ -42,7 +52,6 @@ export default function PartOne (props) {
const [municipio, setMunicipio] = useState(
{
algumFoiEscolhido : false,
selected : '',
name : ''
}
)
@@ -50,62 +59,62 @@ export default function PartOne (props) {
const [codigoINEP, setCodigoINEP] = useState(
{
codigoInvalido : false,
selected : ''
value : ''
}
)
const handleCodigoINEP = (event) => {
const code = event.target.value
setCodigoINEP({...codigoINEP,
codigoInvalido : false,
selected : code
value : code
})
}
const validateINEP = () => {
const code = codigoINEP.selected
const code = codigoINEP.value
axios.get((`${simcaqAPIurl}/portal_mec_inep?filter=school_cod:` + code)
axios.get(('https://www.simcaq.c3sl.ufpr.br/api/v1/portal_mec_inep?filter=school_cod:' + code)
).then( (response) => {
console.log('code ', code, ' is valid')
handleSubmit()
}, (error) => {
setCodigoINEP({...codigoINEP,
codigoInvalido : true,
selected : ''
value : ''
})
}
)
}
const handleSubmit = () => {
//console.log('handle submit : ', uf.abbreviation, uf.selected, municipio.name, municipio.selected, codigoINEP.selected)
props.handleBuscar(uf.name, uf.selected, municipio.name, municipio.selected, codigoINEP.selected)
console.log('handle submit : ', uf.abbreviation, uf.name, municipio.name, codigoINEP.value)
props.handleBuscar(uf.abbreviation, uf.name, municipio.name, codigoINEP.value)
}
//on render component, call simcaq api and update ufList
useEffect ( () => {
axios.get(('https://simcaq.c3sl.ufpr.br/api/v1/state')
).then( (response) => {
console.log(sortDict(response.data.result))
handleSetStates(sortDict(response.data.result))
console.log(response.data.result)
},
(error) => console.log('erro acessando api do simcaq (estados)'))
}, [])
const handleChooseUF = (event) => {
const ufID = event.target.value.ufID
const ufAbbreviation = event.target.value.abbreviation
const ufName = event.target.value.name
const ufName = event.target.value
const {id, abbreviation} = extractUFInfo(ufList, ufName)
console.log(id, abbreviation)
setUF({...uf,
algumFoiEscolhido : true,
selected : ufID,
name : ufName,
abbreviation : ufAbbreviation
abbreviation : abbreviation
}
)
axios.get(('https://simcaq.c3sl.ufpr.br/api/v1/city?filter=state:' + ufID)
axios.get(('https://simcaq.c3sl.ufpr.br/api/v1/city?filter=state:' + id)
).then( (response) => {
handleSetMunicipioList(sortDict(response.data.result))
}, (error) => console.log('erro acessando api do simcaq (cidades)')
@@ -113,11 +122,10 @@ export default function PartOne (props) {
}
const handleChooseCity = (event) => {
const cityID = event.target.value.id
const cityName = event.target.value.name
const cityName = event.target.value
console.log(cityName)
setMunicipio({...municipio,
algumFoiEscolhido : true,
selected : cityID,
name : cityName
}
)
@@ -141,7 +149,7 @@ export default function PartOne (props) {
>
{
ufList.map( (ufs)=>
<MenuItem key={ufs.id} value={{abbreviation : ufs.abbreviation, ufID : ufs.id, name : ufs.name}}>{ufs.name}</MenuItem>
<MenuItem key={ufs.name} value={ufs.name}>{ufs.name}</MenuItem>
)
}
</Select>
@@ -156,7 +164,7 @@ export default function PartOne (props) {
>
{
municipioList.map( (cidades)=>
<MenuItem value={{id : cidades.id, name : cidades.name}}>{cidades.name}</MenuItem>
<MenuItem key={cidades.name} value={cidades.name}>{cidades.name}</MenuItem>
)
}
</Select>
@@ -182,7 +190,7 @@ export default function PartOne (props) {
<FormInput
inputType={'text'}
name={'Código INEP'}
value={codigoINEP.selected}
value={codigoINEP.value}
handleChange = {handleCodigoINEP}
placeholder={'Código INEP'}
required={true}
Loading