Created
June 2, 2016 09:49
-
-
Save trollknurr/3e57a236b6bef19726050494fccf2b2f to your computer and use it in GitHub Desktop.
Вопрос react-router
This file contains hidden or 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
render(h(Provider, { | |
store: store | |
}, [ | |
div([ | |
h(Router, { | |
history: browserHistory | |
}, | |
[h(Route, { | |
path: "oi/:orderID/", | |
name: "Операторский интерфейс", | |
component: OiLayout | |
}, [h(IndexRedirect, {to: 'client'}), | |
h(Route, { | |
path: 'client', | |
name: 'Клиент', | |
component: ClientLayout | |
}), | |
h(Route, { | |
path: 'goods', | |
name: 'Товары', | |
component: GoodsLayout | |
}) | |
]) | |
]), | |
h(NotificationContainer) | |
]), | |
]), document.getElementById('main')) |
This file contains hidden or 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
const tabsByName = { | |
client: (id) => { | |
return li(".client", [ | |
h(Link, { | |
activeClassName: 'active', | |
to: `/oi/${id}/client/` | |
}, ['Заказчик']) | |
]) | |
}, | |
goods: (id) => { | |
return li(".goods", [ | |
h(Link, { | |
activeClassName: 'active', | |
to: `/oi/${id}/goods/` | |
}, ['Товары']) | |
]) | |
}, | |
delivery: (id) => { | |
return li(".delivery", [ | |
h(Link, { | |
activeClassName: 'active', | |
to: `/oi/${id}/delivery/` | |
}, ['Доставка']) | |
]) | |
}, | |
passport: (id) => { | |
return li(".passport", [ | |
h(Link, { | |
activeClassName: 'active', | |
to: `/oi/${id}/passport/` | |
}, ['Паспорта']) | |
]) | |
}, | |
payment: (id) => { | |
return li(".payment", [ | |
h(Link, { | |
activeClassName: 'active', | |
to: `/oi/${id}/payment/` | |
}, ['Оплата']) | |
]) | |
}, | |
final: (id) => { | |
return li(".final", [ | |
h(Link, { | |
activeClassName: 'active', | |
to: `/oi/${id}/final/` | |
}, ['Отправка']) | |
]) | |
}, | |
history: (id) => { | |
return li(".history", [ | |
h(Link, { | |
activeClassName: 'active', | |
to: `/oi/${id}/history/` | |
}, ['История']) | |
]) | |
} | |
} | |
const tabsByMode = { | |
b2c: ['client', 'goods', 'delivery', 'passport', 'payment', 'final', 'history'], | |
preorder: ['client', 'goods', 'final', 'history'] | |
} | |
class OiHeader extends Component { | |
constructor(props) { | |
super() | |
} | |
render() { | |
let { | |
id, | |
number, | |
created, | |
modified, | |
mode | |
} = this.props.order | |
var tabs = [] | |
if (mode) { | |
let tabsName = tabsByMode[mode] | |
tabs = R.map((tabName) => tabsByName[tabName](id), tabsName) | |
} | |
return ( | |
div([ | |
div('.container', [ | |
ul('.list-inline', [ | |
li([b('Заказ №')]), | |
li(number), | |
li([b('Дата создания')]), | |
li(created), | |
li([b('Дата модификации')]), | |
li(modified) | |
]), | |
]), | |
div(".container-fluid.text-center.container_menu", [ | |
ul(".nav.nav-pills.center_ul", tabs) | |
]) | |
]) | |
); | |
} | |
} | |
function mapStateToProps(state) { | |
return { | |
order: state.order | |
}; | |
} | |
export default withRouter(connect(mapStateToProps)(OiHeader)); |
This file contains hidden or 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 OiLayout extends Component { | |
componentWillMount() { | |
this.props.dispatch(fetchOrder(this.props.params.orderID)) | |
} | |
render() { | |
return ( | |
div('.order_layout', [ | |
h(OiHeader), | |
this.props.children | |
]) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment