diff --git a/src/components/School.js b/src/components/School.js new file mode 100644 index 0000000..6b8723f --- /dev/null +++ b/src/components/School.js @@ -0,0 +1,22 @@ +import React from 'react'; +import toTitleCase from 'utils/toTitleCase'; +import convertKilometerToMeter from 'utils/convertKilometerToMeter'; +import { SchoolContact } from 'components/SchoolContact'; +import STRINGS from 'configs/Strings'; +import findGroupName from 'utils/findGroupName'; + +export const School = ({school, groupCode, key}) => { console.log(school, groupCode, key); return ( +
+
+

{school.nm_unidade_educacao}

+ {school.sg_tp_escola != null &&

{school.sg_tp_escola}

} + {school.endereco_completo != null &&

{toTitleCase(school.endereco_completo)}

} + {groupCode != null &&

Crianças atualmente matriculadas no {findGroupName(groupCode)}: {school.signed_up}

} + {school.distance != null &&

{convertKilometerToMeter(school.distance)} {STRINGS.messages.meters}

} + {school.telefones &&

{STRINGS.messages.phone}: {school.telefones[0]}

} +
+
+ +
+
+)}; diff --git a/src/components/SchoolList.js b/src/components/SchoolList.js new file mode 100644 index 0000000..41ef418 --- /dev/null +++ b/src/components/SchoolList.js @@ -0,0 +1,51 @@ +import React from 'react'; +import { DefaultButton } from 'components/DefaultButton'; +import { School } from 'components/School'; +import STRINGS from 'configs/Strings'; +import { Link } from 'react-router-dom'; + +const shortenedListSize = 5; + +export class SchoolList extends React.Component { + constructor(props) { + super(props); + this.state = { + displayedListSize: props.shortenList + ? Math.min(shortenedListSize, props.schools.length) + : props.schools.length, + }; + this.handleSeeMore = this.handleSeeMore.bind(this); + } + + handleSeeMore() { + this.setState({ + displayedListSize: this.props.schools.length, + }); + } + + isListShortened() { + return this.props.schools.length !== this.state.displayedListSize; + } + + render() { + return ( +
+ {this.props.schools.slice(0,this.state.displayedListSize).map( + (school,i) => + )} + {this.isListShortened() ?
+ + + +
: null} +
+ ); + } +}; diff --git a/src/containers/Register/Register.js b/src/containers/Register/Register.js index 78442a9..ea2ba1d 100644 --- a/src/containers/Register/Register.js +++ b/src/containers/Register/Register.js @@ -4,7 +4,7 @@ import { BackButton } from "components/BackButton"; import { Banner } from "components/Banner"; import { SubBanner } from "components/SubBanner"; import { ContinueButton } from "components/ContinueButton"; -import { RegistrationList } from "./RegistrationList"; +import { SchoolList } from "components/SchoolList"; export class Register extends React.Component { constructor(props) { @@ -19,6 +19,15 @@ export class Register extends React.Component { } render() { + const schools = this.props.location.state.schoolsNearby.map(school => { + return { + nm_unidade_educacao: school.nm_unidade_educacao, + sg_tp_escola: school.sg_tp_escola, + endereco_completo: school.endereco_completo, + distance: school.distance, + telefones: school.telefones, + }; + }); return (
@@ -36,7 +45,7 @@ export class Register extends React.Component { - + diff --git a/src/containers/Register/RegistrationList.js b/src/containers/Register/RegistrationList.js deleted file mode 100644 index 699bc5d..0000000 --- a/src/containers/Register/RegistrationList.js +++ /dev/null @@ -1,33 +0,0 @@ -import React from 'react'; -import convertKilometerToMeter from 'utils/convertKilometerToMeter'; -import toTitleCase from 'utils/toTitleCase'; -import { SchoolContact } from "components/SchoolContact"; -import STRINGS from 'configs/Strings'; - -// FIXME: this will probably require another request to the api with all schools in radius, not just those that have slots -export class RegistrationList extends React.Component { - render() { - let schoolList; - if (this.props.schools) { - schoolList = this.props.schools.map((school, i) => -
-
-

{school.nm_unidade_educacao}

-

{school.sg_tp_escola}

-

{toTitleCase(school.endereco_completo)}

-

{convertKilometerToMeter(school.distance)} {STRINGS.messages.meters}

- {school.telefones &&

{STRINGS.messages.phone}: {school.telefones[0]}

} -
-
- -
-
- ); - } - return ( -
- {schoolList} -
- ) - } -} diff --git a/src/containers/Results/Results.js b/src/containers/Results/Results.js index b9da456..421bee8 100644 --- a/src/containers/Results/Results.js +++ b/src/containers/Results/Results.js @@ -31,7 +31,6 @@ export class Results extends React.Component { waitListSize: result.results.wait, } }); - console.log(this.state.queryResults); }, (error) => { this.setState({ diff --git a/src/containers/Results/ResultsLoaded.js b/src/containers/Results/ResultsLoaded.js index 851f37e..371dd60 100644 --- a/src/containers/Results/ResultsLoaded.js +++ b/src/containers/Results/ResultsLoaded.js @@ -3,13 +3,21 @@ import PropTypes from 'prop-types'; import STRINGS from 'configs/Strings'; import { Banner } from 'components/Banner'; import findGroupName from 'utils/findGroupName'; -import { SchoolList } from 'containers/Results/SchoolList'; +import { SchoolList } from 'components/SchoolList'; import { Link } from 'react-router-dom'; import { DefaultButton } from 'components/DefaultButton'; import { ContinueButton } from 'components/ContinueButton'; import { Spacer } from 'components/Spacer'; export const ResultsLoaded = (props) => { + const schools = props.schoolsNearby.map(school => { + return { + nm_unidade_educacao: school.nm_unidade_educacao, + endereco_completo: school.endereco_completo, + distance: school.distance, + signed_up: school[`vagas_cd_serie_${props.groupCode}`], + }; + }); return ( { ]} /> {props.schoolsNearby.length ? : } diff --git a/src/containers/Results/SchoolList.js b/src/containers/Results/SchoolList.js deleted file mode 100644 index eb779d9..0000000 --- a/src/containers/Results/SchoolList.js +++ /dev/null @@ -1,60 +0,0 @@ -import React from 'react' -import { DefaultButton } from "components/DefaultButton"; -import { BrowserRouter as Link } from 'react-router-dom'; -import convertKilometerToMeter from 'utils/convertKilometerToMeter'; -import toTitleCase from 'utils/toTitleCase'; -import { SchoolContact } from "components/SchoolContact"; -import STRINGS from 'configs/Strings'; - -export class SchoolList extends React.Component { - constructor(props) { - super(props); - this.state = { - schoolList: this.props.schools, - schoolListPaginated: this.props.schools.slice(0, 5) - }; - this.handleSeeMore = this.handleSeeMore.bind(this) - } - generateSchoolList(schools) { - let schoolList; - if (schools) { - schoolList = schools.map((school, i) => -
-
-

{school.nm_unidade_educacao}

-

{toTitleCase(school.endereco_completo)}

-

Crianças atualmente matriculadas no {this.props.groupName}: {school['vagas_cd_serie_' + this.props.groupCode]}

-

{convertKilometerToMeter(school.distance)} {STRINGS.messages.meters}

-
-
- -
-
- ); - } - return schoolList; - } - - handleSeeMore() { - const schoolList = this.state.schoolList; - this.setState({ - schoolListPaginated: schoolList.slice(0, schoolList.length) - }); - } - - render() { - let paginate = this.props.schools.length > 5 && this.state.schoolList.length !== this.state.schoolListPaginated.length ? true : false; - return ( -
-
- {this.generateSchoolList(this.state.schoolListPaginated)} -
- {paginate && - - } -
-
-
- ) - } -}