From 66269d68ffc901521f61269bd4201b077b5b3834 Mon Sep 17 00:00:00 2001 From: zmagod Date: Wed, 27 Sep 2017 09:17:09 +0200 Subject: [PATCH] fixed image upload --- .../client_api/users/users_controller.rb | 6 +-- .../components/UserAccountDropdown.jsx | 42 ++++++++++--------- .../src/components/actions/UsersActions.js | 16 +------ .../profile/components/InputEnabled.jsx | 4 +- .../scenes/profile/components/MyProfile.jsx | 13 ++++-- app/javascript/src/services/api/users_api.js | 9 +++- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/app/controllers/client_api/users/users_controller.rb b/app/controllers/client_api/users/users_controller.rb index 650d4a9b7..6da879ed6 100644 --- a/app/controllers/client_api/users/users_controller.rb +++ b/app/controllers/client_api/users/users_controller.rb @@ -51,7 +51,7 @@ module ClientApi bypass_sign_in(current_user) success_response else - unsuccess_response(current_user.errors.full_messages) + unsuccess_response(current_user.errors.full_messages, :unauthorized) end rescue CustomUserError => error unsuccess_response(error.to_s) @@ -97,11 +97,11 @@ module ClientApi end end - def unsuccess_response(message) + def unsuccess_response(message, status = :unprocessable_entity) respond_to do |format| format.json do render json: { message: message }, - status: :unprocessable_entity + status: status end end end diff --git a/app/javascript/src/components/Navigation/components/UserAccountDropdown.jsx b/app/javascript/src/components/Navigation/components/UserAccountDropdown.jsx index caa239fb8..527324d17 100644 --- a/app/javascript/src/components/Navigation/components/UserAccountDropdown.jsx +++ b/app/javascript/src/components/Navigation/components/UserAccountDropdown.jsx @@ -5,21 +5,30 @@ import { NavDropdown, MenuItem, Image } from "react-bootstrap"; import styled from "styled-components"; import { FormattedMessage } from "react-intl"; -import { getCurrentUser } from "../../actions/UsersActions"; +import { getCurrentUser } from "../../../services/api/users_api"; +import { addCurrentUser } from "../../actions/UsersActions"; const StyledNavDropdown = styled(NavDropdown)` -& #user-account-dropdown { - padding-top: 10px; - padding-bottom: 10px; -} + & #user-account-dropdown { + padding-top: 10px; + padding-bottom: 10px; + } +`; + +const StyledAvatar = styled(Image)` + max-width: 30px; + max-height: 30px; `; class UserAccountDropdown extends Component { componentDidMount() { - this.props.getCurrentUser(); + getCurrentUser().then(data => { + this.props.addCurrentUser(data); + }); } render() { + const { fullName, avatarThumb } = this.props.current_user; return (   - {this.props.current_user.fullName} @@ -52,24 +61,17 @@ class UserAccountDropdown extends Component { } UserAccountDropdown.propTypes = { - getCurrentUser: PropTypes.func.isRequired, + addCurrentUser: PropTypes.func.isRequired, current_user: PropTypes.shape({ id: PropTypes.number.isRequired, fullName: PropTypes.string.isRequired, - avatarPath: PropTypes.string.isRequired + avatarThumb: PropTypes.string.isRequired }).isRequired }; // Map the states from store to component const mapStateToProps = ({ current_user }) => ({ current_user }); -// Map the fetch activity action to component -const mapDispatchToProps = dispatch => ({ - getCurrentUser() { - dispatch(getCurrentUser()); - } -}); - -export default connect(mapStateToProps, mapDispatchToProps)( +export default connect(mapStateToProps, { addCurrentUser })( UserAccountDropdown ); diff --git a/app/javascript/src/components/actions/UsersActions.js b/app/javascript/src/components/actions/UsersActions.js index 75c81aa82..215710318 100644 --- a/app/javascript/src/components/actions/UsersActions.js +++ b/app/javascript/src/components/actions/UsersActions.js @@ -1,7 +1,6 @@ import axios from "../../config/axios"; import { - CURRENT_USER_PATH, CHANGE_USER_TIMEZONE_PATH, CHANGE_USER_ASSIGNEMENTS_NOTIFICATION_PATH, CHANGE_USER_ASSIGNMENTS_NOTIFICATION_EMAIL_PATH, @@ -20,26 +19,13 @@ import { CHANGE_SYSTEM_MESSAGE_NOTIFICATION_EMAIL } from "../../config/action_types"; -function addCurrentUser(data) { +export 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); - }); - }; -} - export function saveTimezone({ timezone }) { return { type: CHANGE_CURRENT_USER_TIMEZONE, diff --git a/app/javascript/src/scenes/SettingsPage/scenes/profile/components/InputEnabled.jsx b/app/javascript/src/scenes/SettingsPage/scenes/profile/components/InputEnabled.jsx index 0e0182a6b..f7fc6ccc0 100644 --- a/app/javascript/src/scenes/SettingsPage/scenes/profile/components/InputEnabled.jsx +++ b/app/javascript/src/scenes/SettingsPage/scenes/profile/components/InputEnabled.jsx @@ -299,7 +299,7 @@ class InputEnabled extends Component { ); @@ -400,7 +400,7 @@ InputEnabled.propTypes = { }; InputEnabled.defaultProps = { - forceRerender: false + forceRerender: () => (false) } export default InputEnabled; diff --git a/app/javascript/src/scenes/SettingsPage/scenes/profile/components/MyProfile.jsx b/app/javascript/src/scenes/SettingsPage/scenes/profile/components/MyProfile.jsx index 0e26c47c8..15ab8c2e6 100644 --- a/app/javascript/src/scenes/SettingsPage/scenes/profile/components/MyProfile.jsx +++ b/app/javascript/src/scenes/SettingsPage/scenes/profile/components/MyProfile.jsx @@ -1,8 +1,10 @@ import React, { Component } from "react"; import { func } from "prop-types"; +import { connect } from "react-redux"; import styled from "styled-components"; import { FormattedMessage } from "react-intl"; import { getUserProfileInfo } from "../../../../../services/api/users_api"; +import { addCurrentUser } from "../../../../../components/actions/UsersActions"; import AvatarInputField from "./AvatarInputField"; import ProfileInputField from "./ProfileInputField"; @@ -25,7 +27,7 @@ class MyProfile extends Component { timeZone: "", newEmail: "" }; - this.loadInfo = this.loadInfo.bind(this) + this.loadInfo = this.loadInfo.bind(this); } componentDidMount() { @@ -37,6 +39,7 @@ class MyProfile extends Component { .then(data => { const { fullName, initials, email, avatarThumb, timeZone } = data; this.setState({ fullName, initials, email, avatarThumb, timeZone }); + this.props.addCurrentUser(data); }) .catch(error => { console.log(error); @@ -52,8 +55,10 @@ class MyProfile extends Component { - + { return axiosInstance.get(USER_PROFILE_INFO).then(({ data }) => data.user); @@ -15,3 +19,6 @@ export const updateUser = (params, formObj = false) => { .post(UPDATE_USER_PATH, { user: params }) .then(({ data }) => data.user); }; + +export const getCurrentUser = () => + axiosInstance.get(CURRENT_USER_PATH).then(({ data }) => data.user);