diff --git a/public/index.html b/public/index.html index f5b5090..288f0bb 100644 --- a/public/index.html +++ b/public/index.html @@ -24,7 +24,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - Dog Shelter + Trading License Department diff --git a/src/components/.newApplication.js.swp b/src/components/.newApplication.js.swp new file mode 100644 index 0000000..99d8995 Binary files /dev/null and b/src/components/.newApplication.js.swp differ diff --git a/src/components/application.js b/src/components/application.js index 2086539..d23ace2 100644 --- a/src/components/application.js +++ b/src/components/application.js @@ -1,10 +1,10 @@ import React from 'react'; import { withRouter } from 'react-router'; -import { Image, Row, Col, Typography, Space, Button } from 'antd' -import ApplicationIcon from './applicationicon'; +import { Image, Row, Col, Typography, Space, Button } from 'antd'; import { status, json } from '../utilities/requestHandlers'; import UserContext from '../contexts/user'; +import {useContext} from 'react'; const { Title, Paragraph } = Typography; @@ -22,8 +22,15 @@ class Application extends React.Component { componentDidMount() { const id = this.props.match.params.id; // available using withRouter() - - fetch(`https://animal-hello-3000.codio-box.uk/api/v1/applications/${id}`) + const username = this.context.user.username + const password = this.context.user.password + const url = "https://animal-hello-3000.codio-box.uk/api/v1/applications/${id}" + fetch(url, { + method: "GET", + headers: { + "Authorization": "Basic " + btoa(username + ":" + password) + }, + }) .then(status) .then(json) .then(application => { @@ -60,19 +67,13 @@ class Application extends React.Component { //Error Here!! Change the user.role to a valid verification let adminSpace = - if(this.context.user.loggedIn){ if(this.context.user.loggedIn){ adminSpace = - } } - if (!application) { - return

Loading applications...

- } - return( //add {adminSpace} here
@@ -84,7 +85,7 @@ class Application extends React.Component { Company Registration Number: {application.crn} Address: {application.address} Email: {application.email} - Funded in: {application.dateFunded} + Founded in: {application.dateFunded} Created In: {application.dateCreated} Status: {application.status} diff --git a/src/components/applicationcard.js b/src/components/applicationcard.js index 944528c..e40bf22 100644 --- a/src/components/applicationcard.js +++ b/src/components/applicationcard.js @@ -1,6 +1,5 @@ import React from 'react'; import { Card } from 'antd'; -import ApplicationIcon from './applicationicon'; import NavImage from './navimage'; import {Link} from "react-router-dom"; diff --git a/src/components/applicationicon.js b/src/components/applicationicon.js deleted file mode 100644 index 09f9905..0000000 --- a/src/components/applicationicon.js +++ /dev/null @@ -1,90 +0,0 @@ -import React from 'react'; - -import LikeOutlined from '@ant-design/icons/LikeOutlined'; -import LikeFilled from '@ant-design/icons/LikeFilled'; - -import { status, json } from '../utilities/requestHandlers'; - -/** - * @typedef {"filled" | "outlined"} theme - * @typedef {"like"} iconType - */ - -/** - * Determine the icon to be displayed - * - * @param {theme} theme - design of icon - * @param {iconType} iconType - icon to show - * @returns {Object} - the correct Ant Design icon component - */ -function getIcon (theme, iconType) { - let Icon; - - if (theme === 'filled') { - Icon = LikeFilled - } else if (theme === 'outlined') { - Icon = LikeOutlined - } - return Icon; -} - -class ApplicationIcon extends React.Component { - constructor(props){ - super(props); - this.state = { - selected: props.selected, - count: 0 - }; - this.onClick = this.onClick.bind(this); - } - - onClick(){ - if (this.props.viewOnly) { - console.log('This icon is view only: preventing update'); - return; - } - //reverse the selected state with every click - this.setState({selected: !this.state.selected}); - } - - componentDidMount() { - if (!this.props.countLink) return; // prevent fetch on parent mount - fetch(this.props.countLink) - .then(status) - .then(json) - .then(count => { - this.setState({count:count}) - }) - .catch(err => { - console.log(`${this.props.type} icon error for application ${this.props.id}`) - }); - } - - componentDidUpdate(prevProps, prevState){ - if (prevState.selected !== this.state.selected) { - //run the handler passed in by the parent component - this.props.handleToggle(this.state.selected); - } - } - - render(){ - const theme = this.state.selected ? 'filled' : 'outlined'; - const iconType = this.props.type; - const Icon = getIcon(theme, iconType); - - //return a span that contains the desired icon - //and a space then the counter - //if the icon is clicked we will run onClick handler - - return ( - - - {this.state.count} - - ); - } -} - -export default ApplicationIcon; diff --git a/src/components/editApplication.js b/src/components/editApplication.js index f881180..af8b668 100644 --- a/src/components/editApplication.js +++ b/src/components/editApplication.js @@ -1,4 +1,4 @@ -import {Form, Input, Button, Row,Col} from 'antd' +import {Form, Input, Button, Row, Col, Select} from 'antd' import { Redirect } from 'react-router-dom' import {status,json} from '../utilities/requestHandlers' import UserContext from '../contexts/user' @@ -15,8 +15,7 @@ class EditApplication extends React.Component{ constructor(props){ super(props) this.state={ - imageURL:null, - redirect:null + imageURL:null } this._onFinish =this._onFinish.bind(this) this._onCancel =this._onCancel.bind(this) @@ -41,26 +40,25 @@ class EditApplication extends React.Component{ values={companyName:companyName,crn:crn,address:address,email:email,dateFunded:dateFunded} console.log("Befpre IF -statement ") console.log(values) - //Change listing_to_update for the one used in the TLD backend - values.id=this.context.Listing_to_update.ID + values.id=this.context.ID if (!companyName===true) { - values.companyName=this.context.Listing_to_update.companyName + values.companyName=this.context.companyName } if (!crn===true) { - values.crn=this.context.Listing_to_update.crn + values.crn=this.context.crn } if (!address===true) { - values.address=this.context.Listing_to_update.address + values.address=this.context.address } if (!email===true) { - values.email=this.context.Listing_to_update.email + values.email=this.context.email } if (!dateFunded===true) { - values.dateFunded=this.context.Listing_to_update.dateFunded + values.dateFunded=this.context.dateFunded } console.log("after if statement") console.log(values) - this.context.updateListing(values) + this.context.application(values) const formData= new FormData formData.append('id',values.id) @@ -69,8 +67,8 @@ class EditApplication extends React.Component{ formData.append('address',values.address) formData.append('email',values.email) formData.append('dateFunded',values.dateFunded) - if (this.state.upload) { - formData.append('upload',this.state.upload,this.state.upload.name) + if (this.state.imageURL) { + formData.append('imageURL',this.state.imageURL) } @@ -84,40 +82,44 @@ class EditApplication extends React.Component{ .then(status) .then(json) .then(()=>{ - this.setState({redirect:`/{this.context.Listing_to_update.id}`}) - alert("Successfully updated listing") + this.setState({redirect:`/{this.context.id}`}) + alert("Successfully updated application") }) .catch(console.error()) } render(){ - if (this.state.redirect) { - return - } return( <> -

Updating listing

+

Update Application

- + - + - + - + - + - + /* Add select for the application status + + + */ + diff --git a/src/components/homegrid.js b/src/components/homegrid.js index 74f7bf2..1207ce5 100644 --- a/src/components/homegrid.js +++ b/src/components/homegrid.js @@ -3,8 +3,12 @@ import { Col, Row } from 'antd'; import ApplicationCard from './applicationcard'; import { status, json } from '../utilities/requestHandlers'; import { withRouter } from 'react-router-dom'; +import UserContext from '../contexts/user'; +import {useContext} from 'react'; class HomeGrid extends React.Component { + + static contextType = UserContext; constructor(props) { super(props); @@ -13,11 +17,18 @@ class HomeGrid extends React.Component { } } + componentDidMount() { + const username = this.context.user.username + const password = this.context.user.password let url = "https://animal-hello-3000.codio-box.uk/api/v1/applications" if (this.props.query) {url = `https://animal-hello-3000.codio-box.uk/api/v1/applications?query=${this.props.query}`} - console.log(url) - fetch(url) + fetch(url, { + method: "GET", + headers: { + "Authorization": "Basic " + btoa(username + ":" + password) + }, + }) .then(status) .then(json) .then(data => { @@ -32,9 +43,6 @@ class HomeGrid extends React.Component { render() { if (!this.state.applications.length) { - if(!this.state.found){ - return

No applications were found. Refresh the page or check your connection!

- } return

Loading applications...

} const applicationList = this.state.applications.map(application => { diff --git a/src/components/newApplication.js b/src/components/newApplication.js index 4eb5f45..e059413 100644 --- a/src/components/newApplication.js +++ b/src/components/newApplication.js @@ -1,6 +1,6 @@ import React from 'react' import UserContext from '../contexts/user' -import { Form, Input, Button,Upload } from 'antd' +import { Form, Input, Button, Upload, Row,Col, DatePicker } from 'antd' import { status, json } from '../utilities/requestHandlers' import { Redirect } from 'react-router-dom' const formItemLayout = { @@ -25,10 +25,10 @@ const emailRule=[ {required:true,message:'Please enter the company email.',whitespace:false, min:5,max:32} ] const dateFoundedRule=[ - {required:true,message:'Please enter the foundation date of the company.',whitespace:false, min:5,max:32} + {required:true,message:'Please enter the foundation date of the company.',whitespace:false} ] /** - * Form to add new listing: + * Form to add new application: */ class NewApplication extends React.Component{ constructor(props){ @@ -39,8 +39,7 @@ class NewApplication extends React.Component{ address:"", email:"", dateFunded:"", - imageURL:"", - redirect:null + imageURL:"" } this.handleSubmit =this.handleSubmit.bind(this) this.handleFile =this.handleFile.bind(this) @@ -67,7 +66,7 @@ class NewApplication extends React.Component{ formData.append('address',this.state.address) formData.append('email',this.state.email) formData.append('dateFunded',this.state.dateFunded) - formData.append('imageURL',this.state.upload,this.state.imageURL.name) + formData.append('imageURL',this.state.imageURL) fetch('https://animal-hello-3000.codio-box.uk/api/v1/applications',{ method:"POST", body:formData, @@ -78,11 +77,11 @@ class NewApplication extends React.Component{ .then(status) .then(json) .then(()=>{ - alert("Successfully added new listing") - this.setState({redirect:"/"})// change this to all users listings pages + alert("Successfully added new application") + this.setState({redirect:"/"})// change this to all users applications pages }) .catch(err => { - alert("Error trying to add new listing") + alert("Error trying to add new application") console.log(err) }) } @@ -96,10 +95,13 @@ class NewApplication extends React.Component{ this.setState({upload:e.target.files[0]}) } render(){ - if (this.state.redirect) { - return - } return( + <> + + +

Create New Application

+ +
@@ -113,16 +115,17 @@ class NewApplication extends React.Component{