scinote-web/app/javascript/packs/shared/actions/UsersActions.js

50 lines
991 B
JavaScript
Raw Normal View History

2017-08-09 15:08:13 +08:00
import axios from "axios";
import { CURRENT_USER_PATH } from "../../app/routes";
2017-08-11 21:04:36 +08:00
import {
SET_CURRENT_USER,
CHANGE_CURRENT_USER_FULL_NAME,
CHANGE_CURRENT_USER_INITIALS,
CHANGE_CURRENT_USER_EMAIL
} from "../../app/action_types";
2017-08-09 15:08:13 +08:00
function addCurrentUser(data) {
return {
type: SET_CURRENT_USER,
payload: data
};
}
export function getCurrentUser() {
return dispatch => {
axios
.get(CURRENT_USER_PATH, { withCredentials: true })
.then(({ data }) => {
dispatch(addCurrentUser(data.user));
})
.catch(error => {
console.log("get Current User Error: ", error);
});
};
}
2017-08-11 21:04:36 +08:00
export function changeFullName(name) {
return {
type: CHANGE_CURRENT_USER_FULL_NAME,
payload: name
};
}
export function changeInitials(initials) {
return {
type: CHANGE_CURRENT_USER_INITIALS,
payload: initials
};
}
export function changeEmail(email) {
return {
type: CHANGE_CURRENT_USER_EMAIL,
payload: email
};
}