@@ -2,12 +2,22 @@ import React, { Component } from 'react';
22import { NavLink , withRouter } from 'react-router-dom' ;
33import AppBar from '@material-ui/core/AppBar' ;
44import Toolbar from '@material-ui/core/Toolbar' ;
5+ import IconButton from '@material-ui/core/IconButton' ;
56import Typography from '@material-ui/core/Typography' ;
6- import SearchInput from 'components/SearchInput ' ;
7+ import jwt from 'jsonwebtoken ' ;
78import { withStyles } from '@material-ui/core/styles' ;
8-
9+ import MenuIcon from '@material-ui/icons/Menu' ;
10+ import Popper from '@material-ui/core/Popper' ;
911import ava from 'containers/AccountPage/images/3.jpg' ;
10- import { Avatar , Button } from '@material-ui/core' ;
12+ import {
13+ Avatar ,
14+ Button ,
15+ MenuItem ,
16+ MenuList ,
17+ Grow ,
18+ ClickAwayListener ,
19+ Paper ,
20+ } from '@material-ui/core' ;
1121
1222const styles = ( ) => ( {
1323 root : {
@@ -23,14 +33,33 @@ const styles = () => ({
2333 } ,
2434 logo : {
2535 color : '#000' ,
26- width : 193 ,
2736 textDecoration : 'none' ,
2837 } ,
2938} ) ;
3039
3140class Header extends Component {
41+ state = {
42+ open : false ,
43+ } ;
44+
45+ handleToggle = ( ) => {
46+ this . setState ( state => ( { open : ! state . open } ) ) ;
47+ } ;
48+
49+ handleClose = event => {
50+ if ( this . anchorEl . contains ( event . target ) ) {
51+ return ;
52+ }
53+
54+ this . setState ( { open : false } ) ;
55+ } ;
56+
3257 render ( ) {
3358 const { classes } = this . props ;
59+ const { open } = this . state ;
60+
61+ const fromToken = jwt . decode ( localStorage . token , { complete : true } ) ;
62+
3463 return (
3564 < div className = { classes . root } >
3665 < AppBar position = "static" color = "default" className = { classes . appBar } >
@@ -41,31 +70,149 @@ class Header extends Component {
4170 display : 'flex' ,
4271 justifyContent : 'space-between' ,
4372 padding : 0 ,
73+ zIndex : 1000 ,
4474 } }
4575 >
4676 < NavLink to = "/" className = { classes . logo } >
4777 < Typography variant = "h5" color = "inherit" >
4878 Consensus
4979 </ Typography >
5080 </ NavLink >
51- < SearchInput />
52- { localStorage . name ? (
53- < NavLink
54- to = { `/account/${ localStorage . id } ` }
55- style = { { color : '#000' , textDecoration : 'none' } }
56- >
57- < Avatar style = { { backgroundColor : '#212121' } } >
58- { localStorage . name [ 0 ] }
59- </ Avatar >
60- </ NavLink >
81+ { localStorage . token ? (
82+ < div style = { { display : 'flex' , alignItems : 'center' } } >
83+ < NavLink
84+ to = { `/account/${ fromToken . payload . _id } ` }
85+ style = { {
86+ color : '#000' ,
87+ textDecoration : 'none' ,
88+ marginRight : '1rem' ,
89+ } }
90+ >
91+ < Avatar style = { { backgroundColor : '#212121' } } >
92+ { fromToken . payload . name [ 0 ] }
93+ </ Avatar >
94+ </ NavLink >
95+ < IconButton
96+ buttonRef = { node => {
97+ this . anchorEl = node ;
98+ } }
99+ aria-owns = { open ? 'menu-list-grow' : null }
100+ aria-haspopup = "true"
101+ onClick = { this . handleToggle }
102+ >
103+ < MenuIcon color = "primary" />
104+ </ IconButton >
105+ </ div >
61106 ) : (
62- < Button
63- variant = "outlined"
64- onClick = { ( ) => this . props . history . push ( '/login' ) }
65- >
66- Вход и регистрация
67- </ Button >
107+ < div >
108+ < Button
109+ variant = "outlined"
110+ onClick = { ( ) => this . props . history . push ( '/login' ) }
111+ style = { { marginRight : '1rem' } }
112+ >
113+ Вход и регистрация
114+ </ Button >
115+ < IconButton
116+ buttonRef = { node => {
117+ this . anchorEl = node ;
118+ } }
119+ aria-owns = { open ? 'menu-list-grow' : null }
120+ aria-haspopup = "true"
121+ onClick = { this . handleToggle }
122+ >
123+ < MenuIcon color = "primary" />
124+ </ IconButton >
125+ </ div >
68126 ) }
127+
128+ < Popper open = { open } anchorEl = { this . anchorEl } transition >
129+ { ( { TransitionProps, placement } ) => (
130+ < Grow
131+ { ...TransitionProps }
132+ style = { {
133+ transformOrigin :
134+ placement === 'bottom' ? 'center top' : 'center bottom' ,
135+ } }
136+ >
137+ < Paper >
138+ < ClickAwayListener onClickAway = { this . handleClose } >
139+ < MenuList >
140+ < MenuItem style = { { padding : '0' } } >
141+ < NavLink
142+ to = "/account/5d05d5d5ee5aaf259cbc4e16"
143+ style = { {
144+ color : '#000' ,
145+ textDecoration : 'none' ,
146+ width : '100%' ,
147+ height : '100%' ,
148+ padding : '8px 16px' ,
149+ } }
150+ >
151+ Дизайн
152+ </ NavLink >
153+ </ MenuItem >
154+ < MenuItem style = { { padding : '0' } } >
155+ < NavLink
156+ to = "/account/5d05d65a39e79f25a4a17519"
157+ style = { {
158+ color : '#000' ,
159+ textDecoration : 'none' ,
160+ width : '100%' ,
161+ height : '100%' ,
162+ padding : '8px 16px' ,
163+ } }
164+ >
165+ Брендбук
166+ </ NavLink >
167+ </ MenuItem >
168+ < MenuItem style = { { padding : '0' } } >
169+ < NavLink
170+ to = "/account/5d05d5aeee5aaf259cbc4e15"
171+ style = { {
172+ color : '#000' ,
173+ textDecoration : 'none' ,
174+ width : '100%' ,
175+ height : '100%' ,
176+ padding : '8px 16px' ,
177+ } }
178+ >
179+ Айдентика
180+ </ NavLink >
181+ </ MenuItem >
182+ < MenuItem style = { { padding : '0' } } >
183+ < NavLink
184+ to = "/account/5d05d62939e79f25a4a17518"
185+ style = { {
186+ color : '#000' ,
187+ textDecoration : 'none' ,
188+ width : '100%' ,
189+ height : '100%' ,
190+ padding : '8px 16px' ,
191+ } }
192+ >
193+ Логотипирование
194+ </ NavLink >
195+ </ MenuItem >
196+ < MenuItem style = { { padding : '0' } } >
197+ < NavLink
198+ to = "/account/5d09259240e14e4472ffd906"
199+ style = { {
200+ color : '#000' ,
201+ textDecoration : 'none' ,
202+ width : '100%' ,
203+ height : '100%' ,
204+ padding : '8px 16px' ,
205+ } }
206+ >
207+ Колористика и цветоведение
208+ </ NavLink >
209+ </ MenuItem >
210+ </ MenuList >
211+ </ ClickAwayListener >
212+ </ Paper >
213+ </ Grow >
214+ ) }
215+ </ Popper >
69216 </ Toolbar >
70217 </ AppBar >
71218 </ div >
0 commit comments