Skip to content

Commit

Permalink
Merge pull request #4 from Kestava-keikkatyo/fiilismittari
Browse files Browse the repository at this point in the history
Fiilismittari
  • Loading branch information
wesenbergg authored Feb 10, 2021
2 parents 0750e90 + 9390b66 commit 60d2012
Show file tree
Hide file tree
Showing 59 changed files with 1,334 additions and 413 deletions.
2 changes: 1 addition & 1 deletion docs/components_LandingPage_LogInForm.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1 class="page-title">Source: components/LandingPage/LogInForm.js</h1>
import PropTypes from 'prop-types'
import { useTranslation } from 'react-i18next'

import { FormikTextField, FormikRadioField } from '../FormField'
import { FormikTextField, FormikRadioField } from '../../components/FormField'

import { Card, CardContent, Typography, Button, Box, CircularProgress } from '@material-ui/core'

Expand Down
2 changes: 1 addition & 1 deletion docs/components_LandingPage_SignUpForm.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1 class="page-title">Source: components/LandingPage/SignUpForm.js</h1>
import PropTypes from 'prop-types'
import { useTranslation } from 'react-i18next'

import { FormikTextField, FormikSelectField } from '../FormField'
import { FormikTextField, FormikSelectField } from '../../components/FormField'
import SignUpModal from './SignUpModal'

import {
Expand Down
2 changes: 1 addition & 1 deletion docs/components_ProfilePage_CompanyProfile.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h1 class="page-title">Source: components/ProfilePage/CompanyProfile.js</h1>
<pre class="prettyprint source linenums"><code>import React, { useState } from 'react'
import { Formik, Form } from 'formik'
import PropTypes from 'prop-types'
import { FormikTextField } from '../FormField'
import { FormikTextField } from '../../components/FormField'
import { Card, CardContent, Typography, Button, Box, FormControlLabel, Switch } from '@material-ui/core'

/**
Expand Down
2 changes: 1 addition & 1 deletion docs/components_ProfilePage_PasswordChange.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h1 class="page-title">Source: components/ProfilePage/PasswordChange.js</h1>
import { Formik, Form } from 'formik'
import PropTypes from 'prop-types'

import { FormikTextField } from '../FormField'
import { FormikTextField } from '../../components/FormField'

import { Card, CardContent, Typography, Button, Box } from '@material-ui/core'

Expand Down
2 changes: 1 addition & 1 deletion docs/components_ProfilePage_WorkerProfile.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1 class="page-title">Source: components/ProfilePage/WorkerProfile.js</h1>
import PropTypes from 'prop-types'
import * as Yup from 'yup'

import { FormikTextField } from '../FormField'
import { FormikTextField } from '../../components/FormField'

import {
Card,
Expand Down
40 changes: 40 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"axios": "^0.20.0",
"chart.js": "^2.9.4",
"formik": "^2.1.5",
"history": "^4.10.1",
"i18next": "^19.8.3",
"i18next-browser-languagedetector": "^6.0.1",
"i18next-xhr-backend": "^3.2.2",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-chartjs-2": "^2.11.1",
"react-collapsible": "^2.8.3",
"react-dom": "^16.13.1",
"react-i18next": "^11.7.3",
Expand Down
125 changes: 37 additions & 88 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,47 @@
import React, { useEffect, useState } from 'react'
import React, { useEffect } from 'react'
import { Switch, Route, Redirect, useLocation } from 'react-router-dom'
import { useSelector, useDispatch } from 'react-redux'

import LandingPage from './components/LandingPage'
import HomePage from './components/HomePage'
import ProfilePage from './components/ProfilePage'
import WorkersPage from './components/WorkersPage'
import ContractsPage from './components/ContractsPage'
import LandingPage from './pages/LandingPage'
import HomePage from './pages/HomePage'
import ProfilePage from './pages/ProfilePage'
import WorkersPage from './pages/WorkersPage'
import ContractsPage from './pages/ContractsPage'
import PrivateRoute from './components/PrivateRoute'
import ProcessPage from './components/ProcessPage'
import TasksPage from './components/TaskPage'
import MessagePage from './components/MessagePage'
import DocumentPage from './components/DocumentPage'
import FormsPage from './components/FormsPage'
import Drawer from './components/Drawer'
import AppBar from './components/AppBar'
import ProcessPage from './pages/ProcessPage'
import TasksPage from './pages/TaskPage'
import MessagePage from './pages/MessagePage'
import DocumentPage from './pages/DocumentPage'
import FormsPage from './pages/FormsPage'
import WorkerStatistics from './pages/WorkerStatistics'

import { clearAlert } from './actions/alertActions'
import Role from './utils/role'

import { CssBaseline, Snackbar, Toolbar } from '@material-ui/core'
import { CssBaseline, Snackbar } from '@material-ui/core'
import { Alert } from '@material-ui/lab'


/**
* App component, main react component which acts as a container for all the other components.
* @exports App
*/
const App = () => {
const { loggedIn, data } = useSelector((state) => state.user)
const alert = useSelector((state) => state.alert)
const dispatch = useDispatch()
const [open, setOpen] = useState(false)

const handleSnackbarClose = (_event, reason) => {
if (reason !== 'clickaway') {
dispatch(clearAlert())
}
}

/**
* Function for opening and closing drawer component.
* Passed as prop to [AppBar]{@link module:components/AppBar} and
* [Drawer]{@link module:components/Drawer}.
* @function
*/
const handleDrawer = () => {
setOpen((prevOpen) => !prevOpen)
}

// extra toolbar prevents content from going underneath appbar.
return (
<>
<ScrollToTop />
<CssBaseline />
<AppBar handleDrawer={handleDrawer} />
<Toolbar />
<Drawer
open={open}
handleDrawer={handleDrawer}
loggedIn={loggedIn}
role={data.role}
/>

<Snackbar open={alert.open} onClose={handleSnackbarClose}>
<Alert
onClose={handleSnackbarClose}
Expand All @@ -71,71 +52,39 @@ const App = () => {
</Alert>
</Snackbar>
<Switch>
<Route exact path="/">
{loggedIn ? <Redirect to="/home" /> : <LandingPage />}
</Route>
<Route path="/home">
<PrivateRoute path="/home" >
<HomePage />
</Route>
<PrivateRoute path="/profile" loggedIn={loggedIn}>
<ProfilePage />
</PrivateRoute>
<PrivateRoute
path="/contracts"
role={data.role}
roles={[Role.Agency]}
loggedIn={loggedIn}
>
<ContractsPage />
</PrivateRoute>
<PrivateRoute
path="/workers"
role={data.role}
roles={[Role.Business, Role.Agency]}
loggedIn={loggedIn}
>
<WorkersPage />
</PrivateRoute>
<PrivateRoute
path="/process"
role={data.role}
roles={[Role.Worker]}
loggedIn={loggedIn}
>
<ProcessPage />
<PrivateRoute path="/profile" >
<ProfilePage />
</PrivateRoute>
<PrivateRoute
path="/tasks"
role={data.role}
roles={[Role.Worker, Role.Agency, Role.Business]}
loggedIn={loggedIn}
>
<PrivateRoute path="/tasks" >
<TasksPage />
</PrivateRoute>
<PrivateRoute
path="/messages"
role={data.role}
roles={[Role.Worker, Role.Agency, Role.Business]}
loggedIn={loggedIn}
>
<PrivateRoute path="/messages" >
<MessagePage />
</PrivateRoute>
<PrivateRoute
path="/documents"
role={data.role}
roles={[Role.Worker, Role.Agency, Role.Business]}
loggedIn={loggedIn}
>
<PrivateRoute path="/documents" >
<DocumentPage />
</PrivateRoute>
<PrivateRoute
path="/forms"
role={data.role}
roles={[Role.Agency]}
loggedIn={loggedIn}
>
<PrivateRoute path="/process" roles={[Role.Worker]} >
<ProcessPage />
</PrivateRoute>
<PrivateRoute path="/fiilismittari" roles={[Role.Worker]} >
<WorkerStatistics />
</PrivateRoute>
<PrivateRoute path="/contracts" roles={[Role.Agency]} >
<ContractsPage />
</PrivateRoute>
<PrivateRoute path="/forms" roles={[Role.Agency]} >
<FormsPage />
</PrivateRoute>
<PrivateRoute path="/workers" roles={[Role.Business, Role.Agency]} >
<WorkersPage />
</PrivateRoute>
<Route exact path="/">
<LandingPage />
</Route>
<Redirect from="*" to="/home" />
</Switch>
</>
Expand Down
8 changes: 7 additions & 1 deletion src/actions/userActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export const me = (role) => {
type: userConstants.REQUEST
})
try {
//TODO: PURKKAMALLIRATKAISU
// Kirjautuessa sisään setItem ei ehdi päivittää loggedInnoAppUseria
if(!localStorage.getItem('loggedInnoAppUser'))
return
const { data: profile } = await userService.me(role)
dispatch({
type: userConstants.PROFILE_SUCCESS,
Expand Down Expand Up @@ -121,6 +125,7 @@ export const update = (updateData, role) => {
})
dispatch(setAlert('User information updated'))
} catch (error) {
console.log('update error');
statusHandler(dispatch, error)
}
}
Expand All @@ -134,7 +139,8 @@ export const update = (updateData, role) => {
*/
const statusHandler = (dispatch, response) => {
if (!response || response.status === 401 || response.status === 500) {
logoutUser()
// console.log(response.status);
// logoutUser()
dispatch({ type: userConstants.FAILURE })
dispatch(setAlert('invalid token', 'error'))
} else {
Expand Down
Binary file added src/assets/profile-thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions src/components/ActiveLastBreadcrumb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import Breadcrumbs from '@material-ui/core/Breadcrumbs';
import Link from '@material-ui/core/Link';

function handleClick(event) {
event.preventDefault();
console.info('You clicked a breadcrumb.');
}

export default function ActiveLastBreadcrumb() {
return (
<Breadcrumbs aria-label="breadcrumb">
<Link color="inherit" href="/" onClick={handleClick}>
Main
</Link>
{/* <Link color="inherit" href="/getting-started/installation/" onClick={handleClick}>
Core
</Link> */}
<Link
color="textPrimary"
href="/components/breadcrumbs/"
onClick={handleClick}
aria-current="page"
>
Feel-o-meter
</Link>
</Breadcrumbs>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import i18n, { getCurrentLocale } from '../i18nextInit'
import i18n, { getCurrentLocale } from '../../i18nextInit'

import {
AppBar as MUIAppBar,
Expand Down
8 changes: 6 additions & 2 deletions src/components/Drawer.js → src/components/Legacy/Drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import PropTypes from 'prop-types'
import { useDispatch } from 'react-redux'
import { useTranslation } from 'react-i18next'

import { logout } from '../actions/userActions'
import Role from '../utils/role'
import { logout } from '../../actions/userActions'
import Role from '../../utils/role'

import {
Divider,
Expand Down Expand Up @@ -83,6 +83,10 @@ const Drawer = ({ open, handleDrawer, loggedIn, role }) => {
<ListItemIcon><Home /></ListItemIcon>
<ListItemText primary={t('home')} />
</ListItem>
<ListItem button component={Link} to="/fiilismittari">
<ListItemIcon><Home /></ListItemIcon>
<ListItemText primary={t('home')} />
</ListItem>
{loggedIn &&
<ListItem button component={Link} to="/profile">
<ListItemIcon><AccountCircle /></ListItemIcon>
Expand Down
Loading

0 comments on commit 60d2012

Please sign in to comment.