2019-07-02 08:10:25 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-07-17 19:22:19 +01:00
|
|
|
import { changeValue, submit, reset } from '../../../actions/group_editor';
|
2019-07-18 20:37:53 +01:00
|
|
|
import Icon from '../../../components/icon';
|
2019-07-02 08:10:25 +01:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2019-07-18 20:37:53 +01:00
|
|
|
import classNames from 'classnames';
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2019-07-18 20:37:53 +01:00
|
|
|
title: { id: 'groups.form.title', defaultMessage: 'Enter a new group title' },
|
|
|
|
description: { id: 'groups.form.description', defaultMessage: 'Enter the group description' },
|
|
|
|
coverImage: { id: 'groups.form.coverImage', defaultMessage: 'Upload a banner image' },
|
|
|
|
coverImageChange: { id: 'groups.form.coverImageChange', defaultMessage: 'Banner image selected' },
|
2019-07-17 19:22:19 +01:00
|
|
|
create: { id: 'groups.form.create', defaultMessage: 'Create group' },
|
2019-07-02 08:10:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2019-07-17 19:22:19 +01:00
|
|
|
title: state.getIn(['group_editor', 'title']),
|
|
|
|
description: state.getIn(['group_editor', 'description']),
|
|
|
|
coverImage: state.getIn(['group_editor', 'coverImage']),
|
|
|
|
disabled: state.getIn(['group_editor', 'isSubmitting']),
|
2019-07-02 08:10:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
2019-07-17 19:22:19 +01:00
|
|
|
onTitleChange: value => dispatch(changeValue('title', value)),
|
|
|
|
onDescriptionChange: value => dispatch(changeValue('description', value)),
|
|
|
|
onCoverImageChange: value => dispatch(changeValue('coverImage', value)),
|
|
|
|
onSubmit: routerHistory => dispatch(submit(routerHistory)),
|
|
|
|
reset: () => dispatch(reset()),
|
2019-07-02 08:10:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
export default @connect(mapStateToProps, mapDispatchToProps)
|
|
|
|
@injectIntl
|
|
|
|
class Create extends React.PureComponent {
|
|
|
|
|
2019-07-17 19:22:19 +01:00
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
title: PropTypes.string.isRequired,
|
|
|
|
description: PropTypes.string.isRequired,
|
|
|
|
coverImage: PropTypes.object,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onTitleChange: PropTypes.func.isRequired,
|
|
|
|
onSubmit: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.props.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleTitleChange = e => {
|
|
|
|
this.props.onTitleChange(e.target.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDescriptionChange = e => {
|
|
|
|
this.props.onDescriptionChange(e.target.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCoverImageChange = e => {
|
|
|
|
this.props.onCoverImageChange(e.target.files[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSubmit = e => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.onSubmit(this.context.router.history);
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { title, description, coverImage, disabled, intl } = this.props;
|
|
|
|
|
|
|
|
return (
|
2019-07-18 20:37:53 +01:00
|
|
|
<form className='group-form' onSubmit={this.handleSubmit}>
|
|
|
|
<div>
|
2019-07-17 19:22:19 +01:00
|
|
|
<input
|
2019-07-23 03:35:46 +01:00
|
|
|
className='standard'
|
|
|
|
type='text'
|
2019-07-17 19:22:19 +01:00
|
|
|
value={title}
|
|
|
|
disabled={disabled}
|
|
|
|
onChange={this.handleTitleChange}
|
|
|
|
placeholder={intl.formatMessage(messages.title)}
|
|
|
|
/>
|
2019-07-18 20:37:53 +01:00
|
|
|
</div>
|
|
|
|
<div>
|
2019-07-23 04:22:42 +01:00
|
|
|
<textarea
|
2019-07-23 03:35:46 +01:00
|
|
|
className='standard'
|
|
|
|
type='text'
|
2019-07-17 19:22:19 +01:00
|
|
|
value={description}
|
|
|
|
disabled={disabled}
|
|
|
|
onChange={this.handleDescriptionChange}
|
|
|
|
placeholder={intl.formatMessage(messages.description)}
|
|
|
|
/>
|
2019-07-18 20:37:53 +01:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<label htmlFor='group_cover_image' className={classNames('group-form__file-label', { 'group-form__file-label--selected': coverImage !== null })}>
|
2019-07-25 05:27:58 +01:00
|
|
|
{intl.formatMessage(coverImage === null ? messages.coverImage : messages.coverImageChange)}
|
2019-07-18 20:37:53 +01:00
|
|
|
</label>
|
2019-07-17 19:22:19 +01:00
|
|
|
<input
|
|
|
|
type='file'
|
2019-07-18 20:37:53 +01:00
|
|
|
className='group-form__file'
|
|
|
|
id='group_cover_image'
|
2019-07-17 19:22:19 +01:00
|
|
|
disabled={disabled}
|
|
|
|
onChange={this.handleCoverImageChange}
|
|
|
|
/>
|
2019-07-20 05:10:29 +01:00
|
|
|
<button className='standard-small'>{intl.formatMessage(messages.create)}</button>
|
2019-07-18 20:37:53 +01:00
|
|
|
</div>
|
2019-07-17 19:22:19 +01:00
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
}
|