mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-12 16:57:39 -05:00
Admin is mostly working
This commit is contained in:
46
admin/src/User/user-actions.js
Normal file
46
admin/src/User/user-actions.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import axios from "axios";
|
||||
//import { browserHistory } from "react-router"
|
||||
import * as types from "./user-constants";
|
||||
import { push } from 'connected-react-router';
|
||||
|
||||
|
||||
// "Log Out" action creators
|
||||
function beginLogout() {
|
||||
return { type: types.LOGOUT_USER };
|
||||
}
|
||||
|
||||
function logoutSuccess() {
|
||||
return { type: types.LOGOUT_SUCCESS_USER };
|
||||
}
|
||||
|
||||
function logoutError() {
|
||||
return { type: types.LOGOUT_ERROR_USER };
|
||||
}
|
||||
|
||||
// Example of an Async Action Creator
|
||||
// http://redux.js.org/docs/advanced/AsyncActions.html
|
||||
export function manualLogout() {
|
||||
return dispatch => {
|
||||
dispatch(beginLogout());
|
||||
|
||||
return axios
|
||||
.get(process.env.REACT_APP_ACCOUNT_SERVER + "/logout", {withCredentials: true})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(logoutSuccess());
|
||||
// use browserHistory singleton to control navigation. Will generate a
|
||||
// state change for time-traveling as we are using the react-router-redux package
|
||||
//browserHistory.push("/") // logout to home page
|
||||
dispatch(push("/"));
|
||||
} else {
|
||||
dispatch(logoutError());
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened during logout that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
6
admin/src/User/user-constants.js
Normal file
6
admin/src/User/user-constants.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export const LOGIN_SUCCESS_USER = "LOGIN_SUCCESS_USER"
|
||||
export const LOGIN_EMAIL_ERROR_USER = "LOGIN_EMAIL_ERROR_USER"
|
||||
export const LOGIN_ERROR_USER = "LOGIN_ERROR_USER"
|
||||
export const LOGOUT_USER = "LOGOUT_USER"
|
||||
export const LOGOUT_SUCCESS_USER = "LOGOUT_SUCCESS_USER"
|
||||
export const LOGOUT_ERROR_USER = "LOGOUT_ERROR_USER"
|
||||
55
admin/src/User/user-reducer.js
Normal file
55
admin/src/User/user-reducer.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
LOGOUT_USER,
|
||||
LOGOUT_SUCCESS_USER,
|
||||
LOGOUT_ERROR_USER,
|
||||
LOGIN_SUCCESS_USER,
|
||||
LOGIN_ERROR_USER,
|
||||
LOGIN_EMAIL_ERROR_USER
|
||||
} from "./user-constants";
|
||||
|
||||
const user = (
|
||||
state = {
|
||||
isWaiting: false,
|
||||
authenticated: false,
|
||||
userId: ""
|
||||
},
|
||||
action
|
||||
) => {
|
||||
switch (action.type) {
|
||||
case LOGIN_SUCCESS_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
authenticated: true,
|
||||
...action.data
|
||||
});
|
||||
case LOGIN_EMAIL_ERROR_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
authenticated: false,
|
||||
userId: action.data.userId
|
||||
});
|
||||
case LOGIN_ERROR_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
authenticated: false
|
||||
});
|
||||
case LOGOUT_USER:
|
||||
return Object.assign({}, state, { isWaiting: true });
|
||||
case LOGOUT_SUCCESS_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
authenticated: false,
|
||||
email: "",
|
||||
userId: ""
|
||||
});
|
||||
case LOGOUT_ERROR_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
authenticated: true
|
||||
});
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default user;
|
||||
Reference in New Issue
Block a user