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

114 lines
2.3 KiB
JavaScript
Raw Normal View History

import axios from "../../app/axios";
2017-08-09 15:08:13 +08:00
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,
CHANGE_CURRENT_USER_PASSWORD,
2017-08-16 19:41:55 +08:00
CHANGE_CURRENT_USER_AVATAR,
2017-08-16 21:52:42 +08:00
CHANGE_CURRENT_USER_TIMEZONE,
2017-08-17 17:10:19 +08:00
CHANGE_ASSIGNMENTS_NOTIFICATION,
CHANGE_ASSIGNMENTS_NOTIFICATION_EMAIL,
CHANGE_RECENT_NOTIFICATION,
CHANGE_RECENT_NOTIFICATION_EMAIL,
CHANGE_SYSTEM_MESSAGE_NOTIFICATION_EMAIL
2017-08-11 21:04:36 +08:00
} 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
};
}
export function changePassword(password) {
return {
type: CHANGE_CURRENT_USER_PASSWORD,
payload: password
};
}
export function changeAvatar(avatarSrc) {
return {
type: CHANGE_CURRENT_USER_AVATAR,
payload: avatarSrc
};
}
2017-08-16 19:41:55 +08:00
export function changeTimezone(timezone) {
return {
type: CHANGE_CURRENT_USER_TIMEZONE,
payload: timezone
};
}
2017-08-16 21:52:42 +08:00
export function changeAssignmentsNotification(status) {
return {
2017-08-17 17:10:19 +08:00
type: CHANGE_ASSIGNMENTS_NOTIFICATION,
2017-08-16 21:52:42 +08:00
payload: status
};
}
2017-08-23 17:20:10 +08:00
2017-08-16 21:52:42 +08:00
export function changeAssignmentsNotificationEmail(status) {
return {
2017-08-17 17:10:19 +08:00
type: CHANGE_ASSIGNMENTS_NOTIFICATION_EMAIL,
2017-08-16 21:52:42 +08:00
payload: status
};
}
2017-08-23 17:20:10 +08:00
2017-08-16 21:52:42 +08:00
export function changeRecentNotification(status) {
return {
2017-08-17 17:10:19 +08:00
type: CHANGE_RECENT_NOTIFICATION,
2017-08-16 21:52:42 +08:00
payload: status
};
}
export function changeRecentNotificationEmail(status) {
return {
2017-08-17 17:10:19 +08:00
type: CHANGE_RECENT_NOTIFICATION_EMAIL,
2017-08-16 21:52:42 +08:00
payload: status
};
}
export function changeSystemMessageNotificationEmail(status) {
return {
2017-08-17 17:10:19 +08:00
type: CHANGE_SYSTEM_MESSAGE_NOTIFICATION_EMAIL,
2017-08-16 21:52:42 +08:00
payload: status
};
}