web-base/admin/src/header.js

89 lines
3.6 KiB
JavaScript
Raw Normal View History

2020-06-14 12:38:35 +02:00
import * as React from "react";
2020-06-15 23:10:14 +02:00
import Icon from "./elements/icon";
2020-06-15 00:37:29 +02:00
import {useState} from "react";
import {getPeriodString} from "./global";
2020-06-15 23:10:14 +02:00
import {Link} from "react-router-dom";
2020-06-14 12:38:35 +02:00
2020-06-15 00:37:29 +02:00
export default function Header(props) {
2020-06-14 12:38:35 +02:00
2020-06-15 00:37:29 +02:00
const parent = {
notifications: props.notifications || { },
};
2020-06-14 12:38:35 +02:00
2020-06-15 00:37:29 +02:00
const [dropdownVisible, showDropdown] = useState(false);
const mailIcon = <Icon icon={"envelope"} type={"fas"} />;
let notificationCount = Object.keys(parent.notifications).length;
let notificationText = "No new notifications";
if(notificationCount === 1) {
notificationText = "1 new notification";
} else if(notificationCount > 1) {
notificationText = notificationCount + " new notification";
}
let notificationItems = [];
for (let uid in parent.notifications) {
const notification = parent.notifications[uid];
const createdAt = getPeriodString(notification.created_at);
notificationItems.push(
2020-06-15 23:10:14 +02:00
<Link to={"/admin/logs?notification=" + uid} className={"dropdown-item"} key={"notification-" + uid}>
2020-06-15 00:37:29 +02:00
{mailIcon}
<span className={"ml-2"}>{notification.title}</span>
<span className={"float-right text-muted text-sm"}>{createdAt}</span>
2020-06-15 23:10:14 +02:00
</Link>);
2020-06-15 00:37:29 +02:00
}
return (
<nav className={"main-header navbar navbar-expand navbar-white navbar-light"}>
2020-06-14 12:38:35 +02:00
{/*Left navbar links */}
<ul className={"navbar-nav"}>
<li className={"nav-item"}>
<a href={"#"} className={"nav-link"} data-widget={"pushmenu"} role={"button"}>
<Icon icon={"bars"}/>
</a>
</li>
<li className={"nav-item d-none d-sm-inline-block"}>
2020-06-15 23:10:14 +02:00
<Link to={"/admin/dashboard"} className={"nav-link"}>
2020-06-14 12:38:35 +02:00
Home
2020-06-15 23:10:14 +02:00
</Link>
2020-06-14 12:38:35 +02:00
</li>
</ul>
{/* SEARCH FORM */}
<form className={"form-inline ml-3"}>
<div className={"input-group input-group-sm"}>
<input className={"form-control form-control-navbar"} type={"search"} placeholder={"Search"} aria-label={"Search"} />
<div className={"input-group-append"}>
<button className={"btn btn-navbar"} type={"submit"}>
<Icon icon={"search"}/>
</button>
</div>
</div>
</form>
{/* Right navbar links */}
<ul className={"navbar-nav ml-auto"}>
2020-06-14 22:35:01 +02:00
2020-06-14 12:38:35 +02:00
{/* Notifications Dropdown Menu */}
2020-06-15 00:37:29 +02:00
<li className={"nav-item dropdown"} onClick={() => showDropdown(!dropdownVisible)}>
2020-06-14 12:38:35 +02:00
<a href={"#"} className={"nav-link"} data-toggle={"dropdown"}>
2020-06-14 22:35:01 +02:00
<Icon icon={"bell"} type={"far"} />
2020-06-14 12:38:35 +02:00
<span className={"badge badge-warning navbar-badge"}>
{notificationCount}
</span>
</a>
2020-06-15 00:37:29 +02:00
<div className={"dropdown-menu dropdown-menu-lg dropdown-menu-right " + (dropdownVisible ? " show" : "")}>
2020-06-14 12:38:35 +02:00
<span className={"dropdown-item dropdown-header"}>
{notificationText}
</span>
2020-06-15 00:37:29 +02:00
{notificationItems}
2020-06-14 12:38:35 +02:00
<div className={"dropdown-divider"} />
2020-06-15 23:10:14 +02:00
<Link to={"/admin/logs"} className={"dropdown-item dropdown-footer"}>See All Notifications</Link>
2020-06-14 12:38:35 +02:00
</div>
</li>
</ul>
</nav>
2020-06-15 00:37:29 +02:00
)
2020-06-14 12:38:35 +02:00
}