From 0de080485eda6eb926ed4ba3f794e61c0ae8d3cf Mon Sep 17 00:00:00 2001 From: Toni Dezman Date: Thu, 10 Aug 2017 16:58:47 +0200 Subject: [PATCH] adds avatar and editable inputs --- .../packs/src/settings/components/Avatar.jsx | 10 +++ .../src/settings/components/InputDisabled.jsx | 25 ++++++ .../src/settings/components/InputEnabled.jsx | 51 +++++++++++ .../src/settings/components/MyProfile.jsx | 90 +++++++++++++++++++ app/views/client_api/users/show.json.jbuilder | 1 + 5 files changed, 177 insertions(+) create mode 100644 app/javascript/packs/src/settings/components/Avatar.jsx create mode 100644 app/javascript/packs/src/settings/components/InputDisabled.jsx create mode 100644 app/javascript/packs/src/settings/components/InputEnabled.jsx create mode 100644 app/javascript/packs/src/settings/components/MyProfile.jsx diff --git a/app/javascript/packs/src/settings/components/Avatar.jsx b/app/javascript/packs/src/settings/components/Avatar.jsx new file mode 100644 index 000000000..a44bbc78b --- /dev/null +++ b/app/javascript/packs/src/settings/components/Avatar.jsx @@ -0,0 +1,10 @@ +import React from "react"; +import { string } from "prop-types"; + +const Avatar = props => default avatar; + +Avatar.propTypes = { + imgSource: string.isRequired +}; + +export default Avatar; diff --git a/app/javascript/packs/src/settings/components/InputDisabled.jsx b/app/javascript/packs/src/settings/components/InputDisabled.jsx new file mode 100644 index 000000000..0c64ac4c8 --- /dev/null +++ b/app/javascript/packs/src/settings/components/InputDisabled.jsx @@ -0,0 +1,25 @@ +import React from "react"; +import { string, func } from "prop-types"; +import { FormGroup, FormControl, ControlLabel, Button } from "react-bootstrap"; + +const InputDisabled = props => +
+ + + {props.labelValue} + + + + +
; + +InputDisabled.propTypes = { + labelValue: string.isRequired, + inputType: string.isRequired, + inputValue: string.isRequired, + enableEdit: func.isRequired +}; + +export default InputDisabled; diff --git a/app/javascript/packs/src/settings/components/InputEnabled.jsx b/app/javascript/packs/src/settings/components/InputEnabled.jsx new file mode 100644 index 000000000..f795b0428 --- /dev/null +++ b/app/javascript/packs/src/settings/components/InputEnabled.jsx @@ -0,0 +1,51 @@ +import React, { Component } from "react"; +import PropTypes from "prop-types"; +import { FormGroup, FormControl, ControlLabel, Button } from "react-bootstrap"; + +class InputEnabled extends Component { + constructor(props) { + super(props); + + this.state = { + value: this.props.inputValue + }; + + this.handleChange = this.handleChange.bind(this); + } + + handleChange(event) { + this.setState({ value: event.target.value }); + } + + render() { + return ( +
+
+ + + {this.props.labelValue} + + + + + +
+
+ ); + } +} + +InputEnabled.propTypes = { + labelValue: PropTypes.string.isRequired, + inputType: PropTypes.string.isRequired, + inputValue: PropTypes.string.isRequired, + disableEdit: PropTypes.func.isRequired +}; + +export default InputEnabled; diff --git a/app/javascript/packs/src/settings/components/MyProfile.jsx b/app/javascript/packs/src/settings/components/MyProfile.jsx new file mode 100644 index 000000000..2cdd9fb68 --- /dev/null +++ b/app/javascript/packs/src/settings/components/MyProfile.jsx @@ -0,0 +1,90 @@ +import React, { Component } from "react"; +import axios from "axios"; +import _ from "lodash"; + +import Avatar from "./Avatar"; +import InputDisabled from "./InputDisabled"; +import InputEnabled from "./InputEnabled"; + +import { CURRENT_USER_PATH } from "../../../app/routes"; + +class MyProfile extends Component { + constructor(props) { + super(props); + + this.state = { + avatar: "", + inputs: { + fullName: { + label: "Full name", + value: "", + isEditable: false + } + } + }; + + this.toggleIsEditable = this.toggleIsEditable.bind(this); + } + + componentDidMount() { + axios.get(CURRENT_USER_PATH, { withCredentials: true }).then(data => { + const userData = data.data.user; + this.setState(previousState => + _.merge({}, previousState, { + avatar: userData.avatarThumbPath, + inputs: { + fullName: { + value: userData.fullName + } + } + }) + ); + }); + } + + toggleIsEditable(e) { + const currEditableState = this.state.inputs.fullName.isEditable; + e.preventDefault(); + this.setState(previousState => + _.merge({}, previousState, { + inputs: { fullName: { isEditable: !currEditableState } } + }) + ); + } + + render() { + let fullNameField; + const fullNameState = this.state.inputs.fullName; + + if (this.state.inputs.fullName.isEditable) { + fullNameField = ( + + ); + } else { + fullNameField = ( + + ); + } + + return ( +
+

My Profile

+

Avatar

+ + {fullNameField} +
+ ); + } +} + +export default MyProfile; diff --git a/app/views/client_api/users/show.json.jbuilder b/app/views/client_api/users/show.json.jbuilder index 91a8f4081..69cbd571d 100644 --- a/app/views/client_api/users/show.json.jbuilder +++ b/app/views/client_api/users/show.json.jbuilder @@ -2,4 +2,5 @@ json.user do json.id user.id json.fullName user.full_name json.avatarPath avatar_path(user, :icon_small) + json.avatarThumbPath avatar_path(user, :thumb) end