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 { Tooltip, List, Avatar, Menu, ListItem, MenuItem, Select, Button, IconButton, Grid } from '@material-ui/core';
import { Home as HomeIcon, Polymer as PolymerIcon, Apps as AppsIcon, Description as DescriptionIcon} from '@material-ui/icons';
import { useAlert } from "react-alert";
const hoverColor = "#f85a3e"
const hoverOutColor = "#e8eaf6"
const Header = props => {
const { globalUrl, 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 alert = useAlert()
const hrefStyle = {
color: hoverOutColor,
textDecoration: "none",
}
// 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 handleClose = () => {
setAnchorEl(null);
};
// Should be based on some path
const avatarMenu =