Guest User

Untitled

a guest
Jul 4th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react';
  2. import {Button} from 'react-bootstrap';
  3. import UserListItem from './UserListItem';
  4.  
  5. export default class UserList extends Component {
  6.     componentWillMount() {
  7.         this.props.fetchUsers();
  8.     }
  9.  
  10.     renderUsers(users) {
  11.         const removeUser = this.props.deleteUser;
  12.         return users.map((user) => {
  13.             return (
  14.                 <UserListItem user={user} key={user.id} onRemove={()=>removeUser(user.id)}/>
  15.             );
  16.         });
  17.     }
  18.  
  19.     render() {
  20.         const {users, loading, error} = this.props.userList;
  21.         if (loading) {
  22.             return <div className="row"><h1>Użytkownicy</h1><h3>Loading...</h3></div>
  23.         } else if (error) {
  24.             return <div className="alert alert-danger">Error: {error.message}</div>
  25.         }
  26.  
  27.         return (
  28.             <div className="row">
  29.                 <h1>Użytkownicy</h1>
  30.                 <Button onClick={ () => this.props.refreshUsers() }>Odświerz</Button>
  31.                 <table className="table table-sripped">
  32.                     <thead>
  33.                     <tr>
  34.                         <td>Id</td>
  35.                         <td>Nazwa użytkownika</td>
  36.                         <td>Email</td>
  37.                         <td>Akcja</td>
  38.                         <td>Akcja</td>
  39.                     </tr>
  40.                     </thead>
  41.                     <tbody>
  42.                     {this.renderUsers(users)}
  43.                     </tbody>
  44.                 </table>
  45.             </div>
  46.         );
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment