import React from 'react'; import PropTypes from 'prop-types'; import {connect} from 'react-redux'; import {get, cloneDeep, isEmpty} from 'lodash'; import * as actions from '../../../actions'; import * as selectors from '../../../selectors'; import {gettext} from '../../../utils'; import {EVENTS} from '../../../constants'; import {EventScheduleSummary} from '../../Events'; import {Row} from '../../UI/Preview'; import {TextAreaInput} from '../../UI/Form'; import {RelatedPlannings} from '../../'; import '../style.scss'; import {formProfile} from '../../../validators'; export class PostponeEventComponent extends React.Component { constructor(props) { super(props); this.state = { reason: '', errors: {}, }; this.onReasonChange = this.onReasonChange.bind(this); } componentWillMount() { // Enable save so that the user can action on this event. get(this.props, 'formProfile.schema.reason.required', false) ? this.props.disableSaveInModal() : this.props.enableSaveInModal(); } submit() { const reason = this.state.reason ? (gettext('Event Postponed: ') + this.state.reason) : this.state.reason; return this.props.onSubmit( this.props.original, {reason: reason}, get(this.props, 'modalProps.onCloseModal') ); } onReasonChange(field, reason) { const errors = cloneDeep(this.state.errors); let errorMessages = []; if (this.props.formProfile) { formProfile( { field: field, value: reason, profile: this.props.formProfile, errors: errors, messages: errorMessages, } ); if (get(errorMessages, 'length', 0) > 0 || (get(this.props.formProfile, 'schema.reason.required', false) && isEmpty(reason))) { this.props.disableSaveInModal(); } else { this.props.enableSaveInModal(); } } this.setState({ reason, errors, }); } render() { const {original, submitting} = this.props; let reasonLabel = gettext('Reason for Event postponement:'); const numPlannings = original._plannings.length; return (