diff --git a/src/App.js b/src/App.js index 04d8a96..770e080 100644 --- a/src/App.js +++ b/src/App.js @@ -12,7 +12,6 @@ import Home from './components/homescreen'; import Application from './components/application'; import ApplicationForUsers from './components/applicationsForUsers'; import NewApplication from './components/newApplication'; -import EditApplication from './components/editApplication'; import Messages from './components/messages'; import Uploader from './components/upload'; @@ -84,7 +83,6 @@ class App extends React.Component { } /> } /> } /> - } /> }/> diff --git a/src/components/application.js b/src/components/application.js index 95b3f8d..9fbe510 100644 --- a/src/components/application.js +++ b/src/components/application.js @@ -1,14 +1,15 @@ import React from 'react'; import { withRouter } from 'react-router'; -import { Image, Row, Col, Typography, Space, Button, Form, Input } from 'antd'; +import { Image, Row, Col, Typography, Space, Button, Form, Input, Select } from 'antd'; import { status, json } from '../utilities/requestHandlers'; -import Select from 'react-select'; import { Link, useHistory } from "react-router-dom"; import UserContext from '../contexts/user'; const { Title, Paragraph } = Typography; +const { Option } = Select; + class Application extends React.Component { static contextType = UserContext; @@ -71,7 +72,7 @@ class Application extends React.Component { .then(json) .then(data => { console.log(data); - alert("Application successfully updated and will be reviewed soon!") + alert("Application Updated!") }) .catch(errorResponse => { console.log(errorResponse) @@ -97,7 +98,7 @@ class Application extends React.Component { .then(status) .then(user => { console.log(`Deleted application ${this.state.application.ID}`); - this.props.history.push('/') + this.props.history.push('/adminSpace') }) .catch(error => { console.log('Delete failed' + error); @@ -106,25 +107,26 @@ class Application extends React.Component { /** Renders all the structure with the data */ render() { - if (!this.state.application) { + if (!this.context.user.loggedIn) { + return ( +

Login first in order to see applications!

+ ) + }if (this.context.user.role!="admin") { + return ( +

You have to be a user in order to see applications!

+ ) + }if (!this.state.application) { return

Loading application...

- } + }else { + const application = this.state.application; - //Error Here!! Change the user.role to a valid verification let adminSpace = - if(this.context.user.role === "admin"){ //Add user.role so that only admins can change it! + if(this.context.user.role === "admin"){ //Only admins can change it! adminSpace = - } - - const options = [ - { value: 'pending', label: 'Pending' }, - { value: 'accepted', label: 'Accepted' }, - { value: 'rejected', label: 'Rejected' }, - ] /** Returns the data about the application */ return( @@ -142,14 +144,18 @@ render() { Created In: {application.dateCreated} Status: {application.status}
- - + + - + - + @@ -162,5 +168,6 @@ render() { ); } } +} export default withRouter(Application); diff --git a/src/components/applicationsForUsers.js b/src/components/applicationsForUsers.js index b0180b6..d84760a 100644 --- a/src/components/applicationsForUsers.js +++ b/src/components/applicationsForUsers.js @@ -50,9 +50,18 @@ class ApplicationForUsers extends React.Component { /** Renders all the structure with the data */ render() { - if (!this.state.application) { + if (!this.context.user.loggedIn) { + return ( +

Login first in order to see your application!

+ ) + }if (this.context.user.role!="user") { + return ( +

You have to be a user in order to see your application!

+ ) + }if (!this.state.application) { return

Loading application...

- } + }else { + const application = this.state.application; /** Returns the data about the application */ @@ -78,7 +87,7 @@ render() { ); } - + } } diff --git a/src/components/editApplication.js b/src/components/editApplication.js deleted file mode 100644 index d2dace8..0000000 --- a/src/components/editApplication.js +++ /dev/null @@ -1,103 +0,0 @@ -import React from 'react'; -import { status, json } from '../utilities/requestHandlers'; -import { Form, Input, Button, Typography } from 'antd'; -import UserContext from '../contexts/user'; - -const { Title } = Typography; - -const usernameRules= [ - {required: true, message: "The username field is empty", whitespace:true} -] - -const formItemLayout = { - labelCol: { xs: { span: 24 }, sm: { span: 6 } }, - wrapperCol: { xs: { span: 24 }, sm: { span: 12 } } - }; - -const tailFormItemLayout = { - wrapperCol: { xs: { span: 24, offset: 0 }, sm: { span: 16, offset: 6 } }, -}; - -class EditForm extends React.Component { - - static contextType = UserContext; - - constructor(props) { - super(props); - this.onFinish = this.onFinish.bind(this) - this.state = { - application: {} - } - } - - render() { - - if (!this.context.user.loggedIn) { - return ( - You must login to view this page. - ) - } else { - console.log("hello" + this.state.application.tradeName) - return ( -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - ); - } - }; - - onFinish = (values) => { - console.log('Form data: ', values); - const {confirm, ...data} = values; - fetch(`https://animal-hello-3000.codio-box.uk/api/v1/applications/${this.state.application.ID}`, { - method: "PUT", - body: JSON.stringify(data), - headers: { - "Authorization": "Basic " + btoa(this.context.user.username + ":" + this.context.user.password), - "Content-Type": "application/json" - } - }) - .then(status) - .then(json) - .then(data => { - console.log(data); - alert("Application successfully updated and will be reviewed soon!") - this.props.history.push('/') - }) - .catch(errorResponse => { - console.log(errorResponse) - alert(errorResponse) - }) - } -}; - -export default EditForm; \ No newline at end of file diff --git a/src/components/homegrid.js b/src/components/homegrid.js index 2e6ef98..46b1fe6 100644 --- a/src/components/homegrid.js +++ b/src/components/homegrid.js @@ -46,10 +46,17 @@ class HomeGrid extends React.Component { /** Renders the page using Application Card */ render() { - console.log(this.context.errorCode) - if (!this.state.applications.length) { - return

Loading applications...

- } + if (!this.context.user.loggedIn) { + return ( +

Login first in order to see applications!

+ ) + }if (this.context.user.role!="admin") { + return ( +

You have to be a user in order to see applications!

+ ) + }if (!this.state.application) { + return

Loading application...

+ }else { const applicationList = this.state.applications.map(application => { return (
@@ -66,5 +73,6 @@ class HomeGrid extends React.Component { ); } } +} export default withRouter(HomeGrid); diff --git a/src/components/login.js b/src/components/login.js index 074158c..12c5d97 100644 --- a/src/components/login.js +++ b/src/components/login.js @@ -80,6 +80,7 @@ class LoginForm extends React.Component { } return (
+

Login Page

diff --git a/src/components/nav.js b/src/components/nav.js index 0f22a64..1098a81 100644 --- a/src/components/nav.js +++ b/src/components/nav.js @@ -11,9 +11,7 @@ class Nav extends React.Component { static contextType = UserContext; - //Change the Admin space section for admins only!! render() { - console.log(this.context.user.role) return ( <>
diff --git a/src/components/newApplication.js b/src/components/newApplication.js index 68e9bf6..0fc4856 100644 --- a/src/components/newApplication.js +++ b/src/components/newApplication.js @@ -5,21 +5,19 @@ import UserContext from '../contexts/user'; const { Title } = Typography; -const usernameRules= [ - {required: true, message: "The username field is empty", whitespace:true} -] +const { TextArea } = Input const nameRule=[ {required:true,message:'Please type the name of the compnay.',whitespace:false, min:5,max:150} ] const crnRule=[ - {required:true,message:'Please type the company reference number.',whitespace:false, min:8,max:8} + {required:true, type:'number', message:'Please a valid company reference number.',whitespace:false, min:8,max:8} ] const addressRule=[ {required:true,message:'Please enter the address where the company is located.',whitespace:false, min:5,max:32} ] const emailRule=[ - {required:true,message:'Please enter the company email.',whitespace:false, min:5,max:32} + {required:true, type:'email', message:'Please enter a valid company email.',whitespace:false, min:5,max:32} ] const dateFoundedRule=[ {required:true,message:'Please enter the foundation date of the company.'} @@ -76,30 +74,37 @@ class NewApplication extends React.Component { return (

Login first in order to create an application!

) - } else { + }if (this.context.user.role!="user") { + return ( +

You have to be a user in order to create an application!

+ ) + }else { return ( - + +

Application Form

+ - +