blob: 8c5d9669388d609cf54b1a3ab98ef7f098e6af1e [file] [log] [blame]
svishnev8ae8f7e2018-07-02 14:05:17 +03001/*
2 * Copyright © 2016-2018 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
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
svishnev8ae8f7e2018-07-02 14:05:17 +03007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
AviZi280f8012017-06-09 02:39:56 +030010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
svishnev8ae8f7e2018-07-02 14:05:17 +030012 * 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.
AviZi280f8012017-06-09 02:39:56 +030015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import React from 'react';
talig8e9c0652017-12-20 14:30:43 +020017import PropTypes from 'prop-types';
Michael Landoefa037d2017-02-19 12:57:33 +020018import i18n from 'nfvo-utils/i18n/i18n.js';
AviZi280f8012017-06-09 02:39:56 +030019import Input from 'nfvo-components/input/validation/Input.jsx';
20import Form from 'nfvo-components/input/validation/Form.jsx';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020021import { LICENSE_MODEL_CREATION_FORM_NAME } from './LicenseModelCreationConstants.js';
Michael Landoefa037d2017-02-19 12:57:33 +020022
talig8e9c0652017-12-20 14:30:43 +020023const LicenseModelPropType = PropTypes.shape({
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020024 id: PropTypes.string,
25 vendorName: PropTypes.string,
26 description: PropTypes.string
Michael Landoefa037d2017-02-19 12:57:33 +020027});
28
29class LicenseModelCreationView extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020030 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 Landoefa037d2017-02-19 12:57:33 +020039
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020040 render() {
41 let { data = {}, onDataChanged, genericFieldInfo } = this.props;
42 let { vendorName, description } = data;
43 return (
44 <div>
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}
55 onValidateForm={() => this.validate()}>
56 <Input
57 value={vendorName}
58 label={i18n('Vendor Name')}
59 data-test-id="vendor-name"
60 onChange={vendorName =>
61 onDataChanged(
62 { vendorName },
svishnev8ae8f7e2018-07-02 14:05:17 +030063 LICENSE_MODEL_CREATION_FORM_NAME
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020064 )
65 }
svishnev8ae8f7e2018-07-02 14:05:17 +030066 onBlur={e =>
67 this.validateIsNameUnique(e.target.value)
68 }
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020069 isValid={genericFieldInfo.vendorName.isValid}
70 errorText={genericFieldInfo.vendorName.errorText}
71 type="text"
72 isRequired={true}
73 className="field-section"
74 />
75 <Input
76 isRequired={true}
77 value={description}
78 label={i18n('Description')}
79 data-test-id="vendor-description"
80 overlayPos="bottom"
81 onChange={description =>
82 onDataChanged(
83 { description },
84 LICENSE_MODEL_CREATION_FORM_NAME
85 )
86 }
87 isValid={genericFieldInfo.description.isValid}
88 errorText={genericFieldInfo.description.errorText}
89 type="textarea"
90 className="field-section"
91 />
92 </Form>
93 )}
94 </div>
95 );
96 }
Michael Landoefa037d2017-02-19 12:57:33 +020097
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020098 submit() {
99 const { data: licenseModel, usersList } = this.props;
100 this.props.onSubmit(licenseModel, usersList);
101 }
Michael Landoefa037d2017-02-19 12:57:33 +0200102
svishnev8ae8f7e2018-07-02 14:05:17 +0300103 validateIsNameUnique(value) {
104 this.props.isNameUnique(
105 value,
106 'vendorName',
107 LICENSE_MODEL_CREATION_FORM_NAME
108 );
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200109 }
AviZi280f8012017-06-09 02:39:56 +0300110
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200111 validate() {
112 this.props.onValidateForm(LICENSE_MODEL_CREATION_FORM_NAME);
113 }
Michael Landoefa037d2017-02-19 12:57:33 +0200114}
115
116export default LicenseModelCreationView;