|
1 | | -import PropTypes from 'prop-types'; |
2 | 1 | import React from 'react'; |
3 | | -import { connect } from 'react-redux'; |
4 | | -import { bindActionCreators } from 'redux'; |
5 | | -import { withTranslation } from 'react-i18next'; |
| 2 | +import { useDispatch } from 'react-redux'; |
| 3 | +import { useTranslation } from 'react-i18next'; |
| 4 | +import Modal from './Modal'; |
6 | 5 | import NewFileForm from './NewFileForm'; |
7 | 6 | import { closeNewFileModal } from '../actions/ide'; |
8 | | -import ExitIcon from '../../../images/exit.svg'; |
9 | 7 |
|
10 | | -// At some point this will probably be generalized to a generic modal |
11 | | -// in which you can insert different content |
12 | | -// but for now, let's just make this work |
13 | | -class NewFileModal extends React.Component { |
14 | | - constructor(props) { |
15 | | - super(props); |
16 | | - this.focusOnModal = this.focusOnModal.bind(this); |
17 | | - this.handleOutsideClick = this.handleOutsideClick.bind(this); |
18 | | - } |
19 | | - |
20 | | - componentDidMount() { |
21 | | - this.focusOnModal(); |
22 | | - document.addEventListener('click', this.handleOutsideClick, false); |
23 | | - } |
24 | | - |
25 | | - componentWillUnmount() { |
26 | | - document.removeEventListener('click', this.handleOutsideClick, false); |
27 | | - } |
28 | | - |
29 | | - handleOutsideClick(e) { |
30 | | - // ignore clicks on the component itself |
31 | | - if (e.path.includes(this.modal)) return; |
32 | | - |
33 | | - this.props.closeNewFileModal(); |
34 | | - } |
35 | | - |
36 | | - focusOnModal() { |
37 | | - this.modal.focus(); |
38 | | - } |
39 | | - |
40 | | - render() { |
41 | | - return ( |
42 | | - <section |
43 | | - className="modal" |
44 | | - ref={(element) => { |
45 | | - this.modal = element; |
46 | | - }} |
47 | | - > |
48 | | - <div className="modal-content"> |
49 | | - <div className="modal__header"> |
50 | | - <h2 className="modal__title"> |
51 | | - {this.props.t('NewFileModal.Title')} |
52 | | - </h2> |
53 | | - <button |
54 | | - className="modal__exit-button" |
55 | | - onClick={this.props.closeNewFileModal} |
56 | | - aria-label={this.props.t('NewFileModal.CloseButtonARIA')} |
57 | | - > |
58 | | - <ExitIcon focusable="false" aria-hidden="true" /> |
59 | | - </button> |
60 | | - </div> |
61 | | - <NewFileForm focusOnModal={this.focusOnModal} /> |
62 | | - </div> |
63 | | - </section> |
64 | | - ); |
65 | | - } |
66 | | -} |
67 | | - |
68 | | -NewFileModal.propTypes = { |
69 | | - closeNewFileModal: PropTypes.func.isRequired, |
70 | | - t: PropTypes.func.isRequired |
| 8 | +const NewFileModal = () => { |
| 9 | + const { t } = useTranslation(); |
| 10 | + const dispatch = useDispatch(); |
| 11 | + return ( |
| 12 | + <Modal |
| 13 | + title={t('NewFileModal.Title')} |
| 14 | + closeAriaLabel={t('NewFileModal.CloseButtonARIA')} |
| 15 | + onClose={() => dispatch(closeNewFileModal())} |
| 16 | + > |
| 17 | + <NewFileForm /> |
| 18 | + </Modal> |
| 19 | + ); |
71 | 20 | }; |
72 | 21 |
|
73 | | -function mapStateToProps() { |
74 | | - return {}; |
75 | | -} |
76 | | - |
77 | | -function mapDispatchToProps(dispatch) { |
78 | | - return bindActionCreators({ closeNewFileModal }, dispatch); |
79 | | -} |
80 | | - |
81 | | -export default withTranslation()( |
82 | | - connect(mapStateToProps, mapDispatchToProps)(NewFileModal) |
83 | | -); |
| 22 | +export default NewFileModal; |
0 commit comments