fixed image upload

This commit is contained in:
zmagod 2017-09-27 09:17:09 +02:00
parent e2aa0d7515
commit 66269d68ff
6 changed files with 45 additions and 45 deletions

View file

@ -51,7 +51,7 @@ module ClientApi
bypass_sign_in(current_user) bypass_sign_in(current_user)
success_response success_response
else else
unsuccess_response(current_user.errors.full_messages) unsuccess_response(current_user.errors.full_messages, :unauthorized)
end end
rescue CustomUserError => error rescue CustomUserError => error
unsuccess_response(error.to_s) unsuccess_response(error.to_s)
@ -97,11 +97,11 @@ module ClientApi
end end
end end
def unsuccess_response(message) def unsuccess_response(message, status = :unprocessable_entity)
respond_to do |format| respond_to do |format|
format.json do format.json do
render json: { message: message }, render json: { message: message },
status: :unprocessable_entity status: status
end end
end end
end end

View file

@ -5,21 +5,30 @@ import { NavDropdown, MenuItem, Image } from "react-bootstrap";
import styled from "styled-components"; import styled from "styled-components";
import { FormattedMessage } from "react-intl"; 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)` const StyledNavDropdown = styled(NavDropdown)`
& #user-account-dropdown { & #user-account-dropdown {
padding-top: 10px; padding-top: 10px;
padding-bottom: 10px; padding-bottom: 10px;
} }
`;
const StyledAvatar = styled(Image)`
max-width: 30px;
max-height: 30px;
`; `;
class UserAccountDropdown extends Component { class UserAccountDropdown extends Component {
componentDidMount() { componentDidMount() {
this.props.getCurrentUser(); getCurrentUser().then(data => {
this.props.addCurrentUser(data);
});
} }
render() { render() {
const { fullName, avatarThumb } = this.props.current_user;
return ( return (
<StyledNavDropdown <StyledNavDropdown
id="user-account-dropdown" id="user-account-dropdown"
@ -29,11 +38,11 @@ class UserAccountDropdown extends Component {
<span> <span>
<FormattedMessage <FormattedMessage
id="user_account_dropdown.greeting" id="user_account_dropdown.greeting"
values={{ name: this.props.current_user.fullName }} values={{ name: fullName }}
/>&nbsp; />&nbsp;
<Image <StyledAvatar
src={this.props.current_user.avatarPath} src={`${avatarThumb }?${new Date().getTime()}`}
alt={this.props.current_user.fullName} alt={fullName}
circle circle
/> />
</span> </span>
@ -52,24 +61,17 @@ class UserAccountDropdown extends Component {
} }
UserAccountDropdown.propTypes = { UserAccountDropdown.propTypes = {
getCurrentUser: PropTypes.func.isRequired, addCurrentUser: PropTypes.func.isRequired,
current_user: PropTypes.shape({ current_user: PropTypes.shape({
id: PropTypes.number.isRequired, id: PropTypes.number.isRequired,
fullName: PropTypes.string.isRequired, fullName: PropTypes.string.isRequired,
avatarPath: PropTypes.string.isRequired avatarThumb: PropTypes.string.isRequired
}).isRequired }).isRequired
}; };
// Map the states from store to component // Map the states from store to component
const mapStateToProps = ({ current_user }) => ({ current_user }); const mapStateToProps = ({ current_user }) => ({ current_user });
// Map the fetch activity action to component export default connect(mapStateToProps, { addCurrentUser })(
const mapDispatchToProps = dispatch => ({
getCurrentUser() {
dispatch(getCurrentUser());
}
});
export default connect(mapStateToProps, mapDispatchToProps)(
UserAccountDropdown UserAccountDropdown
); );

View file

@ -1,7 +1,6 @@
import axios from "../../config/axios"; import axios from "../../config/axios";
import { import {
CURRENT_USER_PATH,
CHANGE_USER_TIMEZONE_PATH, CHANGE_USER_TIMEZONE_PATH,
CHANGE_USER_ASSIGNEMENTS_NOTIFICATION_PATH, CHANGE_USER_ASSIGNEMENTS_NOTIFICATION_PATH,
CHANGE_USER_ASSIGNMENTS_NOTIFICATION_EMAIL_PATH, CHANGE_USER_ASSIGNMENTS_NOTIFICATION_EMAIL_PATH,
@ -20,26 +19,13 @@ import {
CHANGE_SYSTEM_MESSAGE_NOTIFICATION_EMAIL CHANGE_SYSTEM_MESSAGE_NOTIFICATION_EMAIL
} from "../../config/action_types"; } from "../../config/action_types";
function addCurrentUser(data) { export function addCurrentUser(data) {
return { return {
type: SET_CURRENT_USER, type: SET_CURRENT_USER,
payload: data 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 }) { export function saveTimezone({ timezone }) {
return { return {
type: CHANGE_CURRENT_USER_TIMEZONE, type: CHANGE_CURRENT_USER_TIMEZONE,

View file

@ -299,7 +299,7 @@ class InputEnabled extends Component {
<FormControl <FormControl
type="password" type="password"
value={this.state.current_password} value={this.state.current_password}
onChange={this.handlePasswordConfirmation} onChange={this.handleCurrentPassword}
/> />
</div> </div>
); );
@ -400,7 +400,7 @@ InputEnabled.propTypes = {
}; };
InputEnabled.defaultProps = { InputEnabled.defaultProps = {
forceRerender: false forceRerender: () => (false)
} }
export default InputEnabled; export default InputEnabled;

View file

@ -1,8 +1,10 @@
import React, { Component } from "react"; import React, { Component } from "react";
import { func } from "prop-types"; import { func } from "prop-types";
import { connect } from "react-redux";
import styled from "styled-components"; import styled from "styled-components";
import { FormattedMessage } from "react-intl"; import { FormattedMessage } from "react-intl";
import { getUserProfileInfo } from "../../../../../services/api/users_api"; import { getUserProfileInfo } from "../../../../../services/api/users_api";
import { addCurrentUser } from "../../../../../components/actions/UsersActions";
import AvatarInputField from "./AvatarInputField"; import AvatarInputField from "./AvatarInputField";
import ProfileInputField from "./ProfileInputField"; import ProfileInputField from "./ProfileInputField";
@ -25,7 +27,7 @@ class MyProfile extends Component {
timeZone: "", timeZone: "",
newEmail: "" newEmail: ""
}; };
this.loadInfo = this.loadInfo.bind(this) this.loadInfo = this.loadInfo.bind(this);
} }
componentDidMount() { componentDidMount() {
@ -37,6 +39,7 @@ class MyProfile extends Component {
.then(data => { .then(data => {
const { fullName, initials, email, avatarThumb, timeZone } = data; const { fullName, initials, email, avatarThumb, timeZone } = data;
this.setState({ fullName, initials, email, avatarThumb, timeZone }); this.setState({ fullName, initials, email, avatarThumb, timeZone });
this.props.addCurrentUser(data);
}) })
.catch(error => { .catch(error => {
console.log(error); console.log(error);
@ -52,8 +55,10 @@ class MyProfile extends Component {
<AvatarLabel> <AvatarLabel>
<FormattedMessage id="settings_page.avatar" /> <FormattedMessage id="settings_page.avatar" />
</AvatarLabel> </AvatarLabel>
<AvatarInputField reloadInfo={this.loadInfo} <AvatarInputField
imgSource={this.state.avatarThumb} /> reloadInfo={this.loadInfo}
imgSource={this.state.avatarThumb}
/>
<ProfileInputField <ProfileInputField
value={this.state.fullName} value={this.state.fullName}
@ -94,4 +99,4 @@ class MyProfile extends Component {
} }
} }
export default MyProfile; export default connect(null, { addCurrentUser })(MyProfile);

View file

@ -1,5 +1,9 @@
import { axiosInstance } from "./config"; import { axiosInstance } from "./config";
import { USER_PROFILE_INFO, UPDATE_USER_PATH } from "./endpoints"; import {
USER_PROFILE_INFO,
UPDATE_USER_PATH,
CURRENT_USER_PATH
} from "./endpoints";
export const getUserProfileInfo = () => { export const getUserProfileInfo = () => {
return axiosInstance.get(USER_PROFILE_INFO).then(({ data }) => data.user); 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 }) .post(UPDATE_USER_PATH, { user: params })
.then(({ data }) => data.user); .then(({ data }) => data.user);
}; };
export const getCurrentUser = () =>
axiosInstance.get(CURRENT_USER_PATH).then(({ data }) => data.user);