1
- import React , { Component , Fragment } from 'react'
1
+ import React , { Component } from 'react'
2
2
import { connect } from 'react-redux'
3
3
import { Link } from 'react-router-dom'
4
4
import PropTypes from 'prop-types'
5
5
import AppBar from 'material-ui/AppBar'
6
6
import Toolbar from 'material-ui/Toolbar'
7
7
import Typography from 'material-ui/Typography'
8
- import Button from 'material-ui/Button'
9
- import Avatar from 'material-ui/Avatar'
10
8
11
9
import AuthActionCreator from '../../actions/auth'
12
10
import styles from './Header.scss'
@@ -20,45 +18,25 @@ class Header extends Component {
20
18
}
21
19
22
20
renderHeaderButtons ( ) {
23
- const { authenticated, user } = this . props
24
-
25
- if ( authenticated ) {
26
- return (
27
- < Fragment >
28
- { user . usertype === 'contact' &&
29
- < Button dense className = { this . getLinkStyles ( 'create-project' ) }
30
- component = { Link }
31
- to = "/create-project" >
32
- { 'CREATE PROJECT' }
33
- </ Button >
34
- }
35
- < Button dense className = { this . getLinkStyles ( ) }
36
- component = { Link }
37
- to = "/"
38
- onClick = { this . props . logout } >
39
- { 'LOGOUT' }
40
- </ Button >
41
- < Button dense className = { this . getLinkStyles ( 'profile' ) }
42
- component = { Link }
43
- to = "/profile" >
44
- < Avatar > { user . email . charAt ( 0 ) . toUpperCase ( ) } </ Avatar >
45
- </ Button >
46
- </ Fragment >
47
- )
21
+ if ( this . props . authenticated ) {
22
+ const authButtons = [
23
+ < Link key = "logout" to = '/' onClick = { this . props . logout } className = { this . getLinkStyles ( ) } > LOG OUT</ Link > ,
24
+ < Link key = "profile" to = "/profile" className = { this . getLinkStyles ( 'profile' ) } > PROFILE</ Link >
25
+ ]
26
+ if ( this . props . user . usertype === 'contact' ) {
27
+ return [
28
+ < Link key = "create-project" to = "/create-project" className = { this . getLinkStyles ( 'create-project' ) } > CREATE PROJECT</ Link > ,
29
+ ...authButtons
30
+ ]
31
+ } else {
32
+ return authButtons
33
+ }
48
34
} else {
49
35
return (
50
- < Fragment >
51
- < Button dense className = { this . getLinkStyles ( 'signup' ) }
52
- component = { Link }
53
- to = "/signup" >
54
- { 'SIGN UP' }
55
- </ Button >
56
- < Button dense className = { this . getLinkStyles ( 'login' ) }
57
- component = { Link }
58
- to = "/login" >
59
- { 'LOG IN' }
60
- </ Button >
61
- </ Fragment >
36
+ < div >
37
+ < Link key = "signup" to = "/signup" className = { this . getLinkStyles ( 'signup' ) } > SIGN UP</ Link >
38
+ < Link key = "login" to = '/login' className = { this . getLinkStyles ( 'login' ) } > LOG IN</ Link >
39
+ </ div >
62
40
)
63
41
}
64
42
}
@@ -71,21 +49,16 @@ class Header extends Component {
71
49
72
50
render ( ) {
73
51
return (
74
- < AppBar className = { styles . header }
75
- position = "static"
76
- color = "inherit"
77
- elevation = { 0 } >
78
- < Toolbar >
79
- < Typography className = { `${ styles . button } ${ styles . flex } ` }
80
- type = "title" color = "inherit"
81
- component = { Link }
82
- to = "/" >
83
- { 'calltocode' }
84
- </ Typography >
85
-
86
- { this . renderHeaderButtons ( ) }
87
- </ Toolbar >
88
- </ AppBar >
52
+ < div className = { styles . headerRoot } >
53
+ < AppBar position = "static" color = "inherit" elevation = { 0 } >
54
+ < Toolbar >
55
+ < Typography type = "title" color = "inherit" className = { styles . flex } >
56
+ < Link to = "/" className = { styles . button } > calltocode</ Link >
57
+ </ Typography >
58
+ { this . renderHeaderButtons ( ) }
59
+ </ Toolbar >
60
+ </ AppBar >
61
+ </ div >
89
62
)
90
63
}
91
64
}
@@ -94,7 +67,8 @@ function mapStateToProps (state) {
94
67
return {
95
68
authenticated : state . auth . authenticated ,
96
69
currentPage : state . routing . location . pathname ,
97
- user : state . user
70
+ user : state . user ,
71
+ login : state . login
98
72
}
99
73
}
100
74
@@ -106,7 +80,8 @@ Header.propTypes = {
106
80
authenticated : PropTypes . bool . isRequired ,
107
81
currentPage : PropTypes . string . isRequired ,
108
82
logout : PropTypes . func . isRequired ,
109
- user : PropTypes . object . isRequired
83
+ user : PropTypes . object . isRequired ,
84
+ login : PropTypes . object
110
85
}
111
86
112
87
export default connect ( mapStateToProps , mapDispatchToProps ) ( Header )
0 commit comments