@@ -11,18 +11,48 @@ import styles from 'components/back4App/Header/Header.scss';
11
11
import navData from 'components/back4App/Header/headerNavData' ;
12
12
13
13
export default class Header extends React . Component {
14
+ constructor ( props ) {
15
+ super ( props ) ;
16
+
17
+ this . state = {
18
+ username : null
19
+ } ;
20
+ }
14
21
componentWillMount ( ) {
15
22
/*
16
- - Thi-s resource should be implemented following parse-dashboard community standards (using flux).
23
+ - This resource should be implemented following parse-dashboard community standards (using flux).
17
24
But it was actualy not possible to use the subscribeTo decorator in the Header component
18
25
before the App was injected in the router. This is a simple temporary solution.
19
26
*/
20
27
fetch ( 'https://dashboard.back4app.com/me' , {
21
28
method : 'GET' ,
22
29
credentials : 'include'
23
30
} )
31
+ . then ( response => response . json ( ) )
24
32
. then ( response => {
25
- console . log ( response . json ( ) ) ;
33
+ this . setState ( {
34
+ username : response . username . split ( '@' ) [ 0 ]
35
+ } ) ;
36
+ } )
37
+ . catch ( error => {
38
+ console . log ( "Error" , error ) ;
39
+ } ) ;
40
+
41
+ fetch ( 'https://dashboard.back4app.com/listApps' , {
42
+ method : 'GET' ,
43
+ credentials : 'include'
44
+ } )
45
+ . then ( response => response . json ( ) )
46
+ . then ( apps => {
47
+ let amountAppsWithExpiredPlans = apps . reduce ( ( accumulator , currentValue , currentIndex , array ) => {
48
+ return accumulator + ( currentValue . planCloudColor === 'red' ? 1 : 0 ) ;
49
+ } , 0 ) ;
50
+ this . setState ( {
51
+ amountAppsWithExpiredPlans
52
+ } ) ;
53
+ } )
54
+ . catch ( function ( error ) {
55
+ console . log ( 'error' , error ) ;
26
56
} ) ;
27
57
}
28
58
render ( ) {
@@ -32,33 +62,28 @@ export default class Header extends React.Component {
32
62
< Media query = "(max-width: 1099px)" >
33
63
< div className = { styles [ 'hamburger-wrapper' ] } >
34
64
< HamburgerButton onClick = { ( ) => {
35
- props . sidebarToggle ( ) ;
65
+ this . props . sidebarToggle ( ) ;
36
66
} } />
37
67
</ div >
38
68
</ Media >
39
- < Media query = "(min-width: 1100px)" >
40
- < a className = { styles [ 'logo-face' ] } href = "http://www.back4app.com/" >
41
- < Icon width = { 46 } height = { 47 } name = 'back4app-logo-face-blue' fill = '#208AEC' />
69
+ < a className = { styles [ 'logo-face' ] } href = "http://www.back4app.com/" >
70
+ < Icon width = { 46 } height = { 47 } name = 'back4app-logo-face-blue' fill = '#208AEC' />
71
+ </ a >
72
+ < Media query = "(min-width: 680px)" >
73
+ < a className = { styles [ 'logo-text' ] } href = "http://www.back4app.com/" >
74
+ < Icon width = { 134 } height = { 53 } name = 'back4app-logo-text-blue' fill = '#208AEC' />
42
75
</ a >
43
76
</ Media >
44
- < a className = { styles [ 'logo-text' ] } href = "http://www.back4app.com/" >
45
- < Icon width = { 134 } height = { 53 } name = 'back4app-logo-text-blue' fill = '#208AEC' />
46
- </ a >
47
- </ div >
48
77
78
+ </ div >
49
79
< div className = { styles [ 'right-side' ] } >
50
-
51
- < Media query = "(min-width: 1100px)" >
52
- < Nav items = { navData . items } />
53
- </ Media >
54
-
80
+ < Nav items = { navData . items } amountAppsWithExpiredPlans = { this . state . amountAppsWithExpiredPlans } />
55
81
< Media query = "(min-width: 1100px)" >
56
82
< div className = "ml-auto" >
57
- < Dropdown items = { navData . dropdownItems } > Hello, TBrayner! < i className = "dropdown-icon zmdi zmdi-caret-down" > </ i > </ Dropdown >
83
+ < Dropdown items = { navData . dropdownItems } > { this . state . username && ` Hello, ${ this . state . username } ` } < i className = "dropdown-icon zmdi zmdi-caret-down" > </ i > </ Dropdown >
58
84
< Button color = "green" weight = "700" url = "https://dashboard.back4app.com/apps/#!/apps/new" > NEW APP</ Button >
59
85
</ div >
60
86
</ Media >
61
-
62
87
</ div >
63
88
</ header >
64
89
) ;
0 commit comments