diff --git a/client/coral-framework/actions/user.js b/client/coral-framework/actions/user.js
index 04d5c9238..0000acc5c 100644
--- a/client/coral-framework/actions/user.js
+++ b/client/coral-framework/actions/user.js
@@ -2,15 +2,15 @@ import * as actions from '../constants/user';
import {base, handleResp, getInit} from '../helpers/response';
const saveBioRequest = () => ({type: actions.SAVE_BIO_REQUEST});
-const saveBioSuccess = user => ({type: actions.SAVE_BIO_SUCCESS, user});
+const saveBioSuccess = settings => ({type: actions.SAVE_BIO_SUCCESS, settings});
const saveBioFailure = error => ({type: actions.SAVE_BIO_FAILURE, error});
export const saveBio = (user_id, formData) => dispatch => {
dispatch(saveBioRequest());
- fetch(`${base}/${user_id}/bio`, getInit('POST', formData))
+ fetch(`${base}/user/${user_id}/bio`, getInit('PUT', formData))
.then(handleResp)
- .then(({user}) => {
- dispatch(saveBioSuccess(user));
+ .then(({settings}) => {
+ dispatch(saveBioSuccess(settings));
})
.catch(error => dispatch(saveBioFailure(error)));
};
diff --git a/client/coral-framework/reducers/user.js b/client/coral-framework/reducers/user.js
index 96307b293..f1d02a42c 100644
--- a/client/coral-framework/reducers/user.js
+++ b/client/coral-framework/reducers/user.js
@@ -4,8 +4,8 @@ import * as actions from '../constants/user';
const initialState = Map({
displayName: '',
- profiles: [],
- settings: []
+ profiles: null,
+ settings: null
});
const purge = user => {
@@ -29,7 +29,7 @@ export default function user (state = initialState, action) {
return initialState;
case actions.SAVE_BIO_SUCCESS:
return state
- .set('bio', action.user.bio);
+ .set('settings', action.settings);
default :
return state;
}
diff --git a/client/coral-settings/components/Bio.js b/client/coral-settings/components/Bio.js
index 36c3855df..c142ee5bc 100644
--- a/client/coral-settings/components/Bio.js
+++ b/client/coral-settings/components/Bio.js
@@ -2,15 +2,17 @@ import React from 'react';
import styles from './Bio.css';
import {Button} from '../../coral-ui';
-export default ({userData, bio, handleSave, handleChange}) => (
+export default ({bio, handleSave, handleInput}) => (
Bio
Tell the community about yourself
-
-
-
-
-
+
);
diff --git a/client/coral-settings/containers/BioContainer.js b/client/coral-settings/containers/BioContainer.js
index d3a04e14b..b045b71f9 100644
--- a/client/coral-settings/containers/BioContainer.js
+++ b/client/coral-settings/containers/BioContainer.js
@@ -5,31 +5,28 @@ export default class BioContainer extends Component {
constructor (props) {
super(props);
- this.state = {
- bio: ''
- };
-
this.handleSave = this.handleSave.bind(this);
- this.handleBioChange = this.handleBioChange.bind(this);
+ this.handleInput = this.handleInput.bind(this);
}
- handleBioChange(e) {
- this.setState({
- bio: e.target.value
+ handleInput(input) {
+ this.bioInput = input;
+ }
+
+ handleSave (e) {
+ e.preventDefault();
+ const {userData, saveBio} = this.props;
+ saveBio(userData.id, {
+ bio: this.bioInput.value
});
}
- handleSave () {
- // const {bio} = this.state;
- // this.props.saveBio(user_id, bio);
- }
-
render () {
return ;
}
}
diff --git a/client/coral-settings/containers/SettingsContainer.js b/client/coral-settings/containers/SettingsContainer.js
index 1013f7a39..fc196b9e7 100644
--- a/client/coral-settings/containers/SettingsContainer.js
+++ b/client/coral-settings/containers/SettingsContainer.js
@@ -31,7 +31,7 @@ class SignInContainer extends Component {
}
render() {
- const {loggedIn} = this.props;
+ const {loggedIn, userData} = this.props;
const {activeTab} = this.state;
return (
@@ -44,7 +44,7 @@ class SignInContainer extends Component {
-
+
);
diff --git a/models/user.js b/models/user.js
index 6e9300ec0..86908ab42 100644
--- a/models/user.js
+++ b/models/user.js
@@ -77,18 +77,12 @@ const UserSchema = new mongoose.Schema({
roles: [String],
// User's settings
- settings: [
- new mongoose.Schema({
- id: {
- type: String,
- required: true
- },
- value: {
- type: String,
- required: true
- }
- })
- ]
+ settings: {
+ bio: {
+ type: String,
+ default: ''
+ }
+ }
}, {
// This will ensure that we have proper timestamps available on this model.
@@ -543,11 +537,13 @@ UserService.all = () => {
*/
UserService.addBio = (id, bio) => (
- UserModel.update({
+ UserModel.findOneAndUpdate({
id
}, {
- $addToSet: {
- bio
+ $set: {
+ 'settings.bio': bio
}
+ }, {
+ new: true
})
);
diff --git a/routes/api/user/index.js b/routes/api/user/index.js
index 3c7e651bb..1765809ad 100644
--- a/routes/api/user/index.js
+++ b/routes/api/user/index.js
@@ -140,7 +140,7 @@ router.post('/request-password-reset', (req, res, next) => {
});
});
-router.post('/:user_id/bio', (req, res, next) => {
+router.put('/:user_id/bio', (req, res, next) => {
const {user_id} = req.params;
const {bio} = req.body;
@@ -150,9 +150,7 @@ router.post('/:user_id/bio', (req, res, next) => {
User
.addBio(user_id, bio)
- .then(() => {
- res.status(204).end();
- })
+ .then(user => res.status(200).send(user))
.catch(error => {
const errorMsg = typeof error === 'string' ? error : error.message;
res.status(500).json({error: errorMsg});