Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unificando listagens de escola #51

Merged
merged 2 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/components/School.js
Original file line number Diff line number Diff line change
@@ -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 (
<div className="row school-list-item vertical-align" key={key}>
<div className="col-xs-12">
<h4 style={{margin:0}}>{school.nm_unidade_educacao}</h4>
{school.sg_tp_escola != null && <p>{school.sg_tp_escola}</p>}
{school.endereco_completo != null && <p>{toTitleCase(school.endereco_completo)}</p>}
{groupCode != null && <p>Crianças atualmente matriculadas no {findGroupName(groupCode)}: {school.signed_up}</p>}
{school.distance != null && <p>{convertKilometerToMeter(school.distance)} {STRINGS.messages.meters}</p>}
{school.telefones && <p>{STRINGS.messages.phone}: {school.telefones[0]}</p>}
</div>
<div className="col-xs-4">
<SchoolContact school={school} />
</div>
</div>
)};
51 changes: 51 additions & 0 deletions src/components/SchoolList.js
Original file line number Diff line number Diff line change
@@ -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 (
<div className="school-list">
{this.props.schools.slice(0,this.state.displayedListSize).map(
(school,i) => <School
school={school}
groupCode={this.props.groupCode}
key={`school_${i}`}
/>
)}
{this.isListShortened() ? <div className="row">
<Link to="#">
<DefaultButton
title={STRINGS.actions.see_more}
onClick={this.handleSeeMore}
/>
</Link>
</div> : null}
</div>
);
}
};
13 changes: 11 additions & 2 deletions src/containers/Register/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 (
<div>
<BackButton />
Expand All @@ -36,7 +45,7 @@ export class Register extends React.Component {
<Banner
title={STRINGS.registration_list.title}
/>
<RegistrationList schools={this.props.location.state.schoolsNearby} />
<SchoolList schools={schools} shortenList={false} />
<Banner
title={STRINGS.actions.can_do}
/>
Expand Down
33 changes: 0 additions & 33 deletions src/containers/Register/RegistrationList.js

This file was deleted.

1 change: 0 additions & 1 deletion src/containers/Results/Results.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class Results extends React.Component {
waitListSize: result.results.wait,
}
});
console.log(this.state.queryResults);
},
(error) => {
this.setState({
Expand Down
14 changes: 11 additions & 3 deletions src/containers/Results/ResultsLoaded.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<React.Fragment>
<Banner
Expand All @@ -29,9 +37,9 @@ export const ResultsLoaded = (props) => {
]}
/>
{props.schoolsNearby.length ? <SchoolList
schools={props.schoolsNearby}
groupName={findGroupName(props.groupCode)}
groupCode={props.groupCode}
schools={schools}
shortenList={true}
/> : <Spacer
classSize="spacer-sm"
/> }
Expand Down
60 changes: 0 additions & 60 deletions src/containers/Results/SchoolList.js

This file was deleted.