import React, {useState, useEffect} from 'react'; import {Route} from 'react-router'; import {BrowserRouter} from 'react-router-dom'; import { CookiesProvider } from 'react-cookie'; import { useCookies } from 'react-cookie'; import EditSchedule from "./EditSchedule"; import Schedules from "./Schedules"; import Webhooks from "./Webhooks"; import Workflows from "./Workflows"; import EditWebhook from "./EditWebhook"; import AngularWorkflow from "./AngularWorkflow"; import ForgotPassword from "./ForgotPassword"; import ForgotPasswordLink from "./ForgotPasswordLink"; import Header from './Header'; import Apps from './Apps'; import AppCreator from './AppCreator'; import Contact from './Contact'; import Oauth2 from './Oauth2'; import About from "./About"; import Post from "./Post"; import Dashboard from "./Dashboard"; import AdminSetup from "./AdminSetup"; import Admin from "./Admin"; import Docs from "./Docs"; import RegisterLink from "./RegisterLink"; import LandingPage from "./Landingpage"; import LandingPageNew from "./LandingpageNew"; import LoginPage from "./LoginPage"; import SettingsPage from "./SettingsPage"; import MuiThemeProvider from '@material-ui/core/styles/MuiThemeProvider'; import { createMuiTheme } from '@material-ui/core/styles'; import AlertTemplate from "react-alert-template-basic"; import { positions, Provider } from "react-alert"; // Production - backend proxy forwarding in nginx var globalUrl = window.location.origin if (window.location.protocol == "http:" && window.location.port === "3000") { globalUrl = "http://192.168.3.6:5001" } console.log(window.location) console.log(globalUrl) const surfaceColor = "#27292D" const inputColor = "#383B40" const theme = createMuiTheme({ palette: { primary: { main: "#f85a3e" }, secondary: { main: '#e8eaf6', }, }, typography: { useNextVariants: true } }); // 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); 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/getinfo", { credentials: "include", headers: { 'Content-Type': 'application/json', }, }) .then(response => response.json()) .then(responseJson => { console.log(responseJson) if (responseJson.success === true) { setUserData(responseJson) setIsLoggedIn(true) // Updating cookie every request console.log("COOKIES: ", cookies) 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: 5000, position: positions.BOTTOM_CENTER }; const includedData = window.location.pathname === "/home" || window.location.pathname === "/features" ?
} />
:
} /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {window.location.pathname = "/docs/about"}} /> {window.location.pathname = "/login"}} />
//
// backgroundColor: "#213243", // This is a mess hahahah return ( {includedData} ); }; export default App;