import PropTypes from 'prop-types' import { Form, FormGroup, Input, Label } from 'reactstrap' import React, { useRef } from 'react' import Shapes from '../../../shapes' import Modal from '../Modal' const NewTopologyModalComponent = ({ show, onCreateTopology, onDuplicateTopology, onCancel, topologies }) => { const textInput = useRef(null) const originTopology = useRef(null) const onCreate = () => { onCreateTopology(textInput.current.value) } const onDuplicate = () => { onDuplicateTopology(textInput.current.value, originTopology.current.value) } const onSubmit = () => { if (originTopology.current.selectedIndex === 0) { onCreate() } else { onDuplicate() } } return (
{ e.preventDefault() onSubmit() }} > {topologies.map((topology) => ( ))}
) } NewTopologyModalComponent.propTypes = { show: PropTypes.bool.isRequired, topologies: PropTypes.arrayOf(Shapes.Topology), onCreateTopology: PropTypes.func.isRequired, onDuplicateTopology: PropTypes.func.isRequired, onCancel: PropTypes.func.isRequired, } export default NewTopologyModalComponent