Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [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 |
| 7 | * |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 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, |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +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. |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | import React from 'react'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 18 | import { connect } from 'react-redux'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 19 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 20 | import Form from 'nfvo-components/input/validation/Form.jsx'; |
| 21 | import Input from 'nfvo-components/input/validation/Input.jsx'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 22 | import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 23 | import keyMirror from 'nfvo-utils/KeyMirror.js'; |
| 24 | |
| 25 | export const CommitModalType = keyMirror({ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 26 | COMMIT: null, |
| 27 | COMMIT_SUBMIT: null |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 28 | }); |
| 29 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 30 | export const mapActionToProps = dispatch => { |
| 31 | return { |
| 32 | onClose: () => |
| 33 | dispatch({ |
| 34 | type: modalActionTypes.GLOBAL_MODAL_CLOSE |
| 35 | }) |
| 36 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | class CommitCommentModal extends React.Component { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 40 | state = { |
| 41 | comment: '' |
| 42 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 43 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 44 | 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 | ]; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 53 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 54 | 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} |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 66 | btnClassName="sdc-modal__footer" |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 67 | className="comment-commit-form"> |
| 68 | <div className="commit-modal-text">{descriptionText}</div> |
| 69 | <Input |
| 70 | data-test-id="commit-comment-text" |
| 71 | onChange={comment => this.setState({ comment: comment })} |
| 72 | label={i18n('Enter Commit Comment:')} |
| 73 | value={this.state.comment} |
| 74 | type="textarea" |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 75 | groupClassName="no-bottom-margin" |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 76 | /> |
| 77 | </Form> |
| 78 | ); |
| 79 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | export default connect(null, mapActionToProps)(CommitCommentModal); |