import React from 'react'; import PropTypes from 'prop-types'; import {connect} from 'react-redux'; import {appConfig} from 'appConfig'; import * as actions from '../../../actions'; import * as selectors from '../../../selectors'; import {gettext, updateFormValues, eventUtils, timeUtils} from '../../../utils'; import {Row} from '../../UI/Preview/'; import {RepeatEventSummary} from '../../Events'; import {RecurringRulesInput} from '../../Events/RecurringRulesInput/index'; import '../style.scss'; import {get, cloneDeep, isEqual, set} from 'lodash'; import {EVENTS, ITEM_TYPE, TIME_COMPARISON_GRANULARITY} from '../../../constants'; import {validateItem} from '../../../validators'; export class UpdateEventRepetitionsComponent extends React.Component { constructor(props) { super(props); this.state = { errors: {}, diff: {}, }; this.onChange = this.onChange.bind(this); this.getPopupContainer = this.getPopupContainer.bind(this); this.dom = {popupContainer: null}; } componentWillMount() { this.setState({ diff: cloneDeep(this.props.original), }); } onChange(field, value) { const {original} = this.props; const errors = cloneDeep(this.state.errors); const diff = cloneDeep(get(this.state, 'diff') || {}); const firstEvent = cloneDeep(get(original, '_recurring[0]')); let errorMessages = []; updateFormValues(diff, field, value); // Use the first Event in the series for validation purposes // This makes the validation of the 'until' date/time work across the series set(firstEvent, 'dates.recurring_rule', get(diff, 'dates.recurring_rule')); this.props.onValidate( firstEvent, this.props.formProfiles, errors, errorMessages ); this.setState({ diff: diff, dirty: !isEqual(this.props.original, diff), errors: errors, }); if (!isEqual(errorMessages, []) || eventUtils.eventsDatesSame( diff, this.props.original, TIME_COMPARISON_GRANULARITY.DAY )) { this.props.disableSaveInModal(); } else { this.props.enableSaveInModal(); } } submit() { return this.props.onSubmit( this.props.original, this.state.diff, get(this.props, 'modalProps') || {} ); } getPopupContainer() { return this.dom.popupContainer; } render() { const {original, submitting} = this.props; const {diff} = this.state; return (