Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame^] | 1 | import React from 'react'; |
| 2 | import {connect} from 'react-redux'; |
| 3 | import ConfirmationModalView from 'nfvo-components/confirmations/ConfirmationModalView.jsx'; |
| 4 | import LicenseAgreementActionHelper from './LicenseAgreementActionHelper.js'; |
| 5 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 6 | |
| 7 | function renderMsg(licenseAgreementToDelete) { |
| 8 | let name = licenseAgreementToDelete ? licenseAgreementToDelete.name : ''; |
| 9 | let msg = i18n('Are you sure you want to delete "{name}"?', {name}); |
| 10 | return( |
| 11 | <div> |
| 12 | <p>{msg}</p> |
| 13 | </div> |
| 14 | ); |
| 15 | }; |
| 16 | |
| 17 | const mapStateToProps = ({licenseModel: {licenseAgreement}}, {licenseModelId}) => { |
| 18 | let {licenseAgreementToDelete} = licenseAgreement; |
| 19 | const show = licenseAgreementToDelete !== false; |
| 20 | return { |
| 21 | show, |
| 22 | title: 'Warning!', |
| 23 | type: 'warning', |
| 24 | msg: renderMsg(licenseAgreementToDelete), |
| 25 | confirmationDetails: {licenseAgreementToDelete, licenseModelId} |
| 26 | }; |
| 27 | }; |
| 28 | |
| 29 | const mapActionsToProps = (dispatch) => { |
| 30 | return { |
| 31 | onConfirmed: ({licenseAgreementToDelete, licenseModelId}) => { |
| 32 | |
| 33 | LicenseAgreementActionHelper.deleteLicenseAgreement(dispatch, {licenseModelId, licenseAgreementId: licenseAgreementToDelete.id}); |
| 34 | LicenseAgreementActionHelper.hideDeleteConfirm(dispatch); |
| 35 | }, |
| 36 | onDeclined: () => { |
| 37 | LicenseAgreementActionHelper.hideDeleteConfirm(dispatch); |
| 38 | } |
| 39 | }; |
| 40 | }; |
| 41 | |
| 42 | export default connect(mapStateToProps, mapActionsToProps)(ConfirmationModalView); |
| 43 | |