import { assoc, pick } from 'ramda'; import React from 'react'; import { connect } from 'react-redux'; import { createServer } from './reducers/server'; import { resetSelectedServer } from './reducers/selectedServer'; import { v4 as uuid } from 'uuid'; import './CreateServer.scss'; export class CreateServer extends React.Component { state = { name: '', url: '', apiKey: '', }; componentDidMount() { this.props.resetSelectedServer(); } render() { const submit = e => { e.preventDefault(); const server = assoc('id', uuid(), this.state); this.props.createServer(server); this.props.history.push(`/server/${server.id}/list-short-urls/1`) }; const renderInputGroup = (id, placeholder, type = 'text') =>
this.setState({ [id]: e.target.value })} required />
; return (
{renderInputGroup('name', 'Name')} {renderInputGroup('url', 'URL', 'url')} {renderInputGroup('apiKey', 'API key')}
); } } export default connect(pick(['selectedServer']), {createServer, resetSelectedServer })(CreateServer);