Commit 54f598a1 authored by Tamás Danis's avatar Tamás Danis

fix logout

parent 4a9b4c8b
......@@ -3,7 +3,6 @@ export const LOGIN_ERROR = 'LOGIN_ERROR';
export const REGISTER_SUCCESS = 'REGISTER_SUCCESS';
export const REGISTER_ERROR = 'REGISTER_ERROR';
export const LOGOUT = 'LOGOUT';
export const LOGGED_OUT = 'LOGGED_OUT';
export const SAVE_TRANSACTION = 'SAVE_TRANSACTION';
export const FETCH_TRANSACTIONS = 'FETCH_TRANSACTIONS';
......@@ -30,7 +30,3 @@ export function register(registerData) {
export function logout() {
return dispatch => dispatch({ type: types.LOGOUT });
}
export function loggedOut() {
return dispatch => dispatch({ type: types.LOGGED_OUT });
}
import React, { Component } from 'react';
import React from 'react';
import { Switch, Route } from 'react-router-dom';
import Header from './common/Header';
import Main from './Main';
import Auth from './layouts/Auth';
import Main from './layouts/Main';
class App extends Component {
// constructor(props) {
// super(props);
// this.state = {
// isLoggedIn: false,
// user: {}
// };
// }
render() {
return (
<>
<Header />
<Main />
</>
);
}
}
const App = () => (
<>
<Header/>
<Switch>
<Route exact path="/login" component={Auth}/>
<Route exact path="/register" component={Auth}/>
<Route path="/" component={Main}/>
</Switch>
</>
);
export default App;
import React from 'react';
import { Switch, Route } from 'react-router-dom';
import Dashboard from './layouts/Dashboard';
import Auth from './layouts/Auth';
const Main =() => {
return (
<Switch>
<Route exact path="/login" component={Auth}/>
<Route exact path="/register" component={Auth}/>
<Route exact path="/main" component={Dashboard}/>
<Route path="/" component={Dashboard}/>
</Switch>
);
};
export default Main;
......@@ -10,7 +10,7 @@ const Header = ({ auth, actions }) => {
const navLinks = auth.loggedIn ? navItems : authNavItems;
const handleClick = e => {
const handleLogout = e => {
e.preventDefault();
actions.logout();
};
......@@ -33,7 +33,7 @@ const Header = ({ auth, actions }) => {
))}
{auth.loggedIn
? <li className="nav-item">
<Link className="nav-link" to="/" onClick={handleClick}>Logout</Link>
<Link className="nav-link" to="/" onClick={handleLogout}>Logout</Link>
</li>
: null}
......
......@@ -2,6 +2,7 @@ import React from 'react';
import { Switch, Route } from 'react-router-dom';
import Login from './Auth/Login';
import Register from './Auth/Register';
import { LOGIN, REGISTER } from '../../data/routes';
const Auth = () => {
return (
......@@ -9,8 +10,8 @@ const Auth = () => {
<div className="row margin-auto">
<div className="col-md-12" style={{ minWidth: '500px' }}>
<Switch>
<Route path="/login" component={Login}/>
<Route path="/register" component={Register}/>
<Route path={LOGIN} component={Login}/>
<Route path={REGISTER} component={Register}/>
</Switch>
</div>
</div>
......
......@@ -9,8 +9,7 @@ import ButtonField from '../../../common/form/ButtonField';
import * as authActions from '../../../../actions/authActions';
import { email, minLength5, required } from '../../../../validation/validation';
const LoginForm = props => {
const { auth, actions, data, valid } = props;
const LoginForm = ({ auth, actions, data, valid }) => {
const handleSubmit = e => {
e.preventDefault();
actions.login(data);
......@@ -56,13 +55,14 @@ LoginForm.defaultProps = {
const selector = formValueSelector('loginForm');
const mapStateToProps = (state) => ({
auth: state.auth,
data: {
email: selector(state, 'email'),
password: selector(state, 'password')
const mapStateToProps = state => ({
auth: state.auth,
data: {
email: selector(state, 'email'),
password: selector(state, 'password')
}
}
});
);
const mapDispatchToProps = dispatch => {
return {
actions: bindActionCreators(authActions, dispatch)
......
......@@ -15,9 +15,7 @@ import {
minLength5
} from '../../../../validation/validation';
const RegisterForm = props => {
const { actions, data, valid } = props;
// console.log(props)
const RegisterForm = ({ actions, data, valid }) => {
const handleSubmit = e => {
e.preventDefault();
......
import React, { Component } from 'react';
import TransactionForm from './DashBoard/TransactionForm';
import TransactionList from './DashBoard/TransactionList';
class Dashboard extends Component {
render() {
return (
<>
<main>
<div className="container">
<div className="row">
<div className="col-md-12">
<h1>Dashboard</h1>
<TransactionForm/>
<TransactionList/>
</div>
</div>
</div>
</main>
</>
);
}
}
export default Dashboard;
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Redirect, Route, Switch } from 'react-router-dom';
import Dashboard from './Main/Dashboard';
import { DASHBOARD, GROUPS, SETTINGS } from '../../data/routes';
import Groups from './Main/Groups';
import Settings from './Main/Settings';
const Main = ({ loggedIn }) => {
if (!loggedIn) return <Redirect to='/login'/>;
return (
<main>
<div className="container">
<div className="row">
<div className="col-md-12">
<Switch>
<Route exact path={DASHBOARD} component={Dashboard}/>
<Route path={GROUPS} component={Groups}/>
<Route path={SETTINGS} component={Settings}/>
</Switch>
</div>
</div>
</div>
</main>
);
};
Main.propTypes = {
loggedIn: PropTypes.bool.isRequired
};
const mapStateToProps = state => ({
loggedIn: state.auth.loggedIn
});
export default connect(mapStateToProps)(Main);
......@@ -3,11 +3,11 @@ import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Field, formValueSelector, reduxForm } from 'redux-form';
import { bindActionCreators } from 'redux';
import moment from 'moment';
import InputField from '../../common/form/InputField';
import { required, numeric } from '../../../validation/validation';
import ButtonField from '../../common/form/ButtonField';
import * as transactionActions from '../../../actions/transactionActions';
import moment from 'moment/moment';
import InputField from '../../../common/form/InputField';
import { required, numeric } from '../../../../validation/validation';
import ButtonField from '../../../common/form/ButtonField';
import * as transactionActions from '../../../../actions/transactionActions';
const TransactionForm = ({ valid, actions, data }) => {
......@@ -69,7 +69,7 @@ TransactionForm.defaultProps = {
const selector = formValueSelector('transactionForm');
const mapStateToProps = (state) => ({
const mapStateToProps = state => ({
initialValues: {
date: moment().format('YYYY-MM-DD')
},
......
import React, { Component } from 'react';
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import TransactionListItem from './TransactionListItem';
import * as transactionActions from '../../../actions/transactionActions';
class TransactionList extends Component {
//
// static propTypes = {
// actions: PropTypes.func.isRequired,
//
// transactions: PropTypes.array.isRequired
// };
componentDidMount() {
this.props.actions.fetchTransactions();
}
render() {
const { transactions } = this.props;
return (
<ul className="list-group">
{transactions.map(transaction => (
<TransactionListItem key={transaction.id} transaction={transaction}/>
))}
</ul>
);
};
}
import * as transactionActions from '../../../../actions/transactionActions';
const TransactionList = ({ actions, transactions }) => {
useEffect(() => {
actions.fetchTransactions();
}, []);
return (
<ul className="list-group">
{transactions.map(transaction => (
<TransactionListItem key={transaction.id} transaction={transaction}/>
))}
</ul>
);
};
TransactionList.propTypes = {
actions: PropTypes.object.isRequired,
transactions: PropTypes.array.isRequired
};
const mapStateToProps = ({ transactions }) => ({
transactions
......
import React from 'react';
import TransactionForm from './DashBoard/TransactionForm';
import TransactionList from './DashBoard/TransactionList';
const Dashboard = () => (
<>
<h1 className="pt-3">Dashboard</h1>
<TransactionForm/>
<TransactionList/>
</>
);
export default Dashboard;
import React from 'react';
const Groups = () => (
<>
<h1>Groups</h1>
</>
);
export default Groups;
import React from 'react';
const Settings = () => (
<>
<h1>Settings</h1>
</>
);
export default Settings;
import { GROUPS, LOGIN, MAIN, REGISTER, SETTINGS } from './routes';
import { GROUPS, LOGIN, DASHBOARD, REGISTER, SETTINGS } from './routes';
export const authNavItems = [
{
......@@ -14,7 +14,7 @@ export const authNavItems = [
export const navItems = [
{
title: 'Main',
route: MAIN
route: DASHBOARD
},
{
title: 'Groups',
......
export const LOGIN = '/login';
export const REGISTER = '/register';
export const MAIN = '/main';
export const DASHBOARD = '/';
export const GROUPS = '/groups';
export const SETTINGS = '/settings';
......@@ -4,16 +4,16 @@ import initialState from './initialState';
const auth = (state = initialState.auth, action) => {
switch (action.type) {
case types.LOGIN_SUCCESS:
localStorage.setItem('auth_token', action.user.auth_token);
localStorage.setItem('auth_user', JSON.stringify(action.user));
return {
...state,
...action.auth,
user: action.user,
loggedIn: true
};
case types.LOGIN_ERROR:
return {
...state,
...action.auth,
...action.user,
loggedIn: false,
hasError: true,
error: { message: 'User does not exists or password is wrong' }
......@@ -24,15 +24,11 @@ const auth = (state = initialState.auth, action) => {
window.location.replace('/login');
return state;
case types.LOGOUT:
localStorage.removeItem('auth_user');
return {
...state,
loggedIn: false,
redirect: true
};
case types.LOGGED_OUT:
return {
...state,
redirect: false
user: {},
loggedIn: false
};
default:
return state;
......
const storedUser = JSON.parse(localStorage.getItem('auth_user'));
const authUser = storedUser || {};
export default {
auth: {
loggedIn: false,
user: authUser,
loggedIn: Boolean(storedUser),
hasError: false,
error: {},
redirect: false
......
......@@ -11,8 +11,8 @@
|
*/
Route::get('/', 'HomeController@index')->name('home');
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/', 'HomeController@index');
//Route::get('/home', 'HomeController@index')->name('home');
Auth::routes();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment