Added hability to create servers

This commit is contained in:
Alejandro Celaya 2018-07-16 18:48:50 +02:00
parent be30d62f6f
commit 22406d1253
3 changed files with 18 additions and 13 deletions

View file

@ -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') =>
<div className="form-group row">
@ -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);

View file

@ -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);
};

View file

@ -35,17 +35,21 @@ export class Paginator extends React.Component {
return (
<Pagination>
<PaginationItem disabled={currentPage === 1}>
<PaginationLink previous
<PaginationLink
previous
tag={Link}
to={`/server/${serverId}/list-short-urls/${currentPage - 1}`}
onClick={() => this.updatePage(currentPage - 1)} />
onClick={() => this.updatePage(currentPage - 1)}
/>
</PaginationItem>
{renderPages()}
<PaginationItem disabled={currentPage >= pagesCount}>
<PaginationLink next
<PaginationLink
next
tag={Link}
to={`/server/${serverId}/list-short-urls/${currentPage + 1}`}
onClick={() => this.updatePage(currentPage + 1)} />
onClick={() => this.updatePage(currentPage + 1)}
/>
</PaginationItem>
</Pagination>
);