|
|
|
@ -66,23 +66,29 @@ class RouteForm extends Component {
|
|
|
|
|
this.setState({justSubmit: true}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
componentWillMount() { |
|
|
|
|
const { props } = this |
|
|
|
|
static getDerivedStateFromProps(props, state) { |
|
|
|
|
// if form is ready, then nothing else to do
|
|
|
|
|
if (state.agency !== null || state.id !== null) |
|
|
|
|
return null |
|
|
|
|
|
|
|
|
|
const { agencyId, routeId } = props.match.params |
|
|
|
|
const { results } = props.route |
|
|
|
|
const ones = results.filter(ele => ele.route_id === routeId) |
|
|
|
|
if (ones.length > 0) { |
|
|
|
|
this.setState(ones[0]) |
|
|
|
|
props.updateBreadcrumb({ agencyId, routeId }) |
|
|
|
|
} else { |
|
|
|
|
const agencies = props.agency.results.filter(ele => ele.agency_id === agencyId) |
|
|
|
|
if (routeId === undefined |
|
|
|
|
&& state.agency === null |
|
|
|
|
&& props.agency.count > 0) { |
|
|
|
|
// this is for new route
|
|
|
|
|
const { results } = props.agency |
|
|
|
|
const agencies = results.filter(ele => ele.agency_id === agencyId) |
|
|
|
|
if (agencies.length > 0) { |
|
|
|
|
let d = {} |
|
|
|
|
d["agency_id"] = agencies[0].id |
|
|
|
|
this.setState(d) |
|
|
|
|
props.updateBreadcrumb({ agencyId, routeId: 'new' }) |
|
|
|
|
return { agency: agencies[0].id } |
|
|
|
|
} |
|
|
|
|
} else if (routeId !== undefined && state.id === null) { |
|
|
|
|
// this is for editing route
|
|
|
|
|
const ones = props.route.results.filter(ele => ele.route_id === routeId) |
|
|
|
|
props.updateBreadcrumb({ agencyId, routeId }) |
|
|
|
|
return ones[0] |
|
|
|
|
} |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
renderForm() { |
|
|
|
|