Commit 4936f83f authored by Florent Chehab's avatar Florent Chehab
Browse files

Info Provider added

parent e9c7e960
...@@ -21,9 +21,6 @@ import UniversityGeneralEditor from '../editors/UniversityGeneralEditor'; ...@@ -21,9 +21,6 @@ import UniversityGeneralEditor from '../editors/UniversityGeneralEditor';
import { import {
universitiesElFetchData, universitiesElFetchData,
universitiesElInvalidated, universitiesElInvalidated,
citiesFetchData,
countriesFetchData,
mainCampusesFetchData,
} from '../../../generated/actions'; } from '../../../generated/actions';
const styles = theme => ({ const styles = theme => ({
...@@ -95,11 +92,9 @@ class UniversityGeneral extends MyComponent { ...@@ -95,11 +92,9 @@ class UniversityGeneral extends MyComponent {
myRender() { myRender() {
const univInfos = this.getFetchedData('universitiesEl'); const univInfos = this.getFetchedData('universitiesEl');
const { classes } = this.props; const { classes } = this.props;
const { city, country } = this.getUnivCityAndCountry(this.props.univId);
const outsideData = { const outsideData = {
city: city.name, city: this.props.city.name,
country: country.name country: this.props.country.name
} }
return ( return (
...@@ -128,9 +123,6 @@ UniversityGeneral.propTypes = { ...@@ -128,9 +123,6 @@ UniversityGeneral.propTypes = {
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
return { return {
universitiesEl: state.universitiesEl, universitiesEl: state.universitiesEl,
countries: state.countries,
cities: state.cities,
mainCampuses: state.mainCampuses
}; };
}; };
...@@ -138,9 +130,6 @@ const mapDispatchToProps = (dispatch) => { ...@@ -138,9 +130,6 @@ const mapDispatchToProps = (dispatch) => {
return { return {
fetchData: { fetchData: {
universitiesEl: (univId) => dispatch(universitiesElFetchData(univId)), universitiesEl: (univId) => dispatch(universitiesElFetchData(univId)),
countries: () => dispatch(countriesFetchData()),
cities: () => dispatch(citiesFetchData()),
mainCampuses: () => dispatch(mainCampusesFetchData()),
}, },
invalidateData: () => dispatch(universitiesElInvalidated(true, true)) invalidateData: () => dispatch(universitiesElInvalidated(true, true))
}; };
......
import React from 'react';
import PropTypes from 'prop-types';
import compose from 'recompose/compose';
import { connect } from "react-redux";
import __pick from 'lodash/pick';
import MyComponent from '../../MyComponent';
import {
citiesFetchData,
countriesFetchData,
mainCampusesFetchData,
} from '../../../generated/actions';
class InfoProvider extends MyComponent {
myRender() {
const { city, country } = this.getUnivCityAndCountry(this.props.univId);
const propsToAdd = {
cityId: city.id,
countryId: country.id,
city: city,
country: country,
univId: this.props.univId
}
return (<this.props.renderAndAddPropsTo {...propsToAdd} />)
}
}
InfoProvider.propTypes = {
univId: PropTypes.string.isRequired
};
const mapStateToProps = (state) => {
return {
countries: state.countries,
cities: state.cities,
mainCampuses: state.mainCampuses
};
};
const mapDispatchToProps = (dispatch) => {
return {
fetchData: {
countries: () => dispatch(countriesFetchData()),
cities: () => dispatch(citiesFetchData()),
mainCampuses: () => dispatch(mainCampusesFetchData()),
},
};
};
export default compose(
connect(mapStateToProps, mapDispatchToProps)
)(InfoProvider);
\ No newline at end of file
...@@ -12,6 +12,7 @@ import UniversityGeneral from '../modules/UniversityGeneral'; ...@@ -12,6 +12,7 @@ import UniversityGeneral from '../modules/UniversityGeneral';
import UniversitySemestersDates from '../modules/UniversitySemestersDates'; import UniversitySemestersDates from '../modules/UniversitySemestersDates';
import UniversityDri from '../modules/UniversityDri'; import UniversityDri from '../modules/UniversityDri';
import withWidth, { isWidthUp } from '@material-ui/core/withWidth'; import withWidth, { isWidthUp } from '@material-ui/core/withWidth';
import InfoProvider from '../shared/InfoProvider';
const styles = theme => ({ const styles = theme => ({
root1: { root1: {
...@@ -39,10 +40,16 @@ class GeneralInfoTab extends MyComponent { ...@@ -39,10 +40,16 @@ class GeneralInfoTab extends MyComponent {
<div style={{ flexGrow: 8, paddingRight: 2 * theme.spacing.unit }}> <div style={{ flexGrow: 8, paddingRight: 2 * theme.spacing.unit }}>
<Grid container direction='column' > <Grid container direction='column' >
<Grid item xs style={{ paddingBottom: 2 * theme.spacing.unit }} > <Grid item xs style={{ paddingBottom: 2 * theme.spacing.unit }} >
<UniversityGeneral visible={this.props.visible} univId={this.props.univId} /> <InfoProvider
univId={this.props.univId}
renderAndAddPropsTo={UniversityGeneral}
/>
</Grid> </Grid>
<Grid item xs> <Grid item xs>
<UniversityDri visible={this.props.visible} univId={this.props.univId} /> <InfoProvider
univId={this.props.univId}
renderAndAddPropsTo={UniversityDri}
/>
</Grid> </Grid>
</Grid> </Grid>
</div> </div>
...@@ -66,10 +73,16 @@ class GeneralInfoTab extends MyComponent { ...@@ -66,10 +73,16 @@ class GeneralInfoTab extends MyComponent {
<Grid container spacing={16} > <Grid container spacing={16} >
<Grid item xs={12}> <Grid item xs={12}>
<UniversityGeneral visible={this.props.visible} univId={this.props.univId} /> <InfoProvider
univId={this.props.univId}
renderAndAddPropsTo={UniversityGeneral}
/>
</Grid> </Grid>
<Grid item xs={12}> <Grid item xs={12}>
<UniversityDri visible={this.props.visible} univId={this.props.univId} /> <InfoProvider
univId={this.props.univId}
renderAndAddPropsTo={UniversityDri}
/>
</Grid> </Grid>
<Grid item xs={12}> <Grid item xs={12}>
<UniversitySemestersDates visible={this.props.visible} univId={this.props.univId} /> <UniversitySemestersDates visible={this.props.visible} univId={this.props.univId} />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment