@wenn/onb
Version:
onb-core
153 lines (139 loc) • 3.79 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';
import {
SAVE_RETRY_SMS,
RESET_FAILED_CODE_ATTEMPTS,
SET_SMS_FLAG,
UNSET_SMS_FLAG
} from '../../redux/constants';
const LeadConfirmInfoHOC = Component => {
class LeadConfirmInfo extends React.Component {
constructor() {
super();
this.state = {};
}
componentDidMount() {
sendlog('view_page');
}
componentWillUpdate() {
const { failedCodeAttempts, dispatch, retrySms } = this.props;
if (failedCodeAttempts.count >= 5 && retrySms >= 2) {
dispatch(
globalNotification({
bpmStep: {
code: 'sms_retry_limit',
step: 'end'
}
})
);
dispatch(saveFlowError(true));
} else if (failedCodeAttempts.count >= 5 && retrySms < 3) {
this.sendSms();
} else {
dispatch({ type: UNSET_SMS_FLAG });
}
}
limitLength(v, max) {
return v && v.substring(0, max);
}
sendSms = e => {
e && e.preventDefault();
const {
formData: { values },
saveCamunda,
sendToCamunda,
dispatch
} = this.props;
const { validationcellcode, validationcellphone } = values;
let data = { resendSMS: 'true' };
if (validationcellcode && validationcellphone) {
dispatch(change('InitialInfo', 'validationcellcode', values.validationcellcode));
dispatch(change('InitialInfo', 'validationcellphone', values.validationcellphone));
data = {
...data,
validationcellcode,
validationcellphone
};
}
dispatch({ type: SAVE_RETRY_SMS });
dispatch({ type: SET_SMS_FLAG });
dispatch({ type: RESET_FAILED_CODE_ATTEMPTS });
saveCamunda(data);
sendToCamunda('basicInfo:resendSMS', {
goto: { type: 'String', value: 'step2' },
flowerror: { type: 'String', value: 'false' }
});
};
handleOnSend = e => {
e.preventDefault();
const {
viewName,
saveCamunda,
sendToCamunda,
formData: { values },
data
} = this.props;
sendlog('event', { event_action: 'click', ...values });
saveCamunda({ ...values, bank: data.bankCode });
sendToCamunda(viewName);
};
render() {
return (
<Component
{...this.props}
onHandleOnSend={e => this.handleOnSend(e)}
sendSms={this.sendSms}
limitLength={this.limitLength}
/>
);
}
}
LeadConfirmInfo.proptTypes = {
formData: PropTypes.object.isRequired,
wording: PropTypes.object.isRequired,
saveCamunda: PropTypes.func.isRequired,
sendToCamunda: PropTypes.func.isRequired,
viewName: PropTypes.string.isRequired
};
LeadConfirmInfo = reduxForm({
form: 'LeadConfirmInfo',
destroyOnUnmount: false,
forceUnregisterOnUnmount: true
})(LeadConfirmInfo);
const mapState = (
{
settings: {
wording,
config,
utils: { BANKS }
},
form,
camunda: { country },
camundaData: { get_lead },
retrySms,
failedCodeAttempts
},
{ viewName }
) => ({
formData: form.LeadConfirmInfo ? form.LeadConfirmInfo : {},
data: get_lead,
wording: wording[viewName],
config,
viewName,
BANKS: BANKS[country.value],
retrySms,
failedCodeAttempts
});
const mapDispatch = {
saveCamunda,
sendToCamunda
};
return connect(
mapState,
mapDispatch
)(LeadConfirmInfo);
};
export default LeadConfirmInfoHOC;