Return list of users to admin page

This commit is contained in:
Michael Rode
2019-09-02 23:01:39 -05:00
parent 62de76aca8
commit efdfc798a0
7 changed files with 69 additions and 40 deletions

6
.prettierrc Normal file
View File

@@ -0,0 +1,6 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 70,
}

View File

@@ -22,7 +22,7 @@ export const fetchUser = () => async dispatch => {
};
export const fetchUsers = () => async dispatch => {
const res = await axios.get('/api/admin/current_user');
const res = await axios.get('/api/admin/users');
dispatch({ type: types.FETCH_USERS, payload: res.data });
};

View File

@@ -6,49 +6,50 @@ import * as actions from './../actions';
import Typography from '@material-ui/core/Typography';
class Admin extends Component {
async componentDidMount() {
async componentDidMount() {
await this.props.fetchUsers();
console.log('mike--', this.props.auth)
}
renderUsers() {
if (this.props.auth.users) {
const usersList = this.props.auth.users.map(user => {
return (
<Typography
variant="h2"
key={user.email}
align="center"
color="textSecondary"
paragraph
className="z-depth-2 code"
>
{user.email}
</Typography>
)
})
return <div>{usersList}</div>
}
}
render() {
if (!this.props) {
return;
}
if (!this.props.auth.admin) {
console.log('where are my props', this.props)
if (!this.props.auth.user || !this.props.auth.user.admin) {
console.log('where are my props', this.props.auth)
return <div><p>Checking for admin rights..</p></div>
}
console.log(this.props.auth);
return (
<div>
<HeroSimple />
console.log(this.props.auth);
return (
<div>
<HeroSimple />
<div className="row flex-center">
<Typography
variant="h4"
align="center"
color="textSecondary"
paragraph
>
Select a user to login as &nbsp;
<a href="https://plex.tv/link" target="_blank">
plex.com/link.
</a>
</Typography>
</div>
<div className=" flex-center ">
<Typography
variant="h2"
align="center"
color="textSecondary"
paragraph
className="z-depth-2 code"
>
A list of users
</Typography>
</div>
<div className="row flex-center">
{this.renderUsers()}
</div>
);
</div>
);
}
}

View File

@@ -1,4 +1,4 @@
import {types} from '../actions/index';
import { types } from '../actions/index';
export const initialState = {
loading: false,
@@ -7,17 +7,17 @@ export const initialState = {
users: '',
};
export default function(state = {}, action) {
console.log('action - payload', action.payload);
export default function (state = {}, action) {
console.log('action - payload', action.type);
switch (action.type) {
case types.FETCH_USER:
return action.payload || false;
return { ...state, user: action.payload };
case types.FETCH_USERS:
return action.payload || false;
return { ...state, users: action.payload };
case types.FETCH_PIN:
return {...state, plexPin: action.payload};
return { ...state, plexPin: action.payload };
case types.CHECK_PLEX_PIN:
return {...state, plexToken: action.payload};
return { ...state, plexToken: action.payload };
default:
return state;
}

View File

@@ -0,0 +1,11 @@
import { Router } from 'express';
import models from '../db/models'
const router = Router();
router.get('/users', async (req, res) => {
const users = await models.User.findAll()
res.send(users);
});
export default router;

View File

@@ -10,6 +10,7 @@ import tdaw from './routes/tdaw.route';
import movieDb from './routes/movieDb.route';
import sonarr from './routes/sonarr.route';
import auth from './routes/auth.route';
import admin from './routes/admin.route';
import recommend from './routes/recommend.route';
require('./services/auth/passport');
@@ -44,6 +45,7 @@ export default () => {
server.use('/api/recommend', recommend);
server.use('/auth', auth);
server.use('/api/auth', auth);
server.use('/api/admin', admin);
if (process.env.NODE_ENV === 'production') {
server.use(express.static('client/build'));

View File

@@ -0,0 +1,9 @@
import adminController from '../controllers/admin.controller';
const express = require('express');
const router = express.Router();
router.use(adminController);
export default router;