import React, {useState} from 'react'; import {BrowserView, MobileView} from "react-device-detect"; import {Link} from 'react-router-dom'; import { useTheme } from '@material-ui/core/styles'; import { Chip, Badge, Typography, Paper, Tooltip, List, Avatar, Menu, ListItem, MenuItem, Select, Button, IconButton, Grid } from '@material-ui/core'; import { MeetingRoom as MeetingRoomIcon, Settings as SettingsIcon, Notifications as NotificationsIcon, Home as HomeIcon, Polymer as PolymerIcon, Apps as AppsIcon, Description as DescriptionIcon} from '@material-ui/icons'; //import LogoutIcon from '@mui/icons-material/Logout'; import { useAlert } from "react-alert"; const hoverColor = "#f85a3e" const hoverOutColor = "#e8eaf6" const Header = props => { const { globalUrl, setNotifications, notifications, isLoggedIn, removeCookie, homePage, isLoaded, userdata, cookies } = props; const theme = useTheme(); const [HomeHoverColor, setHomeHoverColor] = useState(hoverOutColor); const [SoarHoverColor, setSoarHoverColor] = useState(hoverOutColor); const [LoginHoverColor, setLoginHoverColor] = useState(hoverOutColor); const [DocsHoverColor, setDocsHoverColor] = useState(hoverOutColor); const [HelpHoverColor, setHelpHoverColor] = useState(hoverOutColor); const [anchorEl, setAnchorEl] = React.useState(null); const [anchorElAvatar, setAnchorElAvatar] = React.useState(null); const alert = useAlert() const hrefStyle = { color: hoverOutColor, textDecoration: "none", } const handleClose = () => { setAnchorEl(null); setAnchorElAvatar(null); }; const clearNotifications = () => { // Don't really care about the logout fetch(`${globalUrl}/api/v1/notifications/clear`, { credentials: "include", method: 'GET', headers: { 'Content-Type': 'application/json', }, }) .then(function(response) { if (response.status !== 200) { console.log("Error in response") } return response.json(); }).then(function(responseJson) { if (responseJson.success === true) { setNotifications([]) handleClose() } else { alert.error("Failed dismissing notifications. Please try again later.") } }) .catch(error => { console.log("error in notification dismissal: ", error) //removeCookie("session_token", {path: "/"}) }) } const dismissNotification = (alert_id) => { // Don't really care about the logout fetch(`${globalUrl}/api/v1/notifications/${alert_id}/markasread`, { credentials: "include", method: 'GET', headers: { 'Content-Type': 'application/json', }, }) .then(function(response) { if (response.status !== 200) { console.log("Error in response") } return response.json(); }).then(function(responseJson) { if (responseJson.success === true) { const newNotifications = notifications.filter(data => data.id !== alert_id) console.log("NEW NOTIFICATIONS: ", newNotifications) setNotifications(newNotifications) } else { alert.error("Failed dismissing notification. Please try again later.") } }) .catch(error => { console.log("error in notification dismissal: ", error) //removeCookie("session_token", {path: "/"}) }) } // DEBUG HERE const handleClickLogout = () => { console.log("COOKIES: ", cookies, "Remover: ", removeCookie) // Don't really care about the logout fetch(globalUrl+"/api/v1/logout", { credentials: "include", method: 'POST', headers: { 'Content-Type': 'application/json', }, }) .then(() => { // Log out anyway //cookies.remove("session_token") //window.location.pathname = "/" console.log("Should've logged out") removeCookie("session_token", {path: "/"}) removeCookie("session_token", {path: "/workflows"}) window.location.reload() }) .catch(error => { console.log("Error in logout: ", error) removeCookie("session_token", {path: "/"}) window.location.reload() //removeCookie("session_token", {path: "/"}) }) } const handleClickChangeOrg = (orgId) => { // Don't really care about the logout //name: org.name, //orgId = "asd" const data = { org_id: orgId, } fetch(`${globalUrl}/api/v1/orgs/${orgId}/change`, { mode: 'cors', method: 'POST', body: JSON.stringify(data), credentials: 'include', crossDomain: true, withCredentials: true, headers: { 'Content-Type': 'application/json; charset=utf-8', }, }) .then(function(response) { if (response.status !== 200) { console.log("Error in response") } return response.json(); }).then(function(responseJson) { if (responseJson.success !== undefined && responseJson.success) { setTimeout(() => { window.location.reload() }, 2000) alert.success("Successfully changed active organization - refreshing!") } else { alert.error("Failed changing org: ", responseJson.reason) } }) .catch(error => { console.log("error changing: ", error) //removeCookie("session_token", {path: "/"}) }) } // Rofl this is weird const handleDocsHover = () => { setDocsHoverColor(hoverColor) } const handleDocsHoverOut = () => { setDocsHoverColor(hoverOutColor) } const handleHomeHover = () => { setHomeHoverColor(hoverColor) } const handleHelpHover = () => { setHelpHoverColor(hoverColor) } const handleHelpHoverOut = () => { setHelpHoverColor(hoverOutColor) } const handleSoarHover = () => { setSoarHoverColor(hoverColor) } const handleSoarHoverOut = () => { setSoarHoverColor(hoverOutColor) } const handleHomeHoverOut = () => { setHomeHoverColor(hoverOutColor) } const handleLoginHover = () => { setLoginHoverColor(hoverColor) } const handleLoginHoverOut = () => { setLoginHoverColor(hoverOutColor) } const handleClick = (event) => { setAnchorEl(event.currentTarget); }; const chipStyle = { backgroundColor: "#3d3f43", height: 30, marginRight: 5, paddingLeft: 5, paddingRight: 5, height: 28, cursor: "pointer", borderColor: "#3d3f43", color: "white", } const notificationWidth = 350 const NotificationItem = (props) => { const {data} = props return ( {/* {new Date(data.updated_at).toISOString()} */} {data.reference_url !== undefined && data.reference_url !== null && data.reference_url.length > 0 ? {data.title} : {data.title} } {data.image !== undefined && data.image !== null && data.image.length > 0 ? {data.title} : null } {data.description} {/*data.tags !== undefined && data.tags !== null && data.tags.length > 0 ? data.tags.map((tag, index) => { return ( { }} variant="outlined" color="primary" /> ) }) : null */} {data.read === false ? : null} ) } const notificationMenu = { setAnchorEl(event.currentTarget); }}> { handleClose() }} >
Your Notifications ({notifications.length}) {notifications.length > 1 ? : null}
Notifications are made by Shuffle to help you discover issues or improvements.
{notifications.map((data, index) => { return ( ) })}
// Should be based on some path const avatarMenu = { setAnchorElAvatar(event.currentTarget); }}> { handleClose() }} > { event.preventDefault() handleClose() }}> Settings { event.preventDefault() handleClose() handleClickLogout() }}>  Logout // Handle top bar or something const logoCheck = !homePage ? null : null //
const loginTextBrowser = !isLoggedIn ?
About
Login
:
Workflows
Apps
{/*
Dashboard
*/}
Docs
{/*
Pricing
*/} {/*
Configure
*/}
{avatarMenu} {notificationMenu} {userdata === undefined || userdata.admin === undefined || userdata.admin === null || !userdata.admin ? null : } {userdata === undefined || userdata.orgs === undefined || userdata.orgs === null || userdata.orgs.length <= 1 ? null : }
//console.log("USR: ", userdata.orgs) const loginTextMobile = !isLoggedIn ?
About
:
Shuffle
Workflows
Apps
{/*
Configure
*/}
{avatarMenu}
// const loadedCheck =
{loginTextBrowser} {loginTextMobile}
//
return (
{loadedCheck}
) } export default Header;