Skip to content

Commit 1bc0c3e

Browse files
committed
Header notification
1 parent 1d7a354 commit 1bc0c3e

File tree

5 files changed

+87
-26
lines changed

5 files changed

+87
-26
lines changed

src/components/back4App/Header/Header.react.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ export default class Header extends React.Component {
3737
.catch(error => {
3838
console.log("Error", error);
3939
});
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);
56+
});
4057
}
4158
render() {
4259
return (
@@ -49,11 +66,9 @@ export default class Header extends React.Component {
4966
}} />
5067
</div>
5168
</Media>
52-
5369
<a className={styles['logo-face']} href="http://www.back4app.com/">
5470
<Icon width={46} height={47} name='back4app-logo-face-blue' fill='#208AEC' />
5571
</a>
56-
5772
<Media query="(min-width: 680px)">
5873
<a className={styles['logo-text']} href="http://www.back4app.com/">
5974
<Icon width={134} height={53} name='back4app-logo-text-blue' fill='#208AEC' />
@@ -62,7 +77,7 @@ export default class Header extends React.Component {
6277

6378
</div>
6479
<div className={styles['right-side']}>
65-
<Nav items={navData.items} />
80+
<Nav items={navData.items} amountAppsWithExpiredPlans={this.state.amountAppsWithExpiredPlans} />
6681
<Media query="(min-width: 1100px)">
6782
<div className="ml-auto">
6883
<Dropdown items={navData.dropdownItems}>{this.state.username && `Hello, ${this.state.username}`}<i className="dropdown-icon zmdi zmdi-caret-down"></i></Dropdown>

src/components/back4App/HeaderNav/HeaderNav.react.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,29 @@ import HeaderNavItem from 'components/back4App/HeaderNavItem/HeaderNavItem.react
44

55
import styles from 'components/back4App/HeaderNav/HeaderNav.scss';
66

7-
const _renderHeaderMenuItems = items => items.map((item, index) => <HeaderNavItem key={index} index={index} {...item} />);
7+
class HeaderNav extends React.Component {
8+
9+
constructor(props) {
10+
super(props);
11+
}
12+
13+
renderHeaderMenuItems(items) {
14+
return items.map((item, index) => (index == 0) ?
15+
<HeaderNavItem key={index} index={index} {...item} notification={this.props.amountAppsWithExpiredPlans} /> :
16+
<HeaderNavItem key={index} index={index} {...item} />
17+
);
18+
}
819

9-
let HeaderNav = props => (
10-
<nav className={styles.nav}>
11-
<ul className={styles.menu}>
12-
{_renderHeaderMenuItems(props.items)}
13-
</ul>
14-
</nav>
15-
);
20+
render() {
21+
return (
22+
<nav className={styles.nav}>
23+
<ul className={styles.menu}>
24+
{this.renderHeaderMenuItems(this.props.items)}
25+
</ul>
26+
</nav>
27+
);
28+
}
1629

17-
export default HeaderNav;
30+
}
31+
32+
export default HeaderNav;

src/components/back4App/HeaderNavItem/HeaderNavItem.react.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,9 @@ import React, { Component } from 'react';
22

33
import { Link } from 'react-router';
44

5-
import styles from 'components/back4App/HeaderNavItem/HeaderNavItem.scss';
5+
import NotificationBullet from 'components/back4App/NotificationBullet/NotificationBullet.react';
66

7-
let NavItem = props => {
8-
return (
9-
<li className={`${styles.item} ${props.isCurrent ? styles.active : ''}`}>
10-
{
11-
props.url ? <a className={styles.label} href={props.url}>{props.label}</a> :
12-
props.pathname ? <Link className={styles.label} to={{ pathname:props.pathname }}>{props.label}</Link>:
13-
null
14-
}
15-
<i className={`${styles.icon} zmdi zmdi-caret-up`}></i>
16-
</li>
17-
);
18-
}
7+
import styles from 'components/back4App/HeaderNavItem/HeaderNavItem.scss';
198

209
export default class HeaderNavItem extends Component {
2110
constructor(props) {
@@ -31,6 +20,20 @@ export default class HeaderNavItem extends Component {
3120

3221
render() {
3322
let { isCurrent } = this.state;
34-
return NavItem({...this.props, isCurrent});
23+
let { notification = '', url, pathname, label } = this.props;
24+
25+
return (
26+
<li className={`${styles.item} ${isCurrent ? styles.active : ''}`}>
27+
{
28+
!!notification && <NotificationBullet notification={notification}></NotificationBullet>
29+
}
30+
{
31+
url ? <a className={styles.label} href={url}>{label}</a> :
32+
pathname ? <Link className={styles.label} to={{ pathname }}>{label}</Link> :
33+
null
34+
}
35+
<i className={`${styles.icon} zmdi zmdi-caret-up`}></i>
36+
</li>
37+
);
3538
}
3639
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
3+
import styles from 'components/back4App/NotificationBullet/NotificationBullet.scss';
4+
5+
const NotificationBullet = props => (
6+
<div className={styles['notification-bullet']}>
7+
{ props.notification }
8+
</div>
9+
);
10+
11+
export default NotificationBullet;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.notification-bullet {
2+
$size: 18px;
3+
position: absolute;
4+
display: block;
5+
cursor: default;
6+
background-color: red;
7+
width: $size;
8+
height: $size;
9+
border-radius: $size / 2;
10+
color: #FFF;
11+
font-size: 11px;
12+
font-weight: 600;
13+
text-align: center;
14+
padding-top: 1px;
15+
margin-top: -12px;
16+
margin-left: 64px;
17+
}

0 commit comments

Comments
 (0)