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 form = useRef(null) 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 (!form.current.reportValidity()) { return false } else if (originTopology.current.selectedIndex === 0) { onCreate() } else { onDuplicate() } return true } return (
{ e.preventDefault() onSubmit() }} innerRef={form} > {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