talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 1 | /*! |
| 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 | |
| 17 | import React from 'react'; |
| 18 | import {connect} from 'react-redux'; |
| 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'; |
| 22 | import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js'; |
| 23 | import keyMirror from 'nfvo-utils/KeyMirror.js'; |
| 24 | |
| 25 | export const CommitModalType = keyMirror({ |
| 26 | COMMIT: null, |
| 27 | COMMIT_SUBMIT: null |
| 28 | |
| 29 | }); |
| 30 | |
| 31 | export const mapActionToProps = (dispatch) => { |
| 32 | return { |
| 33 | onClose: () => dispatch({ |
| 34 | type: modalActionTypes.GLOBAL_MODAL_CLOSE |
| 35 | }) |
| 36 | }; |
| 37 | }; |
| 38 | |
| 39 | class CommitCommentModal extends React.Component { |
| 40 | |
| 41 | state = { |
| 42 | comment: '' |
| 43 | }; |
| 44 | |
| 45 | render() { |
| 46 | const {onCommit, onClose, type} = this.props; |
| 47 | const [commitButtonText, descriptionText] = type === CommitModalType.COMMIT ? |
| 48 | [i18n('Commit'), i18n('You are about to commit your version')] : |
| 49 | [i18n('Commit & Submit'), i18n('You must commit your changes before the submit')]; |
| 50 | |
| 51 | return ( |
| 52 | <Form |
| 53 | ref='validationForm' |
| 54 | hasButtons={true} |
| 55 | onSubmit={ () => {onCommit(this.state.comment); onClose();} } |
| 56 | onReset={onClose} |
| 57 | submitButtonText={commitButtonText} |
| 58 | labledButtons={true} |
| 59 | isValid={true} |
| 60 | className='comment-commit-form'> |
| 61 | <div className='commit-modal-text'>{descriptionText}</div> |
| 62 | <Input |
| 63 | data-test-id='commit-comment-text' |
| 64 | onChange={comment => this.setState({comment: comment})} |
| 65 | label={i18n('Enter Commit Comment:')} |
| 66 | value={this.state.comment} |
| 67 | type='textarea'/> |
| 68 | </Form> |
| 69 | ); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | export default connect(null, mapActionToProps)(CommitCommentModal); |