From 22406d1253faead468469b1111fedd257da6d278 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 16 Jul 2018 18:48:50 +0200 Subject: [PATCH] Added hability to create servers --- src/servers/CreateServer.js | 8 ++++++-- src/servers/services/index.js | 3 --- src/short-urls/Paginator.js | 20 ++++++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/servers/CreateServer.js b/src/servers/CreateServer.js index 1d290fcd..5ec67bf7 100644 --- a/src/servers/CreateServer.js +++ b/src/servers/CreateServer.js @@ -1,6 +1,8 @@ +import { assoc } from 'ramda'; import React from 'react'; import { connect } from 'react-redux'; import { createServer } from './reducers/server'; +import { v4 as uuid } from 'uuid'; import './CreateServer.scss'; @@ -14,7 +16,9 @@ export class CreateServer extends React.Component { render() { const submit = e => { e.preventDefault(); - this.props.createServer(this.state); + 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') =>
@@ -48,4 +52,4 @@ export class CreateServer extends React.Component { } } -export default connect(null, { createServer })(CreateServer); +export default connect(state => ({ selectedServer: state.selectedServer }), { createServer })(CreateServer); diff --git a/src/servers/services/index.js b/src/servers/services/index.js index 2125fad0..6f70558d 100644 --- a/src/servers/services/index.js +++ b/src/servers/services/index.js @@ -1,6 +1,4 @@ import Storage from '../../utils/Storage'; -import { assoc } from 'ramda'; -import { v4 as uuid } from 'uuid'; const SERVERS_STORAGE_KEY = 'servers'; @@ -20,7 +18,6 @@ export class ServersService { createServer = server => { const servers = this.listServers(); - server = assoc('id', uuid(), server); servers[server.id] = server; this.storage.set(SERVERS_STORAGE_KEY, servers); }; diff --git a/src/short-urls/Paginator.js b/src/short-urls/Paginator.js index 24c1a5cb..efd6c1ba 100644 --- a/src/short-urls/Paginator.js +++ b/src/short-urls/Paginator.js @@ -35,17 +35,21 @@ export class Paginator extends React.Component { return ( - this.updatePage(currentPage - 1)} /> + this.updatePage(currentPage - 1)} + /> {renderPages()} = pagesCount}> - this.updatePage(currentPage + 1)} /> + this.updatePage(currentPage + 1)} + /> );