clean repository

This commit is contained in:
Christiaan Evers 2021-07-30 23:49:23 +02:00
commit 34622ca374
41 changed files with 13187 additions and 0 deletions

26
.gitignore vendored Normal file
View File

@ -0,0 +1,26 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# data
/src/data
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

12
.idea/frontend.iml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/frontend.iml" filepath="$PROJECT_DIR$/.idea/frontend.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

74
.idea/workspace.xml Normal file
View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="ffab9a85-d9fb-41e5-9b26-b6bb18eb7f17" name="Default Changelist" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="PackageJsonUpdateNotifier">
<dismissed value="$PROJECT_DIR$/package.json" />
</component>
<component name="ProjectId" id="1tncdibhoVrq7F4BJpNdedp68Mq" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="ASKED_ADD_EXTERNAL_FILES" value="true" />
<property name="ASKED_SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/public/icons" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.selected.package.eslint" value="(autodetect)" />
<property name="nodejs_package_manager_path" value="npm" />
<property name="ts.external.directory.path" value="$PROJECT_DIR$/node_modules/typescript/lib" />
<property name="vue.rearranger.settings.migration" value="true" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/public/icons" />
<recent name="$PROJECT_DIR$/public/logos" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src/screens" />
</key>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="ffab9a85-d9fb-41e5-9b26-b6bb18eb7f17" name="Default Changelist" comment="" />
<created>1623408383784</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1623408383784</updated>
<workItem from="1623408385413" duration="45185000" />
<workItem from="1626249038299" duration="5237000" />
<workItem from="1626295890298" duration="15478000" />
<workItem from="1626647730677" duration="22537000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
<option name="oldMeFiltersMigrated" value="true" />
</component>
</project>

46
README.md Normal file
View File

@ -0,0 +1,46 @@
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `yarn start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `yarn test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `yarn build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `yarn eject`
**Note: this is a one-way operation. Once you `eject`, you cant go back!**
If you arent satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).

54
package.json Normal file
View File

@ -0,0 +1,54 @@
{
"name": "frontend",
"proxy": "http://127.0.0.1:8000",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.11.4",
"@material-ui/data-grid": "^4.0.0-alpha.31",
"@material-ui/icons": "^4.11.2",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/geojson": "^7946.0.8",
"@types/jest": "^26.0.15",
"@types/leaflet": "^1.7.4",
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-leaflet": "^2.8.2",
"@types/react-router-dom": "^5.1.7",
"axios": "^0.21.1",
"bootstrap": "^5.0.1",
"leaflet": "^1.7.1",
"react": "^17.0.2",
"react-bootstrap": "^1.6.1",
"react-dom": "^17.0.2",
"react-leaflet": "^3.2.0",
"react-redux": "^7.2.4",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"redux": "^4.1.0",
"redux-devtools-extension": "^2.13.9",
"redux-thunk": "^2.3.0",
"typescript": "^4.1.2",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": [
">0.2%",
"not dead",
"not op_mini all"
]
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
public/icons/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

43
public/index.html Normal file
View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

BIN
public/logo192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
public/logo512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

BIN
public/logos/logo512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

25
public/manifest.json Normal file
View File

@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

3
public/robots.txt Normal file
View File

@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

38
src/App.css Normal file
View File

@ -0,0 +1,38 @@
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

9
src/App.test.tsx Normal file
View File

@ -0,0 +1,9 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

26
src/App.tsx Normal file
View File

@ -0,0 +1,26 @@
import React from 'react';
import logo from './logo.svg';
import './App.css';
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"
>
Learn React
</a>
</header>
</div>
);
}
export default App;

View File

@ -0,0 +1,19 @@
import axios from 'axios';
export const listDepartments = async (dispatch: any) => {
try {
dispatch({type:'DEPARTMENT_LIST_REQUEST'})
const { data } = await axios.get('/api/departments')
dispatch({
type: 'DEPARTMENT_LIST_SUCCESS',
payload: data
})
} catch (error){
dispatch({
type: "DEPARTMENT_LIST_FAIL",
payload: error.response && error.response.data.message ? error.response.data.message : error.message
})
}
}

View File

@ -0,0 +1,64 @@
import axios from 'axios';
export const login = async (username: string, password: string, dispatch: any) => {
try {
dispatch({type:'USER_LOGIN_REQUEST'});
const config = {
headers: {
'Content-type': 'application/json'
}
};
const { data } = await axios.post('/api/users/login', {username, password}, config);
dispatch({
type: 'USER_LOGIN_SUCCESS',
payload: data
})
localStorage.setItem('userInfo', JSON.stringify(data));
} catch (error){
dispatch({
type: 'USER_LOGIN_FAIL',
payload: error.response && error.response.data.message ? error.response.data.message : error.message
})
}
}
export const logout = (dispatch: any) => {
localStorage.removeItem('userInfo');
dispatch({
type: 'USER_LOGOUT',
})
}
export const getUserDetails = (id: number) => async (dispatch: any, getState: any) => {
try {
dispatch({
type: 'USER_DETAILS_REQUEST'
})
const { userLogin: {userInfo} } = getState()
const config = {
headers: {
'Content-type': 'application/json',
Authorization: `Bearer ${userInfo.access}`
}
}
const { data } = await axios.get(`api/users/${id}`, config);
dispatch({
type: 'USER_DETAILS_SUCCESS',
payload: data
})
} catch(error: any) {
dispatch({
type: 'USER_DETAILS_FAIL',
payload: error.response && error.response.data.message ? error.response.data.message : error.message
})
}
}

View File

@ -0,0 +1,14 @@
import React from 'react';
import {Alert} from 'react-bootstrap';
export const AlertMessage = ({variant, children}: {variant: any, children: any}) => {
return (
<div>
<Alert
variant={variant}
>
{children }
</Alert>
</div>
)
}

View File

@ -0,0 +1,8 @@
export const Authentication = () => {
return (
<div>
Authentication divvv
</div>
)
}

View File

@ -0,0 +1,124 @@
import {useDispatch, useSelector} from 'react-redux';
import {Link as RouterLink} from 'react-router-dom';
import {AppBar, Toolbar, Grid, List, ListItem, ListItemText, Menu, MenuItem, IconButton} from '@material-ui/core';
import MenuIcon from '@material-ui/icons/Menu';
import {makeStyles, Theme} from '@material-ui/core/styles';
import {logout} from '../../actions/user-actions';
import {useState} from "react";
const useStyles = makeStyles((theme: Theme) => ({
root: {
flexGrow: 1,
},
appBar: {
backgroundColor: '#3f51b5',
position: 'static',
},
appBarToolbar: {
},
menuButton: {
marginRight: theme.spacing(2)
},
menuLoginButton: {
position: 'relative',
},
appBarLogo: {
height: '6vh'
},
}));
export const Header = () => {
const userLogin = useSelector((state: any) => state.userLogin);
const {userInfo} = userLogin;
const dispatch = useDispatch();
const logoutHandler = () => {
logout(dispatch);
};
const [anchorEl, setAnchorEl] = useState(null);
const open = Boolean(anchorEl);
const handleClick = (event: any) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const classes = useStyles();
return (
<div className={classes.root}>
<AppBar className={classes.appBar}>
<Toolbar className={classes.appBarToolbar}>
{userInfo ? (
<Grid container justify='space-between'>
<Grid item>
<List>
<IconButton
edge="start"
className={classes.menuButton}
color="inherit"
aria-label="menu"
onClick={handleClick}
>
<MenuIcon></MenuIcon>
</IconButton>
<Menu
id="fade-menu"
anchorEl={anchorEl}
keepMounted
open={open}
onClose={handleClose}
>
<MenuItem component={RouterLink} to={'/'} key={'home'} onClick={handleClose}>Home</MenuItem>
<MenuItem component={RouterLink} to={'/user-details'} key={'user-details'} onClick={handleClose}>Profile</MenuItem>
<MenuItem component={RouterLink} to={'/geo-map'} key={'geo-map'} onClick={handleClose}>Map</MenuItem>
</Menu>
</List>
</Grid>
<Grid item>
<List style={{ display: 'flex', flexDirection: 'row', padding: 0 }}>
<ListItem button component={RouterLink} to={'/user-details'} key={'user-details'} >
<ListItemText>Profile</ListItemText>
</ListItem>
<ListItem button component={RouterLink} to={'/login'} key={'login'} onClick={logoutHandler}>
<ListItemText>Logout</ListItemText>
</ListItem>
</List>
</Grid>
</Grid>
): (
<Grid container justify={'flex-end'}>
<Grid item>
<List>
<ListItem button component={RouterLink} to={'/login'} key={'login'}>
<ListItemText>Login</ListItemText>
</ListItem>
</List>
</Grid>
</Grid>
)}
</Toolbar>
</AppBar>
</div>
)
}
/*
<Grid container justify='space-between'>
<Link color="inherit" className={classes.menuLoginButton}>Login</Link>
</Grid>
*/
/*
<IconButton edge="start" className={classes.menuButton} color="inherit" aria-label="menu">
<Menu/>
</IconButton>
*/

View File

@ -0,0 +1,19 @@
import React from 'react';
import {Spinner} from 'react-bootstrap';
export const Loader = () => {
return (
<Spinner
animation={"border"}
role={"status"}
style={{
height: '100px',
width: '100px',
margin: 'auto',
display: 'block'
}}
>
<span className={'sr-only'}>Loading...</span>
</Spinner>
)
}

13
src/index.css Normal file
View File

@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

20
src/index.tsx Normal file
View File

@ -0,0 +1,20 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import { App } from './screens/App';
import reportWebVitals from './reportWebVitals';
import { Provider } from 'react-redux';
import store from '../src/redux'
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

1
src/logo.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

1
src/react-app-env.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="react-scripts" />

View File

@ -0,0 +1,13 @@
export const departmentListReducer = (state = {departments: []}, action: any) => {
switch (action.type) {
case 'DEPARTMENT_LIST_REQUEST':
return { loading: true, departments: [] }
case 'DEPARTMENT_LIST_SUCCESS':
return { loading: false, departments: action.payload }
case 'DEPARTMENT_LIST_FAIL':
return { loading: false, error: action.payload }
default:
return state
}
}

View File

@ -0,0 +1,29 @@
export const userLoginReducer = (state = {}, action: any) => {
switch (action.type) {
case 'USER_LOGIN_REQUEST':
return { loading: true }
case 'USER_LOGIN_SUCCESS':
return { loading: false, userInfo: action.payload }
case 'USER_LOGIN_FAIL':
return { loading: false, error: action.payload }
case 'USER_LOGOUT':
return {} //reset the state
default:
return state
}
}
export const userDetailsReducer = (state = {user: {}}, action: any) => {
switch (action.type) {
case 'USER_DETAILS_REQUEST':
return { loading: true, ...state }
case 'USER_DETAILS_SUCCESS':
return { loading: false, user: action.payload }
case 'USER_DETAILS_FAIL':
return { loading: false, error: action.payload }
default:
return state
}
}

24
src/redux/index.ts Normal file
View File

@ -0,0 +1,24 @@
import {createStore, combineReducers, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import {composeWithDevTools} from 'redux-devtools-extension';
import {departmentListReducer} from "../reducers/test-reducers";
import {userLoginReducer, userDetailsReducer} from '../reducers/user-reducers';
const reducer = combineReducers({
departmentList: departmentListReducer,
userLogin: userLoginReducer,
userDetails: userDetailsReducer
});
const localStorageUserInfo = localStorage.getItem('userInfo');
const userInfoFromStorage = localStorageUserInfo ? JSON.parse(localStorageUserInfo) : null;
const initialState = {
userLogin: {userInfo: userInfoFromStorage}
};
const middleware = [thunk]
const store = createStore(reducer, initialState, composeWithDevTools(applyMiddleware(...middleware)));
export default store;

15
src/reportWebVitals.ts Normal file
View File

@ -0,0 +1,15 @@
import { ReportHandler } from 'web-vitals';
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;

77
src/screens/App.tsx Normal file
View File

@ -0,0 +1,77 @@
import React, {useEffect} from 'react';
import { BrowserRouter as Router, Route} from 'react-router-dom'; //Switch //Redirect
import {CssBaseline, createMuiTheme, MuiThemeProvider, Container} from "@material-ui/core";
import 'bootstrap/dist/css/bootstrap.min.css'
import {Header} from "../components/Header";
import {Login} from "./Login";
import {Profile} from "./Profile";
import {GeoMap} from "./GeoMap";
const THEME = createMuiTheme({
typography: {
fontFamily: `"Roboto, sans-serif"`,
fontSize: 12,
fontWeightLight: 300,
fontWeightRegular: 400,
fontWeightMedium: 500
}
})
export const App = () => {
useEffect(() => {
//console.log("app use effect")
}, [])
return (
<MuiThemeProvider theme={THEME}>
<Router>
<CssBaseline />
<Header />
<main>
<Container>
<Route path={'/login'} component={Login} exact/>
<Route path={'/user-details'} component={Profile}/>
<Route path={'/geo-map'} component={GeoMap}/>
</Container>
</main>
</Router>
</MuiThemeProvider>
)
}
/*
import React, {useEffect} from "react";
import {useDispatch, useSelector} from 'react-redux';
import {listDepartments} from '../actions/test-actions';
import {Loader} from "../components/Loader";
import 'bootstrap/dist/css/bootstrap.min.css'
import {AlertMessage} from "../components/Alert";
const dispatch = useDispatch();
const departmentList: any = useSelector((state: any) => state.departmentList)
const {error, loading, departments} = departmentList;
export const App = () => {
useEffect(() => {
dispatch(listDepartments)
}, [dispatch])
return (
<div>
<h1>Departments</h1>
{
loading ?
<Loader />
: error ?
<AlertMessage variant={'danger'}>{error}</AlertMessage>
:
departments.map((department: any) => (
<p key={department._id}>{department.name}</p>
))
}
</div>
)
//departments for the current user
}
*/

71
src/screens/GeoMap.tsx Normal file
View File

@ -0,0 +1,71 @@
import React, {useEffect} from 'react';
import neighbourhoods from '../data/buurten-amsterdam.json';
import {Grid} from '@material-ui/core';
import {makeStyles, Theme} from '@material-ui/core/styles';
import {GeoJSON, MapContainer, TileLayer} from 'react-leaflet';
import 'leaflet/dist/leaflet.css';
const useStyles = makeStyles((theme: Theme) => ({
GeoMapContainer: {
spacing: 0,
justifyContent : 'center',
direction: 'initial',
marginTop: '4vh'
},
}));
export const GeoMap = ({Location, history}: {Location: any, history: any}) => {
const mapData: any = neighbourhoods.features;
const classes = useStyles();
//const fillBlueOptions = { fillColor: 'blue' }
useEffect(() => {
console.log(neighbourhoods);
}, [history])
const onEachNeighbourhood = (neighbourhood: any, layer: any) => {
//console.log(neighbourhood);
layer.bindPopup(neighbourhood.properties.Buurt);
layer.options.fillOpacity = Math.random();
layer.on({
click: (event: any) => {
//console.log(event)
event.target.setStyle({
fillColor: "Yellow"
})
}
})
}
return (
<Grid container className={classes.GeoMapContainer}>
<Grid item>
<MapContainer style={{height: "70vh", width: "70vh"}}
center={[52.37, 4.90]}
zoom={12}
scrollWheelZoom={false}
>
<TileLayer
attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<GeoJSON
data={mapData}
onEachFeature={onEachNeighbourhood}
/>
</MapContainer>
</Grid>
</Grid>
)
}
/*
<Grid item>
<List style={{display: 'flex', flexDirection: 'column', padding: 0}}>
<ListItem>
<ListItemText>Hi there....!</ListItemText>
</ListItem>
</List>
</Grid>
*/

140
src/screens/Login.tsx Normal file
View File

@ -0,0 +1,140 @@
import React, {useEffect, useState} from 'react';
import {makeStyles, Theme} from '@material-ui/core/styles';
import {Grid, Paper, Typography, Link, TextField, Button} from '@material-ui/core';
import {useDispatch, useSelector} from 'react-redux';
import {login} from '../actions/user-actions';
import {AlertMessage} from '../components/Alert';
import {Loader} from '../components/Loader';
const useStyles = makeStyles((theme: Theme) => ({
loginFormContainer: {
spacing: 0,
justifyContent : 'center',
direction: 'initial',
marginTop: '4vh'
},
loginForm: {
spacing: 0,
justifyContent : 'center',
justify: 'center'
},
loginBackground: {
justifyContent: 'center',
backgroundColor: '#dce5f2',
minHeight: '30vh',
padding: '7vh',
},
buttonBlock: {
width: '100%'
},
loginLabel: {
marginBottom: '1vh'
}
}));
export const Login = ({Location, history}: {Location: any, history: any}) => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const dispatch = useDispatch();
const redirect = Location && Location.search ? Location.search.split('=')[1] : '/';
const userLogin = useSelector((state: State) => state.userLogin)
const {error, loading, userInfo} = userLogin;
useEffect(() => {
if(userInfo){
console.log("redirected due to existing userInfo" + JSON.stringify(userInfo));
history.push(redirect);
}
}, [history, userInfo, redirect])
const submitHandler = (event: any) => {
event.preventDefault();
login(username, password, dispatch);
};
const classes = useStyles();
return (
<Grid container className={classes.loginFormContainer}>
<Grid item>
<Grid container className={classes.loginForm}>
<Paper className={classes.loginBackground}>
<Grid item>
<Typography variant='h5' className={classes.loginLabel}>
Bij1
</Typography>
</Grid>
<Grid item>
<form onSubmit={submitHandler}>
{error && <AlertMessage variant={'danger'}>{error}</AlertMessage>}
{loading && <Loader />}
<Grid container direction="column" spacing={2}>
<Grid item>
<TextField type="text"
placeholder="Username"
fullWidth
name="username"
variant="outlined"
onChange={(e) => setUsername(e.target.value)}
/>
</Grid>
<Grid item>
<TextField
type="password"
placeholder="Password"
fullWidth
name="password"
variant="outlined"
onChange={(e) => setPassword(e.target.value)}
/>
</Grid>
<Grid item>
<Button className={classes.buttonBlock}
variant="contained"
color="primary"
type="submit"
>
Log in
</Button>
</Grid>
</Grid>
</form>
</Grid>
<Grid item>
<Link href="#" variant="body2">
Wachtwoord vergeten?
</Link>
</Grid>
</Paper>
</Grid>
</Grid>
</Grid>
);
}
/*
const values = {
"username" : event.target.username.value,
"password" : event.target.password.value
};
*/
/*
login(loginRequest)
.then(response => {
localStorage.setItem(ACCESS_TOKEN, response.accessToken);
getCurrentUser().then((response: CurrentUser) => {
props.setUser({currentUser: response, isAuthenticated: true})
}).then(() => history.push('/home/user'));
}).catch(error => {
if (error.status === 401) {
console.log("Your Username or Password is incorrect. Please try again!");
} else {
console.log("Sorry! Something went wrong. Please try again!");
}
});
*/

60
src/screens/Profile.tsx Normal file
View File

@ -0,0 +1,60 @@
import React, {useEffect} from "react";
import {useDispatch, useSelector} from "react-redux";
import {getUserDetails} from "../actions/user-actions";
import {makeStyles, Theme} from "@material-ui/core/styles";
import {Grid, ListItem, ListItemText, List} from '@material-ui/core';
import {AlertMessage} from "../components/Alert";
import {Loader} from "../components/Loader";
const useStyles = makeStyles((theme: Theme) => ({
ProfileContainer: {
spacing: 0,
justifyContent : 'center',
direction: 'initial',
marginTop: '4vh'
},
}));
export const Profile = ({Location, history}: {Location: any, history: any}) => {
const dispatch = useDispatch();
const userDetails = useSelector((state: State) => state.userDetails)
const {error, loading, user} = userDetails;
const userLogin = useSelector((state: State) => state.userLogin)
const { userInfo } = userLogin;
useEffect(() => {
if(!userInfo){
history.push('/login')
} else {
if(!user || !user.username){
dispatch(getUserDetails(userInfo.id))
}// else {setMember(user.member);}
}
}, [user, userInfo, dispatch, history])
const classes = useStyles();
return (
<Grid container className={classes.ProfileContainer}>
{error && <AlertMessage variant={'danger'}>{error}</AlertMessage>}
{loading && <Loader />}
{user && user.member &&
<Grid item>
<List style={{display: 'flex', flexDirection: 'column', padding: 0}}>
<ListItem>
<ListItemText>{user.member.member}</ListItemText>
</ListItem>
<ListItem>
<ListItemText>{user.member.neighbourhood}</ListItemText>
</ListItem>
<ListItem>
<ListItemText>{user.member.registrationDate}</ListItemText>
</ListItem>
</List>
</Grid>
}
</Grid>
);
}

5
src/setupTests.ts Normal file
View File

@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';

37
src/typings/index.d.ts vendored Normal file
View File

@ -0,0 +1,37 @@
type State = {
userLogin: UserLogin,
userDetails: UserDetails
}
type UserLogin = {
loading: boolean,
error: string
userInfo: {
refresh: string,
access: string,
username: string,
email: string,
id: number
}
}
type UserDetails = {
loading: boolean,
error: string
user: User
}
type User = {
first_name: string,
last_name: string,
username: string,
member: Member
}
type Member = {
member: string,
registrationDate: string
active: boolean,
neighbourhood: string
}

26
tsconfig.json Normal file
View File

@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}

12031
yarn.lock Normal file

File diff suppressed because it is too large Load Diff