blob: 50067c390d4c45524bc72fc79678ec669f972f37 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
import React from 'react';
import { PropTypes } from 'prop-types';
import { Helmet } from 'react-helmet';
import brand from 'ba-api/brand';
import { withStyles } from '@material-ui/core/styles';
import { Link } from 'react-router-dom';
import MenuContent from 'ba-api/menu';
import { PapperBlock } from 'ba-components';
import { Button } from '@material-ui/core';
const styles = {
link: {
display: 'block',
textTransform: 'capitalize'
}
};
function sortByKey(array, key) {
return array.sort((a, b) => {
const x = a[key]; const y = b[key];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
class Parent extends React.Component {
render() {
const title = brand.name;
const description = brand.desc;
const { classes } = this.props;
// Get Path Location
let parts = this.props.history.location.pathname.split('/');
const place = parts[parts.length - 1];
parts = parts.slice(1, parts.length - 1);
const menuItems = MenuContent
.find(obj => (
obj.key === place
));
const getMenus = menuArray => menuArray.map((item, index) => (
<Button
key={index.toString()}
color="primary"
component={Link}
className={classes.link}
to={item.link}
>
{item.name}
</Button>
));
return (
<div>
<Helmet>
<title>{title}</title>
<meta name="description" content={description} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="twitter:title" content={title} />
<meta property="twitter:description" content={description} />
</Helmet>
<PapperBlock title={place} desc="">
{menuItems !== undefined && getMenus(sortByKey(menuItems.child, 'key'))}
</PapperBlock>
</div>
);
}
}
Parent.propTypes = {
classes: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
};
export default withStyles(styles)(Parent);
|