svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 7 | * |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 9 | * |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame] | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 15 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | import React from 'react'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 17 | import PropTypes from 'prop-types'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 18 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 19 | import Input from 'nfvo-components/input/validation/Input.jsx'; |
| 20 | import Form from 'nfvo-components/input/validation/Form.jsx'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 21 | import { LICENSE_MODEL_CREATION_FORM_NAME } from './LicenseModelCreationConstants.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 22 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 23 | const LicenseModelPropType = PropTypes.shape({ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 24 | id: PropTypes.string, |
| 25 | vendorName: PropTypes.string, |
| 26 | description: PropTypes.string |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 27 | }); |
| 28 | |
| 29 | class LicenseModelCreationView extends React.Component { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 30 | static propTypes = { |
| 31 | data: LicenseModelPropType, |
| 32 | VLMNames: PropTypes.object, |
| 33 | usersList: PropTypes.array, |
| 34 | onDataChanged: PropTypes.func.isRequired, |
| 35 | onSubmit: PropTypes.func.isRequired, |
| 36 | onValidateForm: PropTypes.func.isRequired, |
| 37 | onCancel: PropTypes.func.isRequired |
| 38 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 39 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 40 | render() { |
| 41 | let { data = {}, onDataChanged, genericFieldInfo } = this.props; |
| 42 | let { vendorName, description } = data; |
| 43 | return ( |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 44 | <div className="license-model-modal"> |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 45 | {genericFieldInfo && ( |
| 46 | <Form |
| 47 | ref="validationForm" |
| 48 | hasButtons={true} |
| 49 | onSubmit={() => this.submit()} |
| 50 | submitButtonText={i18n('Create')} |
| 51 | onReset={() => this.props.onCancel()} |
| 52 | labledButtons={true} |
| 53 | isValid={this.props.isFormValid} |
| 54 | formReady={this.props.formReady} |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 55 | btnClassName="sdc-modal__footer" |
| 56 | className="license-model-form" |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 57 | onValidateForm={() => this.validate()}> |
| 58 | <Input |
| 59 | value={vendorName} |
| 60 | label={i18n('Vendor Name')} |
| 61 | data-test-id="vendor-name" |
| 62 | onChange={vendorName => |
| 63 | onDataChanged( |
| 64 | { vendorName }, |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame] | 65 | LICENSE_MODEL_CREATION_FORM_NAME |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 66 | ) |
| 67 | } |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame] | 68 | onBlur={e => |
| 69 | this.validateIsNameUnique(e.target.value) |
| 70 | } |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 71 | isValid={genericFieldInfo.vendorName.isValid} |
| 72 | errorText={genericFieldInfo.vendorName.errorText} |
| 73 | type="text" |
| 74 | isRequired={true} |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 75 | /> |
| 76 | <Input |
| 77 | isRequired={true} |
| 78 | value={description} |
| 79 | label={i18n('Description')} |
| 80 | data-test-id="vendor-description" |
| 81 | overlayPos="bottom" |
| 82 | onChange={description => |
| 83 | onDataChanged( |
| 84 | { description }, |
| 85 | LICENSE_MODEL_CREATION_FORM_NAME |
| 86 | ) |
| 87 | } |
| 88 | isValid={genericFieldInfo.description.isValid} |
| 89 | errorText={genericFieldInfo.description.errorText} |
| 90 | type="textarea" |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 91 | groupClassName="no-bottom-margin" |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 92 | /> |
| 93 | </Form> |
| 94 | )} |
| 95 | </div> |
| 96 | ); |
| 97 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 98 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 99 | submit() { |
| 100 | const { data: licenseModel, usersList } = this.props; |
| 101 | this.props.onSubmit(licenseModel, usersList); |
| 102 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 103 | |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame] | 104 | validateIsNameUnique(value) { |
| 105 | this.props.isNameUnique( |
| 106 | value, |
| 107 | 'vendorName', |
| 108 | LICENSE_MODEL_CREATION_FORM_NAME |
| 109 | ); |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 110 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 111 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 112 | validate() { |
| 113 | this.props.onValidateForm(LICENSE_MODEL_CREATION_FORM_NAME); |
| 114 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | export default LicenseModelCreationView; |