diff --git a/src/Components/PageProfessorComponents/PartOne.js b/src/Components/PageProfessorComponents/PartOne.js index 5c4b92f659174274c6a55eb3d8432722d2464c28..082ac22fff823f8dce487bb96528b2117dfa39b9 100644 --- a/src/Components/PageProfessorComponents/PartOne.js +++ b/src/Components/PageProfessorComponents/PartOne.js @@ -12,7 +12,7 @@ import {ButtonCancelar} from './PartTwo.js' import axios from 'axios' import FormInput from '../FormInput.js' -function sortDict (dict) { +export function sortDict (dict) { const newDict = dict.sort((a, b) => (a.name) > (b.name) ? 1 : -1) return newDict @@ -31,7 +31,9 @@ export default function PartOne (props) { const [uf, setUF] = useState( { algumFoiEscolhido : false, - value : '' + selected : '', //id + name : '', + abbreviation : '' } ) @@ -39,27 +41,28 @@ export default function PartOne (props) { const [municipio, setMunicipio] = useState( { algumFoiEscolhido : false, - value : '' + selected : '', + name : '' } ) const [codigoINEP, setCodigoINEP] = useState( { codigoInvalido : false, - value : '' + selected : '' } ) const handleCodigoINEP = (event) => { const code = event.target.value - + setCodigoINEP({...codigoINEP, codigoInvalido : false, - value : code + selected : code }) } const validateINEP = () => { - const code = codigoINEP.value + const code = codigoINEP.selected axios.get(('https://www.simcaq.c3sl.ufpr.br/api/v1/portal_mec_inep?filter=school_cod:' + code) ).then( (response) => { @@ -67,14 +70,15 @@ export default function PartOne (props) { }, (error) => { setCodigoINEP({...codigoINEP, codigoInvalido : true, - value : '' + selected : '' }) } ) } const handleSubmit = () => { - props.handleBuscar(uf.value, municipio.value, codigoINEP.value) + console.log('handle submit : ', uf.abbreviation, uf.selected, municipio.name, municipio.selected, codigoINEP.value) + props.handleBuscar(uf.abbreviation, uf.selected, municipio.name, municipio.selected, codigoINEP.value) } //on render component, call simcaq api and update ufList @@ -87,10 +91,14 @@ export default function PartOne (props) { }, []) const handleChooseUF = (event) => { - const ufID = event.target.value + const ufID = event.target.value.ufID + const ufAbbreviation = event.target.value.abbreviation + const ufName = event.target.value.name setUF({...uf, algumFoiEscolhido : true, - value : ufID + selected : ufID, + name : ufName, + abbreviation : ufAbbreviation } ) @@ -102,10 +110,12 @@ export default function PartOne (props) { } const handleChooseCity = (event) => { - const cityID = event.target.value + const cityID = event.target.value.id + const cityName = event.target.value.name setMunicipio({...municipio, algumFoiEscolhido : true, - value : cityID + selected : cityID, + name : cityName } ) } @@ -123,12 +133,12 @@ export default function PartOne (props) { <Select labelId="demo-simple-select-label" id="demo-simple-select" - value={uf.value} + value={uf.name} onChange={handleChooseUF} > { ufList.map( (ufs)=> - <MenuItem value={ufs.id}>{ufs.name}</MenuItem> + <MenuItem key={ufs.id} value={{abbreviation : ufs.abbreviation, ufID : ufs.id, name : ufs.name}}>{ufs.name}</MenuItem> ) } </Select> @@ -138,12 +148,12 @@ export default function PartOne (props) { <Select labelId="demo-simple-select-label" id="demo-simple-select" - value={municipio.value} + value={municipio.name} onChange={handleChooseCity} > { municipioList.map( (cidades)=> - <MenuItem value={cidades.id}>{cidades.name}</MenuItem> + <MenuItem value={{id : cidades.id, name : cidades.name}}>{cidades.name}</MenuItem> ) } </Select> @@ -169,7 +179,7 @@ export default function PartOne (props) { <FormInput inputType={'text'} name={'Código INEP'} - value={codigoINEP.value} + value={codigoINEP.selected} handleChange = {handleCodigoINEP} placeholder={'Código INEP'} required={true} @@ -188,7 +198,7 @@ export default function PartOne (props) { </Content> <Divider/> <ButtonsArea> - <ButtonCancelar>CANCELAR VERIFICAÇÃO</ButtonCancelar> + <ButtonCancelar onClick={props.handleCancelar}>CANCELAR VERIFICAÇÃO</ButtonCancelar> </ButtonsArea> </> ) diff --git a/src/Components/PageProfessorComponents/PartThree.js b/src/Components/PageProfessorComponents/PartThree.js index 75a9faf55704bed484b7025a4ce76536f702968e..32aa206484e85a8bd595c00de60570cfc12f3cde 100644 --- a/src/Components/PageProfessorComponents/PartThree.js +++ b/src/Components/PageProfessorComponents/PartThree.js @@ -9,11 +9,33 @@ import styled from 'styled-components' import {Button} from '@material-ui/core' export default function PartThree (props) { - const [phoneNumber, setPhoneNumber] = useState('') - const handleChangePhoneNumber = (event) => {setPhoneNumber(event.target.value)} + const [phoneNumber, setPhoneNumber] = useState( + { + flagInvalid : false, + number : '' + } + ) + const handleChangePhoneNumber = (event) => { + const input = event.target.value.replace(/\D/,'') + setPhoneNumber({...phoneNumber, + flagInvalid : (input.length > 9 ? true : false), + number : (input.length > 9 ? phoneNumber.number : input), + }) + } + + const [cpf, setCpf] = useState( { + flagInvalid : false, + number : '' + }) + const handleChangeCpf = (event) => { + const input = event.target.value.replace(/\D/,'') + setCpf({...cpf, + flagInvalid : (input.length > 11 ? true : false), + number : (input.length > 11 ? cpf.number : input), + }) + } + - const [cpf, setCpf] = useState('') - const handleChangeCpf = (event) => {setCpf(event.target.value)} return ( <> <Content> @@ -25,10 +47,12 @@ export default function PartThree (props) { <p>Inserir o telefone da escola:</p> <FormInput inputType={'text'} + pattern="[0-9]" name={'DDD e Número'} placeholder={'DDD e Número'} - value={phoneNumber} + value={phoneNumber.number} handleChange={handleChangePhoneNumber} + error={phoneNumber.flagInvalid} > </FormInput> </FormControl> @@ -38,7 +62,7 @@ export default function PartThree (props) { inputType={'text'} name={'11 dÃgitos'} placeholder={'11 dÃgitos'} - value={cpf} + value={cpf.number} handleChange={handleChangeCpf} mask={'999.999.999-99'} > @@ -49,7 +73,8 @@ export default function PartThree (props) { <ButtonConfirmar onClick={props.handleBuscar}>BUSCAR</ButtonConfirmar> </div> <div style={{display:"flex", justifyContent:"center"}}> - <ButtonGrey>VOLTAR</ButtonGrey><ButtonCancelar>CANCELAR</ButtonCancelar> + <ButtonGrey onClick={() => props.goBack(false, true, false)}>VOLTAR</ButtonGrey> + <ButtonCancelar onClick={props.handleCancelar}>CANCELAR</ButtonCancelar> </div> </div> </form> diff --git a/src/Components/PageProfessorComponents/PartTwo.js b/src/Components/PageProfessorComponents/PartTwo.js index e8bce948b1d8e29e24c6f2129856bb6cb4443137..2a9237e7c25188c0af80d5da1e653207da96f7e1 100644 --- a/src/Components/PageProfessorComponents/PartTwo.js +++ b/src/Components/PageProfessorComponents/PartTwo.js @@ -1,15 +1,47 @@ -import React from 'react' +import React, {useState, useEffect} from 'react' import {Content, ButtonsArea} from './PartOne.js' import Divider from '@material-ui/core/Divider'; import Stepper from '../Stepper.js' import CustomizedTables from '../Table.js' import styled from 'styled-components' import {Button} from '@material-ui/core' +import axios from 'axios' +import {simcaqAPIurl} from '../../env' +import {sortDict} from './PartOne.js' export default function PartTwo (props) { + const [htttpRequestDone, setDone] = useState(false) + const [schoolList, setSchoolList] = useState([]) + + useEffect ( () => { + const code = (props.info.inep_code || '') + const uf = (props.info.school_uf.id || '') + const municipio = (props.info.school_City.id || '') + console.log(code, uf, municipio) + //if user searched by inep code + if (code != '') { + axios.get((`${simcaqAPIurl}/portal_mec_inep?filter=school_cod:` + code) + ).then ((response) => { + console.log(response.data.result) + + setSchoolList(response.data.result) + setDone(true) + + }, (error) => console.log('erro ao dar get na escola por inep code') + )} + else if (uf != '' && municipio != '') { + axios.get((`${simcaqAPIurl}/school?filter=state:"` + uf + '",city_name:"' + municipio + '"') + ). then((response)=> { + console.log(response.data.result) + setSchoolList(sortDict(response.data.result)) + setDone(true) + }, (error) => console.log('erro ao dar get na escola por uf e municipio', code, uf, municipio) + )} + }, []) + return ( <> - {console.log(props.info)} + {console.log(props)} <Content> <h4>Vamos localizar o seu cadastro:</h4> <Stepper items={props.stepper}/> @@ -17,12 +49,18 @@ export default function PartTwo (props) { <Content> <InputContainer> <p>Selecione a sua escola:</p> - <CustomizedTables onClick={props.onClickTable}/> + + <CustomizedTables onClick={props.onClickTable} + columns={['Codigo INEP', 'Escola', 'UF', 'Cidade']} + rows={schoolList} + /> + </InputContainer> </Content> <Divider/> <ButtonsArea> - <ButtonGrey>VOLTAR</ButtonGrey><ButtonCancelar>CANCELAR VERIFICAÇÃO</ButtonCancelar> + <ButtonGrey onClick={() => props.goBack(true, false, false)}>VOLTAR</ButtonGrey> + <ButtonCancelar onClick={props.handleCancelar}>CANCELAR VERIFICAÇÃO</ButtonCancelar> </ButtonsArea> </> ) diff --git a/src/Components/Table.js b/src/Components/Table.js index 9bad62312c90aa34c654eaaf2640a381f92c09dd..bdf987cef629d58d1403632546fb5d59b85e6b9c 100644 --- a/src/Components/Table.js +++ b/src/Components/Table.js @@ -31,17 +31,6 @@ const StyledTableRow = withStyles(theme => ({ }, }))(TableRow); -function createData(name, calories, fat, carbs) { - return { name, calories, fat, carbs}; -} - -const rows = [ - createData('Frozen yoghurt', 159, 6.0, 24), - createData('Ice cream sandwich', 237, 9.0, 37), - createData('Eclair', 262, 16.0, 24), - createData('Cupcake', 305, 3.7, 67), - createData('Gingerbread', 356, 16.0, 49), -]; const useStyles = makeStyles({ table: { @@ -53,29 +42,33 @@ export default function CustomizedTables(props) { const classes = useStyles(); return ( + <> + {console.log(props)} <TableContainer component={Paper}> <Table className={classes.table} aria-label="customized table"> <TableHead> <TableRow> - <StyledTableCell>Codigo INEP</StyledTableCell> - <StyledTableCell align="right">Escola</StyledTableCell> - <StyledTableCell align="right">UF</StyledTableCell> - <StyledTableCell align="right">Cidade</StyledTableCell> + { + props.columns.map( (column)=> + <StyledTableCell align="left">{column}</StyledTableCell> + ) + } </TableRow> </TableHead> <TableBody> - {rows.map(row => ( - <StyledTableRow key={row.name}> + {props.rows.map(row => ( + <StyledTableRow onClick={props.onClick} key={row.id}> <StyledTableCell component="th" scope="row"> - {row.name} + {row.id} </StyledTableCell> - <StyledTableCell align="right" onClick={props.onClick}>{row.calories}</StyledTableCell> - <StyledTableCell align="right">{row.fat}</StyledTableCell> - <StyledTableCell align="right">{row.carbs}</StyledTableCell> + <StyledTableCell align="left">{row.name}</StyledTableCell> + <StyledTableCell align="left">{row.state_name}</StyledTableCell> + <StyledTableCell align="left">{row.city_name}</StyledTableCell> </StyledTableRow> ))} </TableBody> </Table> </TableContainer> + </> ); } diff --git a/src/Pages/PageProfessor.js b/src/Pages/PageProfessor.js index b89eacc84d2ede168e41e70c279e820425bc37db..295818ce9e49bccd26dc9f8092cf434260e0be70 100644 --- a/src/Pages/PageProfessor.js +++ b/src/Pages/PageProfessor.js @@ -18,8 +18,14 @@ export default function PageProfessor (props) { teacher_cpf: '', school_phone: '', school_name: '', - school_City: '', // perguntar se aqui é o id ou o nome - school_uf : '', //perguntar se aqui é o id ou o nome + school_City : { + id : '', + name : '' + }, + school_uf : { + id : '', + abbreviation : '' + }, inep_code: '' } ) @@ -37,13 +43,20 @@ export default function PageProfessor (props) { ) } - const handleBuscar = (uf, municipio, inep) => { + const handleBuscar = (ufAbbreviation, ufID, nomeMunicipio, idMunicipio, inep) => { + console.log(ufAbbreviation, ufID, nomeMunicipio, idMunicipio, inep) setRegisterInformation({...registerInformation, - school_uf : uf, - school_City : municipio, - inep_code : inep + school_uf : { + id : (ufID ? ufID : ''), + abbreviation: (ufAbbreviation ? ufAbbreviation : '') + }, + school_City : { + id : (idMunicipio ? idMunicipio : ''), + name : (nomeMunicipio ? nomeMunicipio : '') + }, + inep_code : (inep ? inep : '') }) - toggleStepper(false, true, false) + toggleStepper(false, false, true) } const handleCancelar = () => { @@ -69,8 +82,17 @@ export default function PageProfessor (props) { handleCancelar={handleCancelar} /> } - {stepper[1].selected && <PartTwo stepper={stepper} onClickTable={onClickTable} info={registerInformation}/>} - {stepper[2].selected && <PartThree stepper={stepper}/>} + {stepper[1].selected && + <PartTwo stepper={stepper} onClickTable={onClickTable} + info={registerInformation} goBack={toggleStepper} + handleCancelar={handleCancelar} + /> + } + {stepper[2].selected && + <PartThree stepper={stepper} goBack={toggleStepper} + handleCancelar={handleCancelar} + /> + } </div> </Paper> </div> diff --git a/src/env.js b/src/env.js index 3ba1693d8fd16ad4105d2f3fa6f3b449a4beacbe..36b6bc8d02f338624c2ac33f3d97ce7864acd34c 100644 --- a/src/env.js +++ b/src/env.js @@ -17,9 +17,14 @@ You should have received a copy of the GNU Affero General Public License along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/ -var apiDomain = 'https://api.portalmec.c3sl.ufpr.br/', +var apiDomain = 'https://api.portalmec.c3sl.ufpr.br', apiVersion = 'v1', apiUrl = apiDomain + '/' + apiVersion; +var simcaqAPIDomain = 'https://www.simcaq.c3sl.ufpr.br', + apiVersion = 'v1', + simcaqAPIurl = simcaqAPIDomain + '/' + apiVersion + export {apiUrl}; export {apiDomain}; +export {simcaqAPIurl}