mirror of
https://github.com/wassname/talk.git
synced 2026-07-21 12:51:03 +08:00
Working bios
This commit is contained in:
@@ -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)));
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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}) => (
|
||||
<div className={styles.bio}>
|
||||
<h1>Bio</h1>
|
||||
<p>Tell the community about yourself</p>
|
||||
<textarea defaultValue={userData.bio} value={bio} onChange={handleChange} />
|
||||
<div className={styles.actions}>
|
||||
<Button cStyle='cancel' raised>Cancel</Button>
|
||||
<Button cStyle='success' onClick={handleSave}>Save Changes</Button>
|
||||
</div>
|
||||
<form onSubmit={handleSave}>
|
||||
<textarea defaultValue={bio} ref={handleInput} />
|
||||
<div className={styles.actions}>
|
||||
<Button cStyle='cancel' raised>Cancel</Button>
|
||||
<Button cStyle='success' type="submit">Save Changes</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
|
||||
|
||||
@@ -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 <Bio
|
||||
bio={this.props.bio}
|
||||
userData={this.props.userData}
|
||||
handleSave={this.handleSave}
|
||||
handleChange={this.handleChange}
|
||||
{...this.props}
|
||||
{...this.state}
|
||||
handleInput={this.handleInput}
|
||||
/>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class SignInContainer extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const {loggedIn} = this.props;
|
||||
const {loggedIn, userData} = this.props;
|
||||
const {activeTab} = this.state;
|
||||
return (
|
||||
<RestrictedContent restricted={!loggedIn} restrictedComp={NotLoggedIn}>
|
||||
@@ -44,7 +44,7 @@ class SignInContainer extends Component {
|
||||
<CommentHistory {...this.props}/>
|
||||
</TabContent>
|
||||
<TabContent show={activeTab === 1}>
|
||||
<BioContainer handleSave={this.handleSave} {...this.props} />
|
||||
<BioContainer bio={userData.settings.bio} handleSave={this.handleSave} {...this.props} />
|
||||
</TabContent>
|
||||
</RestrictedContent>
|
||||
);
|
||||
|
||||
+11
-15
@@ -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
|
||||
})
|
||||
);
|
||||
|
||||
@@ -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});
|
||||
|
||||
Reference in New Issue
Block a user