Add new code new version
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / licenseModel / entitlementPools / EntitlementPoolsConfirmationModal.jsx
1 import React from 'react';
2 import {connect} from 'react-redux';
3 import ConfirmationModalView from 'nfvo-components/confirmations/ConfirmationModalView.jsx';
4 import EntitlementPoolsActionHelper from './EntitlementPoolsActionHelper.js';
5 import i18n from 'nfvo-utils/i18n/i18n.js';
6
7 function renderMsg(entitlementPoolToDelete) {
8         let poolName = entitlementPoolToDelete ? entitlementPoolToDelete.name : '';
9         let msg = i18n('Are you sure you want to delete "{poolName}"?', {poolName});
10         let subMsg = entitlementPoolToDelete
11         && entitlementPoolToDelete.referencingFeatureGroups
12         && entitlementPoolToDelete.referencingFeatureGroups.length > 0 ?
13                 i18n('This entitlement pool is associated with one or more feature groups') :
14                 '';
15         return (
16                 <div>
17                         <p>{msg}</p>
18                         <p>{subMsg}</p>
19                 </div>
20         );
21 };
22
23 const mapStateToProps = ({licenseModel: {entitlementPool}}, {licenseModelId}) => {
24         let {entitlementPoolToDelete} = entitlementPool;
25         const show = entitlementPoolToDelete !== false;
26         return {
27                 show,
28                 title: 'Warning!',
29                 type: 'warning',
30                 msg: renderMsg(entitlementPoolToDelete),
31                 confirmationDetails: {entitlementPoolToDelete, licenseModelId}
32         };
33 };
34
35 const mapActionsToProps = (dispatch) => {
36         return {
37                 onConfirmed: ({entitlementPoolToDelete, licenseModelId}) => {
38                         EntitlementPoolsActionHelper.deleteEntitlementPool(dispatch, {
39                                 licenseModelId,
40                                 entitlementPoolId: entitlementPoolToDelete.id
41                         });
42                         EntitlementPoolsActionHelper.hideDeleteConfirm(dispatch);
43                 },
44                 onDeclined: () => {
45                         EntitlementPoolsActionHelper.hideDeleteConfirm(dispatch);
46                 }
47         };
48 };
49
50 export default connect(mapStateToProps, mapActionsToProps)(ConfirmationModalView);
51