Skip to content

Instantly share code, notes, and snippets.

@trollknurr
Created June 2, 2016 09:49
Show Gist options
  • Save trollknurr/3e57a236b6bef19726050494fccf2b2f to your computer and use it in GitHub Desktop.
Save trollknurr/3e57a236b6bef19726050494fccf2b2f to your computer and use it in GitHub Desktop.
Вопрос react-router
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'))
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));
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