Skip to content

Commit

Permalink
Admins can see all users information
Browse files Browse the repository at this point in the history
novaisea committed Jul 4, 2021
1 parent 7fbe271 commit e647bd1
Showing 56 changed files with 315 additions and 15,379 deletions.
273 changes: 0 additions & 273 deletions docs/jsdocs/LoginForm.html

This file was deleted.

181 changes: 0 additions & 181 deletions docs/jsdocs/Nav.html

This file was deleted.

273 changes: 0 additions & 273 deletions docs/jsdocs/NewApplication.html

This file was deleted.

273 changes: 0 additions & 273 deletions docs/jsdocs/RegistrationForm.html

This file was deleted.

117 changes: 0 additions & 117 deletions docs/jsdocs/account.js.html

This file was deleted.

229 changes: 0 additions & 229 deletions docs/jsdocs/application.js.html

This file was deleted.

92 changes: 0 additions & 92 deletions docs/jsdocs/applicationcard.js.html

This file was deleted.

149 changes: 0 additions & 149 deletions docs/jsdocs/applicationsForUsers.js.html

This file was deleted.

210 changes: 0 additions & 210 deletions docs/jsdocs/editApplication.js.html

This file was deleted.

Binary file removed docs/jsdocs/fonts/OpenSans-Bold-webfont.eot
Binary file not shown.
1,830 changes: 0 additions & 1,830 deletions docs/jsdocs/fonts/OpenSans-Bold-webfont.svg

This file was deleted.

Binary file removed docs/jsdocs/fonts/OpenSans-Bold-webfont.woff
Binary file not shown.
Binary file removed docs/jsdocs/fonts/OpenSans-BoldItalic-webfont.eot
Binary file not shown.
1,830 changes: 0 additions & 1,830 deletions docs/jsdocs/fonts/OpenSans-BoldItalic-webfont.svg

This file was deleted.

Binary file removed docs/jsdocs/fonts/OpenSans-BoldItalic-webfont.woff
Binary file not shown.
Binary file removed docs/jsdocs/fonts/OpenSans-Italic-webfont.eot
Binary file not shown.
1,830 changes: 0 additions & 1,830 deletions docs/jsdocs/fonts/OpenSans-Italic-webfont.svg

This file was deleted.

Binary file removed docs/jsdocs/fonts/OpenSans-Italic-webfont.woff
Binary file not shown.
Binary file removed docs/jsdocs/fonts/OpenSans-Light-webfont.eot
Binary file not shown.
1,831 changes: 0 additions & 1,831 deletions docs/jsdocs/fonts/OpenSans-Light-webfont.svg

This file was deleted.

Binary file removed docs/jsdocs/fonts/OpenSans-Light-webfont.woff
Binary file not shown.
Binary file removed docs/jsdocs/fonts/OpenSans-LightItalic-webfont.eot
Binary file not shown.
1,835 changes: 0 additions & 1,835 deletions docs/jsdocs/fonts/OpenSans-LightItalic-webfont.svg

This file was deleted.

Binary file removed docs/jsdocs/fonts/OpenSans-LightItalic-webfont.woff
Binary file not shown.
Binary file removed docs/jsdocs/fonts/OpenSans-Regular-webfont.eot
Binary file not shown.
1,831 changes: 0 additions & 1,831 deletions docs/jsdocs/fonts/OpenSans-Regular-webfont.svg

This file was deleted.

Binary file removed docs/jsdocs/fonts/OpenSans-Regular-webfont.woff
Binary file not shown.
399 changes: 0 additions & 399 deletions docs/jsdocs/global.html

This file was deleted.

112 changes: 0 additions & 112 deletions docs/jsdocs/home.js.html

This file was deleted.

137 changes: 0 additions & 137 deletions docs/jsdocs/homegrid.js.html

This file was deleted.

67 changes: 0 additions & 67 deletions docs/jsdocs/index.html

This file was deleted.

163 changes: 0 additions & 163 deletions docs/jsdocs/login.js.html

This file was deleted.

106 changes: 0 additions & 106 deletions docs/jsdocs/messages.js.html

This file was deleted.

99 changes: 0 additions & 99 deletions docs/jsdocs/nav.js.html

This file was deleted.

206 changes: 0 additions & 206 deletions docs/jsdocs/newApplication.js.html

This file was deleted.

208 changes: 0 additions & 208 deletions docs/jsdocs/register.js.html

This file was deleted.

78 changes: 0 additions & 78 deletions docs/jsdocs/requestHandlers.js.html

This file was deleted.

25 changes: 0 additions & 25 deletions docs/jsdocs/scripts/linenumber.js

This file was deleted.

202 changes: 0 additions & 202 deletions docs/jsdocs/scripts/prettify/Apache-License-2.0.txt

This file was deleted.

2 changes: 0 additions & 2 deletions docs/jsdocs/scripts/prettify/lang-css.js

This file was deleted.

28 changes: 0 additions & 28 deletions docs/jsdocs/scripts/prettify/prettify.js

This file was deleted.

358 changes: 0 additions & 358 deletions docs/jsdocs/styles/jsdoc-default.css

This file was deleted.

111 changes: 0 additions & 111 deletions docs/jsdocs/styles/prettify-jsdoc.css

This file was deleted.

132 changes: 0 additions & 132 deletions docs/jsdocs/styles/prettify-tomorrow.css

This file was deleted.

120 changes: 0 additions & 120 deletions docs/jsdocs/upload.js.html

This file was deleted.

35 changes: 0 additions & 35 deletions package-lock.json
4 changes: 4 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -8,9 +8,11 @@ import Account from './components/account';
import Register from './components/register';
import Login from './components/login';
import Admin from './components/admin';
import Users from './components/users';
import Home from './components/homescreen';
import Application from './components/application';
import ApplicationForUsers from './components/applicationsForUsers';
import UserInfo from './components/usersinfo';
import NewApplication from './components/newApplication';
import ContactForm from './components/contact';
import Uploader from './components/upload';
@@ -84,6 +86,8 @@ class App extends React.Component {
<Route path="/newapplication" children={<NewApplication />} />
<Route path="/contact" children={<ContactForm />} />
<Route path="/adminSpace" children={<Admin />}/>
<Route path="/users" children={<Users />}/>
<Route path="/user/:id" children={<UserInfo />}/>
</Switch>
</Content>

4 changes: 2 additions & 2 deletions src/components/admin.js
Original file line number Diff line number Diff line change
@@ -13,10 +13,10 @@ import Icon from './icon.png';
*/
function Admin(props) {
return (
<div className="site-layout-content">
<div>
<div style={{ padding: '2% 20%' }}>
<Image width={200} alt="TLD" src={Icon} />
<PageHeader className="site-page-header"
<PageHeader
title="Trading License Department"
subTitle="Admins can manage all applications from here."/>
</div>
2 changes: 1 addition & 1 deletion src/components/application.js
Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ render() {
let adminSpace = <Space></Space>
if(this.context.user.role === "admin"){ //Only admins can change it!
adminSpace = <Space>
<Button onClick={this.deleteHandler}>Delete application</Button>
<Button danger onClick={this.deleteHandler}>Delete application</Button>
</Space>
}

2 changes: 1 addition & 1 deletion src/components/applicationgrid.js
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ class ApplicationGrid extends React.Component {
const id = this.context.user.ID;
const username = this.context.user.username
const password = this.context.user.password
fetch(`https://animal-hello-3000.codio-box.uk/api/v1/applications/account/${id}`, {
fetch(`https://animal-hello-3000.codio-box.uk/api/v1/applications/owned/${id}`, {
method: 'GET',
headers: {
"Authorization": "Basic " + btoa(username + ":" + password)
2 changes: 1 addition & 1 deletion src/components/contact.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import emailjs from 'emailjs-com';
import UserContext from '../contexts/user';
import { Typography, Button, Input } from 'antd';
import { withRouter } from 'react-router';
import emailjs from 'emailjs-com';

const { Title } = Typography;
const { TextArea } = Input;
5 changes: 3 additions & 2 deletions src/components/nav.js
Original file line number Diff line number Diff line change
@@ -14,8 +14,9 @@ class Nav extends React.Component {
if (this.context.user.role!=="user") {
return (
<Menu theme="dark" mode="horizontal" defaultSelectedKeys={['1']}>
<Menu.Item key="1" disabled={this.context.user.role!== "admin"}><Link to="/adminSpace">Admin</Link></Menu.Item>
<Menu.Item key="2" disabled={!this.context.user.loggedIn}><Link to="/account">Account</Link></Menu.Item>
<Menu.Item key="1" disabled={this.context.user.role!== "admin"}><Link to="/adminSpace">Applications</Link></Menu.Item>
<Menu.Item key="2" disabled={this.context.user.role!== "admin"}><Link to="/users">Users</Link></Menu.Item>
<Menu.Item key="3" disabled={!this.context.user.loggedIn}><Link to="/account">Account</Link></Menu.Item>
<Menu.Item key="4" disabled={!this.context.user.loggedIn} onClick={this.context.logout}> <Link to="/">Logout</Link></Menu.Item>
</Menu>
)
26 changes: 26 additions & 0 deletions src/components/usercard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { Card } from 'antd';
import NavImage from './navimage';
import {Link} from "react-router-dom";

const { Meta } = Card;

class UserCard extends React.Component {

/** Renders all the structure with the data using the user ID */
render() {
const userID = this.props.ID;
return (
<Link to={`/user/${userID}`}>
<Card
style={{ width: 320, textAlign: "center", paddingTop: "50px"}}
cover={<NavImage src={this.props.avatarURL} to={`/users/${userID}`} />}
hoverable={true}>
<Meta title={this.props.username} description={this.props.email} />
</Card>
</Link>
);
}
}

export default UserCard;
28 changes: 28 additions & 0 deletions src/components/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { PageHeader } from 'antd';
import UsersGrid from './usersgrid';
import { Image } from 'antd'
import Icon from './icon.png';

/**
* @function
* @name User
* Function to show the users page
* @param {object} props
* @returns {object} Page Structure
*/
function User(props) {
return (
<div className="site-layout-content">
<div style={{ padding: '2% 20%' }}>
<Image width={200} alt="TLD" src={Icon} />
<PageHeader
title="Users"
subTitle="All registered users appear here"/>
</div>
<UsersGrid/>
</div>
);
}

export default User;
124 changes: 124 additions & 0 deletions src/components/usersgrid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import React from 'react';
import { Col, Row, Input, Select } from 'antd';
import UserCard from './usercard';
import { status, json } from '../utilities/requestHandlers';
import { withRouter } from 'react-router-dom';
import UserContext from '../contexts/user';


class UsersGrid extends React.Component {

static contextType = UserContext;

constructor(props) {
super(props);
this.state = {
users: [],
search:{}
}
}

/**
* @function
* @name componentDidMount
* Function to get all the users in the DB
* @returns {object} Clickable User Cards with their data
*/
componentDidMount() {
const username = this.context.user.username
const password = this.context.user.password
let url = "https://animal-hello-3000.codio-box.uk/api/v1/users"
if (this.props.query) {url = `https://animal-hello-3000.codio-box.uk/api/v1/users?query=${this.props.query}`}
fetch(url, {
method: "GET",
headers: {
"Authorization": "Basic " + btoa(username + ":" + password)
},
})
.then(status)
.then(json)
.then(data => {
this.setState({ users: data })
})
.catch(err => {
console.log("Not found")
});
}

/**
* @function
* @name searchHandler
* Function to handle the search query
* @param {object} value - Query for the search
* @returns {object} Output from the search
*/
searchHandler = value => {
console.log(value)
this.setState({search:value})
}

/** Renders the page using User Card and filters the search query */
render() {
const { Search } = Input;

if (!this.context.user.loggedIn) {
return (
<h2>Login first in order to see applications!</h2>
)
}if (this.context.user.role!=="admin") {
return (
<h2>You have to be a user in order to see applications!</h2>
)
}if(this.state.search.length){ //If anything is written in the search bar does the search
const searchedUser = this.state.users.filter(user=>user.username.toLowerCase() === this.state.search.toLowerCase() || user.email.toLowerCase() === this.state.search.toLowerCase()).map(user => {
return (
<div style={{padding:"10px"}} key={user.ID}>
<Col span={6}>
<UserCard {...user} />
</Col>
</div>
)
});
return (
<div style={{ padding: '3% 20%' }}>
<Search placeholder="Search by Company Name, Company Reference Number or Email"
allowClear
enterButton="Search"
size="large"
onSearch={this.searchHandler}/>

<Row type="flex" justify="space-around">
{searchedUser}
</Row>
</div>
);
}else{ //If search bar is empty shows all applications
const allUsers = this.state.users.map(user => {
return (
<div style={{padding:"10px"}} key={user.ID}>
<Col span={6}>
<UserCard {...user} />
</Col>
</div>
)
});
return (
<div>
<div style={{ padding: '3% 20%' }}>
<Search placeholder="Search by Company Name, Company Reference Number or Email"
allowClear
enterButton="Search"
size="large"
onSearch={this.searchHandler}/>

</div>
<Row type="flex" justify="space-around">
{allUsers}
</Row>
</div>
);
}
}
}

export default withRouter(UsersGrid);
125 changes: 125 additions & 0 deletions src/components/usersinfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import React from 'react';
import { withRouter } from 'react-router';
import { Image, Row, Col, Typography, Space, Button, Form, Select } from 'antd';
import { status, json } from '../utilities/requestHandlers';
import { Link } from "react-router-dom";

import UserContext from '../contexts/user';

const { Title, Paragraph } = Typography;

const { Option } = Select;

class User extends React.Component {

static contextType = UserContext;

constructor(props) {
super(props);
this.deleteHandler = this.deleteHandler.bind(this)
this.state = {
user: {}
}
}

/**
* @function
* @name componentDidMount
* Function to get the data of an user by providing its id
* @returns {object} the object containing the user information
*/
componentDidMount() {
const id = this.props.match.params.id; // available using withRouter()
const username = this.context.user.username
const password = this.context.user.password
fetch(`https://animal-hello-3000.codio-box.uk/api/v1/users/${id}`, {
method: 'GET',
headers: {
"Authorization": "Basic " + btoa(username + ":" + password)
},
})
.then(status)
.then(json)
.then(user => {
this.setState({user:user})
})
.catch(err => {
console.log(`Fetch error for user ${id}`)
});
};

/**
* @function
* @name deleteHandler
* Function that deletes the user using its id
* @returns {object} the information that the user was deleted
*/
deleteHandler() {
const username = this.context.user.username
const password = this.context.user.password
fetch(`https://animal-hello-3000.codio-box.uk/api/v1/users/${this.state.user.ID}`, {
method: "DELETE",
headers: {
"Authorization": "Basic " + btoa(username + ":" + password)
}
})
.then(status)
.then(user => {
alert(`Deleted user for company ${this.state.user.companyName}`);
this.props.history.push('/adminSpace')
})
.catch(error => {
console.log('Delete failed' + error);
});
}

/** Renders all the structure with the data */
render() {
if (!this.context.user.loggedIn) {
return (
<h2>Login first in order to see users!</h2>
)
}if (this.context.user.role!=="admin") {
return (
<h2>You have to be a user in order to see users!</h2>
)
}if (!this.state.user) {
return <h3>Loading user...</h3>
}else {

const user = this.state.user;

let adminSpace = <Space></Space>
if(this.context.user.role === "admin"){ //Only admins can change it!
adminSpace = <Space>
<Button danger onClick={this.deleteHandler}>Delete user</Button>
</Space>
}


/** Returns the data about the user */
return(
<div>
<Row type="flex" justify="space-around" align="middle">
<Col span={6} align="center">
<Image width={200} src={user.avatarURL} />
</Col>
<Col span={12}>
<Title>{user.firstName} {user.lastName}</Title>
<Paragraph>Username: {user.username}</Paragraph>
<Paragraph>Email: {user.email}</Paragraph>
<Paragraph>Date Registered: {user.dateRegistered}</Paragraph>
<Paragraph>Role: {user.role}</Paragraph>
</Col>
<Col span={6} align="center">
{adminSpace}
</Col>
</Row>
</div>

);
}
}
}

export default withRouter(User);

0 comments on commit e647bd1

Please sign in to comment.