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,
HelpOutline as HelpOutlineIcon,
} from "@material-ui/icons";
import {
Analytics as AnalyticsIcon,
Lightbulb as LightbulbIcon,
} from "@mui/icons-material";
//import LogoutIcon from '@mui/icons-material/Logout';
import { useAlert } from "react-alert";
import SearchField from '../components/Searchfield'
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,
};
localStorage.setItem("getting_started_sidebar", "open");
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 (
) : null}