blob: be1a42c8a35ff753687416508c566213ffc5b1c7 [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
Einav Weiss Keidar1801b242018-08-13 16:19:46 +03007 *
svishnev8ae8f7e2018-07-02 14:05:17 +03008 * http://www.apache.org/licenses/LICENSE-2.0
Einav Weiss Keidar1801b242018-08-13 16:19:46 +03009 *
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 (
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030044 <div className="license-model-modal">
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020045 {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 Keidar1801b242018-08-13 16:19:46 +030055 btnClassName="sdc-modal__footer"
56 className="license-model-form"
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020057 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 },
svishnev8ae8f7e2018-07-02 14:05:17 +030065 LICENSE_MODEL_CREATION_FORM_NAME
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020066 )
67 }
svishnev8ae8f7e2018-07-02 14:05:17 +030068 onBlur={e =>
69 this.validateIsNameUnique(e.target.value)
70 }
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020071 isValid={genericFieldInfo.vendorName.isValid}
72 errorText={genericFieldInfo.vendorName.errorText}
73 type="text"
74 isRequired={true}
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020075 />
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 Keidar1801b242018-08-13 16:19:46 +030091 groupClassName="no-bottom-margin"
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020092 />
93 </Form>
94 )}
95 </div>
96 );
97 }
Michael Landoefa037d2017-02-19 12:57:33 +020098
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020099 submit() {
100 const { data: licenseModel, usersList } = this.props;
101 this.props.onSubmit(licenseModel, usersList);
102 }
Michael Landoefa037d2017-02-19 12:57:33 +0200103
svishnev8ae8f7e2018-07-02 14:05:17 +0300104 validateIsNameUnique(value) {
105 this.props.isNameUnique(
106 value,
107 'vendorName',
108 LICENSE_MODEL_CREATION_FORM_NAME
109 );
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200110 }
AviZi280f8012017-06-09 02:39:56 +0300111
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200112 validate() {
113 this.props.onValidateForm(LICENSE_MODEL_CREATION_FORM_NAME);
114 }
Michael Landoefa037d2017-02-19 12:57:33 +0200115}
116
117export default LicenseModelCreationView;