UNPKG

@wenn/onb

Version:

onb-core

75 lines (64 loc) 1.8 kB
import React from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { disconnect } from '../../redux/actions/run.actions'; const NotificationsHOC = Component => { class Notifications extends React.Component { componentDidMount() { disconnect(); } getWording() { const { notification: { bpmStep }, feedback, currentPage, camunda: { amount } } = this.props; let state, value; if (currentPage === '/felicitaciones') { state = feedback.success; value = 'success'; sendlog('view_page'); sendlog('event', { event_action: 'success', amount: amount.value }); window.dataLayer && window.dataLayer.push({ event: 'purchase', label: 'purchase', value: amount.value }); } else if (bpmStep && feedback[bpmStep.code]) { state = feedback[bpmStep.code]; value = bpmStep.code; sendlog('error', { error_type: 'flow', ...bpmStep }); } else { state = feedback.generic_error; value = 'generic_error'; } window.dataLayer && window.dataLayer.push({ event: 'error', value }); return state; } render() { return <Component {...this.props} wording={this.getWording()} />; } } Notifications.propTypes = { notification: PropTypes.object.isRequired, feedback: PropTypes.object.isRequired }; const mapState = ( { settings: { feedback, assets }, notification, currentPage, camunda }, { viewName } ) => ({ currentPage, notification, feedback, assets, camunda }); return connect(mapState)(Notifications); }; export default NotificationsHOC;