diff --git a/src/servers/CreateServer.js b/src/servers/CreateServer.js index 42f41410..8ce3fd02 100644 --- a/src/servers/CreateServer.js +++ b/src/servers/CreateServer.js @@ -1,46 +1,34 @@ -import { assoc, dissoc, pipe } from 'ramda'; -import React from 'react'; +import React, { useState, useEffect } from 'react'; import { v4 as uuid } from 'uuid'; import PropTypes from 'prop-types'; import './CreateServer.scss'; const SHOW_IMPORT_MSG_TIME = 4000; +const propTypes = { + createServer: PropTypes.func, + history: PropTypes.shape({ + push: PropTypes.func, + }), + resetSelectedServer: PropTypes.func, +}; -const CreateServer = (ImportServersBtn, stateFlagTimeout) => class CreateServer extends React.Component { - static propTypes = { - createServer: PropTypes.func, - history: PropTypes.shape({ - push: PropTypes.func, - }), - resetSelectedServer: PropTypes.func, - }; +const CreateServer = (ImportServersBtn, useStateFlagTimeout) => { + const CreateServerComp = ({ createServer, history, resetSelectedServer }) => { + const [ name, setName ] = useState(''); + const [ url, setUrl ] = useState(''); + const [ apiKey, setApiKey ] = useState(''); + const [ serversImported, setServersImported ] = useStateFlagTimeout(false, SHOW_IMPORT_MSG_TIME); + const { push } = history; + const handleSubmit = (e) => { + e.preventDefault(); - state = { - name: '', - url: '', - apiKey: '', - serversImported: false, - }; + const id = uuid(); + const server = { id, name, url, apiKey }; - handleSubmit = (e) => { - e.preventDefault(); - - const { createServer, history: { push } } = this.props; - const server = pipe( - assoc('id', uuid()), - dissoc('serversImported') - )(this.state); - - createServer(server); - push(`/server/${server.id}/list-short-urls/1`); - }; - - componentDidMount() { - this.props.resetSelectedServer(); - } - - render() { - const renderInputGroup = (id, placeholder, type = 'text') => ( + createServer(server); + push(`/server/${id}/list-short-urls/1`); + }; + const renderInputGroup = (id, placeholder, value, setState, type = 'text') => (