'use strict' import React from 'react' import ReactDOM from 'react-dom' import { BrowserRouter as Router, Route, NavLink, Switch, Redirect } from 'react-router-dom' import Progress from './components/Progress' import appReducer from './reducers' import adminReducer from './reducers/admin' import { fetchAdminData, patchUser, patchPublisher } from './actions/admin' import { toggleMenu } from './actions' import Util from './lib/Util' import Icon from './components/Icon' import IconButton from './components/IconButton' import '../styles/admin.scss' import './containers/listitem.scss' const reducer = Util.combineReducers(appReducer, adminReducer) class App extends React.Component { constructor () { super() this.state = { error: '', user: { id: '', email: '', password: '', currentPassword: '' }, users: [], publishers: [], working: false, navMenu: false } this.dispatch = this.dispatch.bind(this) this.getRegisteredUsers = this.getRegisteredUsers.bind(this) this.getRegisteredPublishers = this.getRegisteredPublishers.bind(this) /* this.state.user = { ...this.state.user, 'created_at': 1551151466802, 'updated_at': 1551151520134, 'id': 1, 'email': 'admin@tkluge.net', 'admin': true } */ } dispatch (action) { if (!action) throw new Error('dispatch: missing action') if (action instanceof Function) { action(this.dispatch, () => this.state) } else { const changes = reducer(this.state, action) if (!changes || !Object.keys(changes).length) return this.setState({ ...changes }) } } componentDidMount () { this.dispatch(fetchAdminData()) } getRegisteredUsers () { return this.state.users.map(user => { return (
  • {user.email} this.dispatch(patchUser({ id: user.id, admin: !user.admin }))} id={`is-admin-${user.id}`} />
    Created at:{new Date(user.created_at).toLocaleString()} Updated at:{new Date(user.updated_at).toLocaleString()}
  • ) }) } getRegisteredPublishers () { return this.state.publishers.map(pub => { return (
  • {pub.name}

    Owner:{pub.user.email} App ID:{pub.appid} App domain: {pub.url}
    this.dispatch(patchPublisher({ id: pub.id, whitelisted: !pub.whitelisted }))} id={`is-whitelisted-${pub.id}`} />
    Created at:{new Date(pub.created_at).toLocaleString()} Updated at:{new Date(pub.updated_at).toLocaleString()}
  • ) }) } render () { return (
    {this.state.error &&
    {this.state.error}
    } (

    Site users

    Registered users on RoE

      {this.getRegisteredUsers()}
    )} /> (

    Publishers

    Whitelist sites who can publish books

      {this.getRegisteredPublishers()}
    )} /> } />
    ) } } ReactDOM.render(, document.getElementById('root'))