diff --git a/src/Components/App.js b/src/Components/App.js index 8f31e7c..464c62c 100644 --- a/src/Components/App.js +++ b/src/Components/App.js @@ -1,7 +1,9 @@ -import React from 'react'; -import { Container, Menu } from 'semantic-ui-react'; +import React, { useState } from 'react'; +import { Container, Menu, Header, Message, Icon } from 'semantic-ui-react'; import { BrowserRouter as Router, Switch, Route, Link, Redirect } from 'react-router-dom'; +import Login from './Login'; + import Dashboard from './Dashboard'; import Account from './Account'; import PackageScanner from './PackageScanner'; @@ -15,13 +17,50 @@ import Warehouses from './Operators/Warehouses'; import AllRoutes from './Operators/Routes'; function App() { + const [ user, setUser ] = useState(null); + + function logout() { + sessionStorage.removeItem('token'); + localStorage.removeItem('token'); + setUser(null); + + // + } + + if (!user) { + return ( + + + + Deliverly + + + + +
Welcome to Deliverly
+ Deliverly is a delivery platform... + + + + + Tracking a Package? + If you are trying to track a package, please click here. + + + + +
+
+ ) + } + return ( Deliverly - Logout + Logout diff --git a/src/Components/Dashboard.js b/src/Components/Dashboard.js index ef08af3..dc0458a 100644 --- a/src/Components/Dashboard.js +++ b/src/Components/Dashboard.js @@ -6,7 +6,7 @@ import Map from './Map'; function Dashboard() { return ( -
Welcome to Deliverly, user!
+
Welcome to Deliverly, user!
diff --git a/src/Components/Login.js b/src/Components/Login.js new file mode 100644 index 0000000..5890cee --- /dev/null +++ b/src/Components/Login.js @@ -0,0 +1,66 @@ +import React, { useState, useEffect } from 'react'; +import { Segment, Header, Form, Input, Message, Button } from 'semantic-ui-react'; + +function Login(props) { + const { setUser } = props; + const [ error, setError ] = useState(null); + const [ loading, setLoading ] = useState(false); + const [ email, setEmail ] = useState('test@example.com'); + const [ password, setPassword ] = useState('password'); + const [ remember, setRemember ] = useState(false); + + useEffect(() => { + let token = sessionStorage.getItem('token'); + if (!token) token = localStorage.getItem('token'); + + if (token) { + setLoading(true); + + //Login + setUser({ + 'name': 'Bob', + 'token': token, + 'operator': false + }); + + setLoading(false); + } + + }, []); + + function attemptLogin() { + let token = 'abc'; + + setUser({ + 'name': 'Bob', + 'token': token, + 'operator': false + }); + + sessionStorage.setItem('token', token); + if (remember) localStorage.setItem('token', token); + } + + return ( + +
Driver Login
+
+ { error && {error} } + + + + setEmail(state.value)} /> + + + + setPassword(state.value)} /> + + + setRemember(state.checked)} /> + + +
+ ); +} + +export default Login; diff --git a/src/Components/Map.js b/src/Components/Map.js index 5a04665..dbc7070 100644 --- a/src/Components/Map.js +++ b/src/Components/Map.js @@ -2,9 +2,6 @@ import React, { createRef, useEffect, useState } from 'react'; import { Segment, ItemDescription, ItemExtra } from 'semantic-ui-react'; import mapboxgl from 'mapbox-gl'; -mapboxgl.accessToken = process.env.REACT_APP_MAPBOX_ACCESS_TOKEN; -console.log(process.env); - function Map(props) { const [ map, setMap ] = useState(null); const ref = createRef(); @@ -13,7 +10,7 @@ function Map(props) { useEffect(() => { if (!items) return; if (items.length === 0) return; - + mapboxgl.accessToken = process.env.REACT_APP_MAPBOX_ACCESS_TOKEN; let _map = new mapboxgl.Map({ container: ref.current, style: 'mapbox://styles/mapbox/streets-v11', diff --git a/src/Components/Operators/Warehouses.js b/src/Components/Operators/Warehouses.js index 1f3c91f..07b7f9d 100644 --- a/src/Components/Operators/Warehouses.js +++ b/src/Components/Operators/Warehouses.js @@ -24,21 +24,21 @@ function Warehouses() { { error && {error} }
- + setName(state.value)} /> - + setStreet(state.value)} /> - + setTown(state.value)} /> - + setPostcode(state.value)} /> @@ -83,21 +83,21 @@ function Warehouses() { { error && {error} } - + setName(state.value)} /> - + setStreet(state.value)} /> - + setTown(state.value)} /> - + setPostcode(state.value)} /> diff --git a/src/index.js b/src/index.js index 9dd1627..33aaa85 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,9 @@ import './index.css'; import App from './Components/App'; import * as serviceWorker from './serviceWorker'; +console.warn('Do not paste anything in here!'); +console.warn('Doing so could grant an attacker full access to your account'); + ReactDOM.render(