blob: ae0913f3a97021ad80cbce73f495550bf47fbfe6 [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17import React from 'react';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020018import { connect } from 'react-redux';
talig8e9c0652017-12-20 14:30:43 +020019import i18n from 'nfvo-utils/i18n/i18n.js';
20import Form from 'nfvo-components/input/validation/Form.jsx';
21import Input from 'nfvo-components/input/validation/Input.jsx';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020022import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js';
talig8e9c0652017-12-20 14:30:43 +020023import keyMirror from 'nfvo-utils/KeyMirror.js';
24
25export const CommitModalType = keyMirror({
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020026 COMMIT: null,
27 COMMIT_SUBMIT: null
talig8e9c0652017-12-20 14:30:43 +020028});
29
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020030export const mapActionToProps = dispatch => {
31 return {
32 onClose: () =>
33 dispatch({
34 type: modalActionTypes.GLOBAL_MODAL_CLOSE
35 })
36 };
talig8e9c0652017-12-20 14:30:43 +020037};
38
39class CommitCommentModal extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020040 state = {
41 comment: ''
42 };
talig8e9c0652017-12-20 14:30:43 +020043
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020044 render() {
45 const { onCommit, onClose, type } = this.props;
46 const [commitButtonText, descriptionText] =
47 type === CommitModalType.COMMIT
48 ? [i18n('Commit'), i18n('You are about to commit your version')]
49 : [
50 i18n('Commit & Submit'),
51 i18n('You must commit your changes before the submit')
52 ];
talig8e9c0652017-12-20 14:30:43 +020053
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020054 return (
55 <Form
56 ref="validationForm"
57 hasButtons={true}
58 onSubmit={() => {
59 onCommit(this.state.comment);
60 onClose();
61 }}
62 onReset={onClose}
63 submitButtonText={commitButtonText}
64 labledButtons={true}
65 isValid={true}
66 className="comment-commit-form">
67 <div className="commit-modal-text">{descriptionText}</div>
68 <Input
69 data-test-id="commit-comment-text"
70 onChange={comment => this.setState({ comment: comment })}
71 label={i18n('Enter Commit Comment:')}
72 value={this.state.comment}
73 type="textarea"
74 />
75 </Form>
76 );
77 }
talig8e9c0652017-12-20 14:30:43 +020078}
79
80export default connect(null, mapActionToProps)(CommitCommentModal);