diff --git a/src/Components/User/ListUser.jsx b/src/Components/User/ListUser.jsx index fede8c09..0ae4b8da 100644 --- a/src/Components/User/ListUser.jsx +++ b/src/Components/User/ListUser.jsx @@ -1,12 +1,12 @@ import React, { useState, useContext, useEffect } from 'react' -import { Button, Row, Table, Card, Col, Form, - Container, } from 'react-bootstrap'; +import { Button, Row, Table, Container } from 'react-bootstrap'; import {CircleImage} from '../../Layout/Image/styledImage'; import { GlobalState } from '../../GlobalState'; import axios from "axios"; import moment from 'moment-timezone' import NavBar from '../NavBar/NavBar'; import Footer from '../Footer/Footer'; +import { useHistory } from 'react-router-dom'; const initialState = { name: "", @@ -21,13 +21,15 @@ const UsersList = () => { const [active, setActive] = useState(false) const [userView, setUserView] = useState(false) const [createdUser, setCreatedUser] = useState(initialState); + const history = useHistory() useEffect(() => { const getAllUsers = async () => { const res = await axios.get(`/api/user/${user._id}`) - console.log(res) - console.log(users) + console.log(res.data.location, 'res') setUsers(res.data.users) + console.log(users, 'users from userslist') + console.log(user, 'user from userlist pulled from state') } getAllUsers() }, [user, active]) @@ -37,6 +39,7 @@ const deleteUser = async (id) => { const deleteUser = axios.delete(`/api/user/${id}`) await deleteUser setActive(!active) + history.push('/users') } catch (err) { alert(err.response.data.msg) } @@ -47,6 +50,7 @@ const addUser = async () => { const addUser = axios.post(`/api/user/register`, { ...createdUser }) await addUser setUserView(false) + history.push('/users') } catch (err) { alert(err.response.data.msg) } @@ -80,37 +84,49 @@ const {name, email, password, role} = createdUser; return ( <> - - + + Add User - - - - - - - Name - - - - Role - - - - - Email - - - - Password - - - Save - setUserView(false)}>Cancel - - - - + + + + Name + + + + Role + + + + Email + + + + Password + + + Save + setUserView(false)}>Cancel + + > )} @@ -124,7 +140,7 @@ const {name, email, password, role} = createdUser; User Management - setUserView(true)}>Add Employee + setUserView(true)}>Add User