summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/user/containers/user.index.js
blob: 8b207e0bc3fa414b1693c636c2845cb23d348956 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, { Component } from 'react'
import { Link } from 'react-router-dom'
import { connect } from 'react-redux'

import { Loader } from 'app/common'
import actions from 'app/actions'

import UserMenu from '../components/user.menu'

// const { result, collectionLookup } = this.props

class UserIndex extends Component {
  componentDidMount() {
    this.fetch()
  }

  fetch() {
    actions.user.index()
  }

  render() {
    const { currentUser } = this.props
    const { loading, lookup, order } = this.props.user.index
    if (loading) {
      return (
        <section>
          <Loader />
        </section>
      )
    }
    if (!lookup || !order.length) {
      return (
        <section>
          <div className="row user-index">
            <UserMenu />
            <div>
              <h1>Users</h1>
              <p className='gray'>
                {"No users"}
              </p>
            </div>
          </div>
        </section>
      )
    }
    return (
      <section>
        <div className="row user-index">
          <UserMenu />
          <div className="user-list">
            <h1>Users</h1>
            {order.map(id => {
              const user = lookup[id]
              return (
                <div key={id}>
                  {(currentUser.is_admin || currentUser.id === user.id)
                    ? <Link to={"/users/" + id + "/edit/"}>
                        {user.username}
                      </Link>
                    : user.username
                  }
                  {user.is_admin && " (admin)"}
                </div>
              )
            })}
          </div>
        </div>
        {order.length >= 50 && <button className='loadMore' onClick={() => this.fetch(true)}>Load More</button>}
      </section>
    )
  }
}

const mapStateToProps = state => ({
  user: state.user,
  currentUser: state.auth.user,
})

export default connect(mapStateToProps)(UserIndex)