trc-client-core
Version:
The core of the TRC Client
79 lines (62 loc) • 2.26 kB
JSX
import ErrorMessage from 'trc-client-core/src/components/ErrorMessage';
import GapReport from 'trc-client-core/src/report/GapReport';
import LegendWarranty from 'trc-client-core/src/copy/learningPlan/LegendWarranty.md';
import Markdown from 'trc-client-core/src/components/Markdown';
import React from 'react';
import ToyotaForLifeIntro from 'trc-client-core/src/copy/learningPlan/ToyotaForLifeIntro.md';
import {connect} from 'react-redux';
const PRETTY_NAMES = {
'toyota-for-life': 'Toyota For Life',
technical_career_plan: 'Technical',
warranty_admin_plan: 'Warranty'
};
class GapReportHandler extends React.Component {
constructor(props) {
super(props);
this.displayName = 'GapReportHandler';
}
getChildContext() {
var learningPlanId = this.getLearningPlanId();
return {
learningPlanId,
gapReportName: PRETTY_NAMES[learningPlanId]
};
}
pathnameContains(str) {
return this.props.location.pathname.indexOf(str) >= 0;
}
getLearningPlanId() {
if (this.props.params.pathwayId) {
return this.props.params.pathwayId;
}
if (this.pathnameContains('toyota-for-life')) {
return 'toyota-for-life';
}
}
renderLegend() {
switch(this.props.params.pathwayId) {
case 'warranty_admin_plan':
return <Markdown html={LegendWarranty.__content} className="padding-bottom2"/>;
}
if(this.props.location.pathname.indexOf('toyota-for-life') >= 0) {
return <Markdown html={ToyotaForLifeIntro.__content} className="padding-bottom2"/>;
}
}
render() {
var {error} = this.props;
if(error) {
return <ErrorMessage code={error.statusCode}/>;
}
var learningPlanId = this.getLearningPlanId()
return <GapReport
legend={this.renderLegend()}
learningPlanId={learningPlanId}
{...this.props}
/>;
}
}
GapReportHandler.childContextTypes = {
learningPlanId: React.PropTypes.string,
gapReportName: React.PropTypes.string
}
export default connect(state => ({error: state.learningPlan.get('error')}))(GapReportHandler);