import React from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePureComponent from 'react-immutable-pure-component' import { defineMessages, injectIntl } from 'react-intl' import isObject from 'lodash.isobject' import { changeGroupTitle, changeGroupPassword, changeGroupDescription, changeGroupCoverImage, changeGroupId, changeGroupTags, changeGroupCategory, changeGroupIsPrivate, changeGroupIsVisible, submit, setGroup, resetEditor, } from '../actions/group_editor' import { openModal, closeModal, } from '../actions/modal' import { fetchGroup } from '../actions/groups' import { fetchGroupCategories } from '../actions/group_categories' import { me } from '../initial_state' import ColumnIndicator from '../components/column_indicator' import Button from '../components/button' import Divider from '../components/divider' import Input from '../components/input' import Text from '../components/text' import Form from '../components/form' import Switch from '../components/switch' import Select from '../components/select' import Textarea from '../components/textarea' import FileInput from '../components/file_input' class GroupCreate extends ImmutablePureComponent { static contextTypes = { router: PropTypes.object } componentDidMount() { const { groupId, group } = this.props this.props.onFetchGroupCategories() if (!group) { if (groupId) { this.props.onFetchGroup(groupId) } else { this.props.onResetEditor() } } else { this.props.onSetGroup(group) } } componentWillReceiveProps(nextProps) { if (this.props.group !== nextProps.group && !!nextProps.group) { this.props.onSetGroup(nextProps.group) } } handleCoverImageChange = (e) => { try { this.props.onCoverImageChange(e.target.files[0]) } catch (error) { // } } handleSubmit = (e) => { e.preventDefault() if (this.props.onClose) this.props.onClose() this.props.onSubmit(this.context.router.history) } render() { const { group, error, titleValue, descriptionValue, passwordValue, coverImage, intl, onTitleChange, onChangeGroupPassword, onDescriptionChange, onChangeGroupId, onChangeGroupTags, onChangeGroupCategory, onChangeGroupIsPrivate, onChangeGroupIsVisible, isSubmitting, onSubmit, idValue, tags, category, isPrivate, isVisible, groupId, categories, isAdmin, } = this.props if (!group && groupId) { return } else if ((!group && error) || (groupId && !isAdmin)) { return } const memberCount = group ? group.get('member_count') : 0 const hasGroupSlug = group ? !!group.get('slug') : false let categoriesOptions = [{'title':'',value:''}] if (categories) { for (let i = 0; i < categories.count(); i++) { const c = categories.get(i) categoriesOptions.push({ title: c.get('text'), value: c.get('id'), }) } } const submitDisabled = ((!titleValue || !category || !descriptionValue) && !groupId) || isSubmitting return (
{ memberCount >= 50 && !hasGroupSlug && { !!idValue && g/{idValue} –  } {intl.formatMessage(messages.idDescription)} }