Last active
December 19, 2018 17:44
-
-
Save cevr/57c236fcaff69ea454d5dbf83ffcb647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getObjectives() { | |
return dispatch => { | |
dispatch(isLoading()); | |
axios | |
.get('url') | |
.then(res => { | |
dispatch(setObjectives(res.data)) | |
dispatch(isNotLoading()); | |
}) | |
.catch(err => { | |
console.log(err); | |
}); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Child extends React.Component { | |
state = { | |
columns: ObjectivesTableLabel, | |
objectives: [], | |
}; | |
componentDidMount() { | |
this.props.getObjectives(); | |
} | |
render() { | |
let { columns } = this.state; | |
const { objectives } = this.props; | |
return ( | |
<div> | |
.... | |
</div> | |
); | |
} | |
} | |
const mapStateToProps = state => ({ | |
objectives: state.objectives.objectives, | |
currentItem: state.dailyPlan.currentItem, | |
}); | |
const mapDisaptchToProps = { | |
getObjectives, | |
}; | |
export default connect( | |
mapStateToProps, | |
mapDisaptchToProps, | |
)(Objectives); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent extends Component { | |
render() { | |
const { classes, isLoading } = this.props; | |
return ( | |
<React.Fragment> | |
<Grid item xs={9}> | |
<div className={classes.dailyplan}> | |
{isLoading ? ( | |
<LoadingSpinner /> | |
) : ( | |
<Switch> | |
<Route path="/dailyplan/:id/configuration-3/objectives" component={Child} /> | |
</Switch> | |
)} | |
</div> | |
</Grid> | |
</React.Fragment> | |
); | |
} | |
} | |
const mapStateToProps = state => ({ | |
dailyPlanList: state.dailyPlan.dailyPlanList, | |
isLoading: state.indicators.isLoading, | |
currentItem: state.dailyPlan.currentItem, | |
optimizationStatus: state.dailyPlan.optimizationStatus, | |
}); | |
const mapDispatchToProps = { | |
getItems, | |
setCurrentItem, | |
getOptimizationStatus, | |
setOptimizationStatus, | |
getObjectives, | |
}; | |
const StyledDailyPlan = withStyles(styles)(DailyPlan); | |
export default connect( | |
mapStateToProps, | |
mapDispatchToProps, | |
)(StyledDailyPlan); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment