2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 import React from 'react';
17 import PropTypes from 'prop-types';
18 import i18n from 'nfvo-utils/i18n/i18n.js';
19 import Validator from 'nfvo-utils/Validator.js';
20 import Input from 'nfvo-components/input/validation/Input.jsx';
21 import Form from 'nfvo-components/input/validation/Form.jsx';
22 import { LICENSE_MODEL_CREATION_FORM_NAME } from './LicenseModelCreationConstants.js';
24 const LicenseModelPropType = PropTypes.shape({
26 vendorName: PropTypes.string,
27 description: PropTypes.string
30 class LicenseModelCreationView extends React.Component {
32 data: LicenseModelPropType,
33 VLMNames: PropTypes.object,
34 usersList: PropTypes.array,
35 onDataChanged: PropTypes.func.isRequired,
36 onSubmit: PropTypes.func.isRequired,
37 onValidateForm: PropTypes.func.isRequired,
38 onCancel: PropTypes.func.isRequired
42 let { data = {}, onDataChanged, genericFieldInfo } = this.props;
43 let { vendorName, description } = data;
46 {genericFieldInfo && (
50 onSubmit={() => this.submit()}
51 submitButtonText={i18n('Create')}
52 onReset={() => this.props.onCancel()}
54 isValid={this.props.isFormValid}
55 formReady={this.props.formReady}
56 onValidateForm={() => this.validate()}>
59 label={i18n('Vendor Name')}
60 data-test-id="vendor-name"
61 onChange={vendorName =>
64 LICENSE_MODEL_CREATION_FORM_NAME,
67 this.validateName(name)
71 isValid={genericFieldInfo.vendorName.isValid}
72 errorText={genericFieldInfo.vendorName.errorText}
75 className="field-section"
80 label={i18n('Description')}
81 data-test-id="vendor-description"
83 onChange={description =>
86 LICENSE_MODEL_CREATION_FORM_NAME
89 isValid={genericFieldInfo.description.isValid}
90 errorText={genericFieldInfo.description.errorText}
92 className="field-section"
101 const { data: licenseModel, usersList } = this.props;
102 this.props.onSubmit(licenseModel, usersList);
105 validateName(value) {
106 const { data: { id }, VLMNames } = this.props;
107 const isExists = Validator.isItemNameAlreadyExistsInList({
114 ? { isValid: true, errorText: '' }
118 "License model by the name '" +
120 "' already exists. License model name must be unique"
126 this.props.onValidateForm(LICENSE_MODEL_CREATION_FORM_NAME);
130 export default LicenseModelCreationView;