@wenn/onb
Version:
onb-core
135 lines (115 loc) • 2.98 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { reduxForm, change } from 'redux-form';
import {
saveCamunda,
sendToCamunda
} from '../../redux/actions/camunda.actions';
const InitialInfoHOC = Component => {
class InitialInfo extends React.Component {
constructor(props) {
super(props);
this.state = {
toggleModal: false,
isSuggestionVisible: true
};
}
componentDidMount() {
sendlog('view_page');
}
parseEmail = v => {
return v && v.replace(/ /g, '');
};
limitLength(v, max) {
return v && v.substring(0, max);
}
handleFocus = value => {
this.setState({ isSuggestionVisible: value });
};
handleModal = () => {
const { toggleModal } = this.state;
this.setState({ toggleModal: !toggleModal });
};
handleOnSend = e => {
e.preventDefault();
const {
formData: { values },
viewName,
saveCamunda,
sendToCamunda,
bpmStep
} = this.props;
const data = {
to: values.email
};
let args = {};
if (bpmStep.includes('PAUSE1') || bpmStep.includes('PAUSE2')) {
args = {
goto: {
type: 'String',
value: 'step1'
}
};
}
sendlog('event', { event_action: 'click', ...values });
saveCamunda(data);
saveCamunda({
...values,
validationcellcode: values.validationcellcode || ''
});
sendToCamunda(viewName, args);
};
replaceEmail(email) {
this.props.dispatch(change('InitialInfo', 'email', email));
}
render() {
return (
<div>
<Component
{...this.props}
{...this.state}
onHandleOnSend={this.handleOnSend}
onHandleFocus={this.handleFocus}
onHandleModal={this.handleModal}
parseEmail={this.parseEmail}
limitLength={this.limitLength}
replaceEmail={email => this.replaceEmail(email)}
/>
</div>
);
}
}
InitialInfo.proptTypes = {
formData: PropTypes.object.isRequired,
wording: PropTypes.object.isRequired,
saveCamunda: PropTypes.func.isRequired,
sendToCamunda: PropTypes.func.isRequired,
viewName: PropTypes.string.isRequired
};
InitialInfo = reduxForm({
form: 'InitialInfo',
destroyOnUnmount: false,
forceUnregisterOnUnmount: true
})(InitialInfo);
const mapState = (
{ settings: { wording, config, theme, assets }, form, bpmStep },
{ viewName }
) => ({
formData: form.InitialInfo ? form.InitialInfo : {},
wording: wording[viewName],
config,
assetsPaths: assets,
viewName,
bpmStep
});
const mapDispatch = {
saveCamunda,
sendToCamunda
};
return connect(
mapState,
mapDispatch
)(InitialInfo);
};
export default InitialInfoHOC;