NetworkSelect.tsx
1 import React from 'react'; 2 import { connect } from 'react-redux'; 3 4 import { TAddCustomNode, AddCustomNodeAction, addCustomNode } from 'features/config'; 5 import NetworkSelector from 'components/NetworkSelector'; 6 import CustomNodeModal from 'components/CustomNodeModal'; 7 8 interface OwnProps { 9 closePanel(): void; 10 } 11 12 interface DispatchProps { 13 addCustomNode: TAddCustomNode; 14 } 15 16 type Props = OwnProps & DispatchProps; 17 18 interface State { 19 isAddingCustomNode: boolean; 20 } 21 22 class NetworkSelect extends React.Component<Props, State> { 23 public state: State = { 24 isAddingCustomNode: false 25 }; 26 27 public render() { 28 const { isAddingCustomNode } = this.state; 29 return ( 30 <React.Fragment> 31 <NetworkSelector 32 onSelectNetwork={this.props.closePanel} 33 onSelectNode={this.props.closePanel} 34 openCustomNodeModal={this.openCustomNodeModal} 35 /> 36 <CustomNodeModal 37 isOpen={isAddingCustomNode} 38 addCustomNode={this.addCustomNode} 39 handleClose={this.closeCustomNodeModal} 40 /> 41 </React.Fragment> 42 ); 43 } 44 45 private openCustomNodeModal = () => { 46 this.setState({ isAddingCustomNode: true }); 47 }; 48 49 private closeCustomNodeModal = () => { 50 this.setState({ isAddingCustomNode: false }); 51 }; 52 53 private addCustomNode = (payload: AddCustomNodeAction['payload']) => { 54 this.closeCustomNodeModal(); 55 this.props.addCustomNode(payload); 56 this.props.closePanel(); 57 }; 58 } 59 60 export default connect(undefined, { addCustomNode })(NetworkSelect);