import React, { useState } from "react"; import { toast } from "react-toastify"; import theme from "../theme.jsx"; import { BrowserView, MobileView } from "react-device-detect"; import { useNavigate, Link } from "react-router-dom"; import ReactGA from "react-ga4"; import LicencePopup from "../components/LicencePopup.jsx"; import SearchField from "../components/Searchfield.jsx"; import { Paper, Typography, Badge, Tooltip, List, ListItem, Avatar, Menu, MenuItem, Select, Button, ButtonGroup, Grid, IconButton, Divider, LinearProgress, AppBar, Dialog, DialogTitle, } from "@mui/material"; import { Close as CloseIcon, MeetingRoom as MeetingRoomIcon, HelpOutline as HelpOutlineIcon, Settings as SettingsIcon, Notifications as NotificationsIcon, Home as HomeIcon, Apps as AppsIcon, Description as DescriptionIcon, EmojiObjects as EmojiObjectsIcon, Business as BusinessIcon, Polyline as PolylineIcon, Add as AddIcon, Analytics as AnalyticsIcon, Lightbulb as LightbulbIcon, ExpandMore as ExpandMoreIcon, } from "@mui/icons-material"; const hoverColor = "#f85a3e"; const hoverOutColor = "#e8eaf6"; const Header = (props) => { const { globalUrl, setNotifications, notifications, isLoaded, isLoggedIn, removeCookie, homePage, userdata, isMobile, serverside, curpath, billingInfo } = props; 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 [isHeader, setIsHeader] = React.useState(false); const [modalOpen, setModalOpen] = useState(false); const [anchorEl, setAnchorEl] = React.useState(null); const [anchorElAvatar, setAnchorElAvatar] = React.useState(null); const [subAnchorEl, setSubAnchorEl] = React.useState(null); const [upgradeHovered, setUpgradeHovered] = React.useState(false); const [showTopbar, setShowTopbar] = useState(false) const stripeKey = typeof window === 'undefined' || window.location === undefined ? "" : window.location.origin === "https://shuffler.io" ? "pk_live_XAxwE2Fp9DEbEcNYw4UKmyby00vIlIPPRp" : "pk_test_EdxgKfqmQGXY5JLjdBqtuhCw00BHbiKJDB" let navigate = useNavigate(); const handleClick = (event) => { setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorEl(null); setAnchorElAvatar(null); }; // Should be based on some path const logoCheck = !homePage ? null : null const hrefStyle = { color: hoverOutColor, textDecoration: "none", }; const menuText = { textTransform: "none", color: "#FFF", textAlign: "center", fontSize: 16, fontStyle: "normal", fontWeight: 400, lineHeight: "normal", } const isCloud = serverside === true || typeof window === "undefined" ? true : window.location.host === "localhost:3002" || window.location.host === "shuffler.io" || window.location.host === "localhost:5002"; const clearNotifications = () => { // Don't really care about the logout toast("Clearing notifications") 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 { toast("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 { toast("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("SHOULD LOG OUT"); // 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 removeCookie("session_token", { path: "/" }); removeCookie("session_token", { path: "/" }); removeCookie("session_token", { path: "/" }); removeCookie("session_token", { path: "/" }); removeCookie("__session", { path: "/" }); removeCookie("__session", { path: "/" }); removeCookie("__session", { path: "/" }); removeCookie("__session", { path: "/" }); window.location.pathname = "/"; localStorage.setItem("globalUrl", "") // Delete userinfo from localstorage localStorage.removeItem("apps") localStorage.removeItem("workflows") localStorage.removeItem("userinfo") }) .catch((error) => { console.log(error); }); }; // 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 notificationWidth = 335 const imagesize = 22; const boxColor = "#86c142"; const NotificationItem = (props) => { const { data } = props var image = ""; var orgName = ""; var orgId = ""; if (userdata.orgs !== undefined) { const foundOrg = userdata.orgs.find((org) => org.id === data["org_id"]); if (foundOrg !== undefined && foundOrg !== null) { //position: "absolute", bottom: 5, right: -5, const imageStyle = { width: imagesize, height: imagesize, pointerEvents: "none", marginLeft: data.creator_org !== undefined && data.creator_org.length > 0 ? 20 : 0, borderRadius: 10, border: foundOrg.id === userdata.active_org.id ? `3px solid ${boxColor}` : null, cursor: "pointer", marginRight: 10, } image = foundOrg.image === "" ? ( {foundOrg.name} ) : ( {foundOrg.name} { }} /> ); orgName = foundOrg.name; orgId = foundOrg.id; } } return ( {data.reference_url !== undefined && data.reference_url !== null && data.reference_url.length > 0 ? {data.title} ({data.amount}) : {data.title} } {data.image !== undefined && data.image !== null && data.image.length > 0 ? {data.title} : null } {data.description}
{data.read === false ? ( ) : null}
{ }} > {image}
); }; const notificationMenu = ( { setAnchorEl(event.currentTarget); }} > {/* n.read === false).length} color="primary">*/} { handleClose(); }} >
Notifications ({notifications.filter((data) => !data.read).length}) {notifications.length > 1 ? ( ) : null}
Notifications generated made by Shuffle to help you discover issues or improvements. Learn more
{notifications.map((data, index) => { if (data.read) { return null } return ; })}
); const handleClickChangeOrg = (orgId) => { // Don't really care about the logout //name: org.name, //orgId = "asd" const data = { org_id: orgId, }; localStorage.setItem("globalUrl", ""); localStorage.setItem("getting_started_sidebar", "open"); fetch(`${globalUrl}/api/v1/orgs/${orgId}/change`, { mode: "cors", credentials: "include", crossDomain: true, method: "POST", body: JSON.stringify(data), withCredentials: true, headers: { "Content-Type": "application/json; charset=utf-8", }, }) .then(function (response) { if (response.status !== 200) { console.log("Error in response"); } else { localStorage.removeItem("apps") localStorage.removeItem("workflows") localStorage.removeItem("userinfo") } return response.json(); }) .then(function (responseJson) { console.log("In here?") if (responseJson.success === true) { if (responseJson.region_url !== undefined && responseJson.region_url !== null && responseJson.region_url.length > 0) { console.log("Region Change: ", responseJson.region_url); localStorage.setItem("globalUrl", responseJson.region_url); //globalUrl = responseJson.region_url } if (responseJson["reason"] === "SSO_REDIRECT") { window.location.href = responseJson["url"] return } setTimeout(() => { window.location.reload(); }, 2000); toast("Successfully changed active organization - refreshing!"); } else { if (responseJson.reason !== undefined && responseJson.reason !== null && responseJson.reason.length > 0) { toast(responseJson.reason); } else { toast("Failed changing org. Try again or contact support@shuffler.io if this persists."); } } }) .catch((error) => { console.log("error changing: ", error); //removeCookie("session_token", {path: "/"}) }); }; const supportMenu = ( { }} > Discord Community Join ); // Should be based on some path const parsedAvatar = userdata.avatar !== undefined && userdata.avatar !== null && userdata.avatar.length > 0 ? userdata.avatar : "" const avatarMenu = ( { setAnchorElAvatar(event.currentTarget); }} > { handleClose(); }} > { handleClose(); }} > Organization { handleClose(); }} > Account { handleClose(); }} > Notifications {/*notificationMenu*/} { handleClose(); }} > About {/* { handleClose(); }} > Get Started */} { handleClose(); }} > Use Cases { handleClose(); }} > Creator page { handleClickLogout(); event.preventDefault(); handleClose(); }} >  Logout Version: 1.4.0 ); const listItemStyle = { textAlign: "center", marginTop: "auto", marginBottom: "auto", marginRight: 10, }; const modalView = { setModalOpen(false); }} PaperProps={{ style: { color: "white", minWidth: 850, minHeight: 370, padding: 20, backgroundColor: "rgba(0, 0, 0, 1)", borderRadius: theme.palette.borderRadius, }, }} > Upgrade your plan { if (isCloud) { ReactGA.event({ category: "header", action: "close_Upgread_popup", label: "", })}; setModalOpen(false); }} style={{ marginLeft: "auto", position: "absolute", top: 20, right: 20, }} >
// Handle top bar or something const defaultTop = -2 const loginTextBrowser = !isLoggedIn ? (
{ if (isCloud) { ReactGA.event({ category: "header", action: "home_click", label: "", }); } }} > shuffle logo {isCloud ? ( ) : null}
) : (
logo
{/* */} Workflows
{/* */} Apps
{/*
Dashboard
*/}
{/* */} Docs
{avatarMenu} {/*notificationMenu*/} {supportMenu} {logoCheck} {userdata === undefined || userdata.orgs === undefined || userdata.orgs === null || userdata.orgs.length <= 0 ? null : ( )} {/* Show on cloud, if not suborg and if not customer/pov/internal */} { userdata.licensed !== undefined && userdata.licensed !== null && userdata.licensed === false ? : null} {userdata === undefined || userdata.app_execution_limit === undefined || userdata.app_execution_usage === undefined || userdata.app_execution_usage < 1000 ? null : (
= 0.9 ? "2px solid #f86a3e" : null, }} onClick={() => { console.log( userdata.appe_execution_usage / userdata.app_execution_limit ); if (window.drift !== undefined) { window.drift.api.startInteraction({ interactionId: 326905, }); navigate("/pricing"); } else { console.log( "Couldn't find drift in window.drift and not .drift-open-chat with querySelector: ", window.drift ); } }} > {( (userdata.app_execution_usage / userdata.app_execution_limit) * 100 ).toFixed(0)} %
)}
); const loginTextMobile = !isLoggedIn ? (
logo
About
) : (
Logout
{logoCheck}
); // // /* !isLoggedIn ?
{loginTextBrowser}
: */ const topbarHeight = showTopbar ? 40 : 0 const topbar = !showTopbar ? null : curpath === "/" || curpath.includes("/docs/") || curpath === "/pricing" || curpath === "/contact" || curpath === "/search" ?
Shuffle 1.4 is out! Read more about  { ReactGA.event({ category: "landingpage", action: "click_header_features", label: "", }) //if (window.drift !== undefined) { // window.drift.api.startInteraction({ interactionId: 341911 }) //} else { // console.log("Couldn't find drift in window.drift and not .drift-open-chat with querySelector: ", window.drift) //} }} style={{ cursor: "pointer", textDecoration: "none", color: "rgba(255,255,255,0.8)" }}> Features { ReactGA.event({ category: "landingpage", action: "click_header_pricing", label: "", }) navigate("/pricing") //if (window.drift !== undefined) { // window.drift.api.startInteraction({ interactionId: 341911 }) //} else { // console.log("Couldn't find drift in window.drift and not .drift-open-chat with querySelector: ", window.drift) //} }} style={{ cursor: "pointer", textDecoration: "none", color: "rgba(255,255,255,0.8)" }}> Pricing  and  { ReactGA.event({ category: "landingpage", action: "click_header_creators", label: "", }) navigate("/creators") //if (window.drift !== undefined) { // window.drift.api.startInteraction({ interactionId: 341911 }) //} else { // console.log("Couldn't find drift in window.drift and not .drift-open-chat with querySelector: ", window.drift) //} }} style={{ cursor: "pointer", textDecoration: "none", color: "rgba(255,255,255,0.8)" }}> Earning as a Creator { setShowTopbar(false) }}>
: null return !isMobile ?
{topbar}
{loginTextBrowser}
{modalView}
: {loginTextMobile} }; export default Header;