forked from Terkea/django_react_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayout.js
84 lines (78 loc) · 2.96 KB
/
Layout.js
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
73
74
75
76
77
78
79
80
81
82
83
84
import React from 'react';
import { Layout, Menu } from 'antd';
import { Link, withRouter, useLocation } from 'react-router-dom';
import { connect } from 'react-redux';
import * as actions from '../store/actions/user';
import { clearNotifications, runNotifications } from '../Helpers/notificationHelpers';
const { Header, Content, Footer } = Layout;
const CustomLayout = props => {
const getFirstPath = () => {
// This function can be used to reliably get the first part of the the path in an pathname
let i = 1;
let firstPath;
do {
firstPath = '/' + pathname.split("/")[i];
i++;
}
while (firstPath === "");
return firstPath
}
const { pathname } = useLocation()
const firstPath = getFirstPath();
return (
<Layout className="layout" style={{ minHeight: '100vh', overflow: "auto" }}>
<Header>
<div className="logo" />
<Menu
theme="dark"
mode="horizontal"
selectedKeys={[firstPath]}
style={{ lineHeight: '64px' }}
>
<Menu.Item key="/">
<Link to="/">Home</Link>
</Menu.Item>
{
props.isAuthenticated ?
<Menu.Item key="/my_profile">
<Link to="/my_profile/">My Profile</Link>
</Menu.Item>
:
<Menu.Item key="/login">
<Link to="/login/" onClick={clearNotifications}>Login</Link>
</Menu.Item>
}
{
props.isAuthenticated ?
<Menu.Item key="/logout" onClick={() => {
clearNotifications();
props.logout(runNotifications);
props.history.push('/')
}
}>
Logout
</Menu.Item>
:
< Menu.Item key="/signup">
<Link to="/signup/" onClick={clearNotifications}>Sign up</Link>
</Menu.Item>
}
</Menu>
</Header>
<Content style={{ padding: '0 50px' }}>
<div style={{ padding: 24 }}>
{props.children}
</div>
</Content>
<Footer style={{ textAlign: 'center' }}>
Footer
</Footer>
</Layout>
);
}
const mapDispatchToProps = dispatch => {
return {
logout: (callback) => dispatch(actions.authLogout(callback))
}
}
export default withRouter(connect(null, mapDispatchToProps)(CustomLayout));