Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.1.3",
"react-router-dom": "^6.16.0",
"react-scripts": "^3.0.1",
"typescript": "^4.9.4",
"web-vitals": "^2.1.4"
Expand Down
38 changes: 24 additions & 14 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import React from 'react';
import logo from './logo.svg';
import './App.css';
import Login from './Login/Login';
import Account from './ModuleAccess/Account';
import { BrowserRouter, Route, Routes, Link } from 'react-router-dom';


const NavBar = () => {
return (<nav>
<ul>
<li>
<a href='/login'>Login</a>
</li>
<li>
<a href='/account'>Account</a>
</li>
</ul>
</nav>)
}

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
testing react with eDigital
</a>
</header>
<BrowserRouter>
<Routes>
<Route path='/' element={<NavBar />} />
<Route path="/login" element={<Login />} />
<Route path="/account" element={<Account />} />
</Routes>
</BrowserRouter>
</div>
);
}
Expand Down
40 changes: 40 additions & 0 deletions src/Login/Login.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react'
import axios from 'axios'

const Login = () => {
const [email, setEmail] = React.useState('')
const [password, setPassword] = React.useState('')

const handleSubmit = () => {
console.error("PostDATA")

const postData = async () => {
const data = { email, password };
const request = await fetch('http://10.0.1.25:9999/api-auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
const response = await request.json()
const token = response.token
localStorage.setItem('token', token);
}
postData()
}


return (
<div className='row'>
<h2>Login</h2>
<label>Email</label>
<input type="email" id="email" onChange={e => setEmail(e.target.value)} value={email} />
<label>Password</label>
<input type="password" id="password" onChange={e => setPassword(e.target.value)} value={password} />
<button type="submit" onClick={handleSubmit}>Login</button>
</div>
)
}

export default Login
26 changes: 26 additions & 0 deletions src/ModuleAccess/Account.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { useEffect } from 'react'

const Account = () => {

useEffect(() => {
const fetchData = async () => {
const token = localStorage.getItem('token')
const request = await fetch('http://10.0.1.25:9999/api-auth/account', {
headers: {
"Authorization": `Token ${token}`
}
})
const response = await request.json()
console.log(response)
}
fetchData()
}, [])

return (
<div>
Account
</div>
)
}

export default Account
6 changes: 3 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import { Provider } from 'react-redux';
import './index.css';
import { store } from "./store";
// import { store } from "./store";
import App from './App';
import reportWebVitals from './reportWebVitals';

Expand All @@ -11,9 +11,9 @@ const root = ReactDOM.createRoot(
);
root.render(
<React.StrictMode>
<Provider store={store}>
{/* <Provider store={store}> */}
<App />
</Provider>
{/* </Provider> */}
</React.StrictMode>
);

Expand Down
82 changes: 42 additions & 40 deletions src/routes/config.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
import { INav } from "../models/INav";
// import { INav } from "../models/INav";

import { SignInPage } from "../pages/SignInPage";
import { HomePage } from "../pages/HomePage";
import { AProtectedPage } from "../pages/AProtectedPage";
import { AnotherProtectedPage } from "../pages/AnotherProtectedPage";
// import { SignInPage } from "../pages/SignInPage";
// import { HomePage } from "../pages/HomePage";
// import { AProtectedPage } from "../pages/AProtectedPage";
// import { AnotherProtectedPage } from "../pages/AnotherProtectedPage";


export const GLOBAL_APP_ROUTES: INav[] = [
{
id: "1",
title: "DNA Map",
path: "/dna-map",
element: <HomePage />,
icon: "home",
authorities: ["admin", "guest", "user"],
},
{
id: "2",
title: "Seewiz",
path: "/seewiz",
element: <AProtectedPage />,
icon: "video-recorder",
authorities: ["admin", "has_protected_page"],
},
{
id: "3",
title: "Live Map",
path: "/live-map",
element: <AnotherProtectedPage />,
icon: "map",
authorities: ["admin", "has_another_protected_page"],
},
];
// export const GLOBAL_APP_ROUTES: INav[] = [
// {
// id: "1",
// title: "DNA Map",
// path: "/dna-map",
// element: <HomePage />,
// icon: "home",
// authorities: ["admin", "guest", "user"],
// },
// {
// id: "2",
// title: "Seewiz",
// path: "/seewiz",
// element: <AProtectedPage />,
// icon: "video-recorder",
// authorities: ["admin", "has_protected_page"],
// },
// {
// id: "3",
// title: "Live Map",
// path: "/live-map",
// element: <AnotherProtectedPage />,
// icon: "map",
// authorities: ["admin", "has_another_protected_page"],
// },
// ];

const defaultAuthRoutes = [
{
id: "1",
title: "Login",
path: "/login",
element: <SignInPage />,
},
];
// const defaultAuthRoutes = [
// {
// id: "1",
// title: "Login",
// path: "/login",
// element: <SignInPage />,
// },
// ];

export const AUTH_ROUTES: INav[] = defaultAuthRoutes;
// export const AUTH_ROUTES: INav[] = defaultAuthRoutes;

export {}
34 changes: 0 additions & 34 deletions src/store/auth.slice.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/store/index.ts

This file was deleted.

33 changes: 0 additions & 33 deletions src/store/user.slice.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "preserve"
},
"include": [
"src"
Expand Down