import React, { useState, useEffect } from 'react'; import { Route } from 'react-router'; import { BrowserRouter } from 'react-router-dom'; import { CookiesProvider } from 'react-cookie'; import { removeCookies, useCookies } from 'react-cookie'; import EditSchedule from "./views/EditSchedule"; import Schedules from "./views/Schedules"; import Webhooks from "./views/Webhooks"; import Workflows from "./views/Workflows"; import EditWebhook from "./views/EditWebhook"; import AngularWorkflow from "./views/AngularWorkflow"; import Header from './components/Header'; import Apps from './views/Apps'; import AppCreator from './views/AppCreator'; import Contact from './views/Contact'; import Oauth2 from './views/Oauth2'; import Dashboard from "./views/Dashboard"; import AdminSetup from "./views/AdminSetup"; import Admin from "./views/Admin"; import Docs from "./views/Docs"; import Introduction from "./views/Introduction"; import LandingPageNew from "./views/LandingpageNew"; import LoginPage from "./views/LoginPage"; import SettingsPage from "./views/SettingsPage"; import { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles'; import ScrollToTop from "./components/ScrollToTop"; import AlertTemplate from "./components/AlertTemplate"; import { positions, Provider } from "react-alert"; // Production - backend proxy forwarding in nginx var globalUrl = window.location.origin // CORS used for testing purposes. Should only happen with specific port and http if (window.location.protocol == "http:" && window.location.port === "3000") { globalUrl = "http://localhost:5001" //globalUrl = "http://localhost:5002" } const theme = createMuiTheme({ palette: { primary: { main: "#f85a3e" }, secondary: { main: '#e8eaf6', }, surfaceColor: "#27292d", inputColor: "#383B40" }, typography: { useNextVariants: true }, overrides: { MuiMenu: { list: { backgroundColor: "#383B40", }, }, }, }); // FIXME - set client side cookies const App = (message, props) => { const [userdata, setUserData] = useState({}); //const [homePage, ] = useState(true); const [cookies, setCookie, removeCookie] = useCookies([]); const [isLoggedIn, setIsLoggedIn] = useState(false); const [dataset, setDataset] = useState(false); const [isLoaded, setIsLoaded] = useState(false); const [curpath, setCurpath] = useState(typeof window === 'undefined' || window.location === undefined ? "" : window.location.pathname) useEffect(() => { if (dataset === false) { checkLogin() setDataset(true) } }) if (isLoaded && !isLoggedIn && (!window.location.pathname.startsWith("/login") && (!window.location.pathname.startsWith("/docs") && (!window.location.pathname.startsWith("/adminsetup"))))) { window.location = "/login" } const checkLogin = () => { var baseurl = globalUrl fetch(baseurl + "/api/v1/users/getinfo", { credentials: "include", headers: { 'Content-Type': 'application/json', }, }) .then(response => response.json()) .then(responseJson => { if (responseJson.success === true) { //console.log(responseJson.success) setUserData(responseJson) setIsLoggedIn(true) //console.log("Cookies: ", cookies) // Updating cookie every request for (var key in responseJson["cookies"]) { setCookie(responseJson["cookies"][key].key, responseJson["cookies"][key].value, { path: "/" }) } } setIsLoaded(true) }) .catch(error => { setIsLoaded(true) }); } // Dumb for content load (per now), but good for making the site not suddenly reload parts (ajax thingies) const options = { timeout: 9000, position: positions.BOTTOM_LEFT, }; const includedData = window.location.pathname === "/home" || window.location.pathname === "/features" ?
} />
:
} /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> { window.location.pathname = "/docs/about" }} /> } /> } /> } />
//
// backgroundColor: "#213243", // This is a mess hahahah return ( {includedData} ); }; export default App;