-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add fix for PostCode on Match form - Add value prop * Add SummaryTable component for useful stats - For num results + capped results * Add ChildRefTable component for child references - Not using Redux, just using fetch() inside the component * Add siccodes conversion JSON - Add SIC code conversion to expand view * Add ResultsTable component * Add additional props into ResultsTable - DefaultPageSize, pagination etc. * Fix clear functionality for UBRN search - Focus on UBRN input after clear * Remove comments, add config for /business endpoint * Add proper formatting of ExpandView JSON * Add Business Index description on Home page * Fix Logout logic, handle 500's - If there is a server error whilst logging out, the user will still be logged out * Clear sessionStorage rather than localStorage
- Loading branch information
Showing
14 changed files
with
1,034 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import ReactTable from 'react-table'; | ||
import ErrorModal from '../components/ErrorModal'; | ||
import industryCodeDescription from '../utils/siccode'; | ||
import config from '../config/api-urls'; | ||
import { formatData } from '../utils/helperMethods'; | ||
|
||
const { REROUTE_URL, API_VERSION, BUSINESS_ENDPOINT } = config; | ||
|
||
class ChildRefTable extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
isLoading: true, | ||
data: [], | ||
error: false, | ||
errorMessage: '', | ||
}; | ||
this.closeModal = this.closeModal.bind(this); | ||
this.fetchData = this.fetchData.bind(this); | ||
} | ||
componentDidMount() { | ||
this.fetchData(this.props.row); | ||
} | ||
fetchData(row) { | ||
fetch(`${REROUTE_URL}`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': sessionStorage.getItem('accessToken'), | ||
}, | ||
body: JSON.stringify({ | ||
method: 'GET', | ||
endpoint: `${API_VERSION}/${BUSINESS_ENDPOINT}/${row.original.id}`, | ||
}), | ||
}) | ||
.then(response => { | ||
if (response.ok) { | ||
return response.json(); | ||
} | ||
throw new Error(`Error: ${response.status} ${response.statusText}`); | ||
}) | ||
.then(data => this.setState({ data: formatData(data), isLoading: false })) | ||
.catch(error => this.setState({ errorMessage: error.message, error: true, isLoading: false })); | ||
} | ||
closeModal() { | ||
this.setState({ error: false, errorMessage: '' }); | ||
} | ||
render() { | ||
return ( | ||
<div style={{ padding: '20px' }}> | ||
<ReactTable | ||
data={this.state.data} | ||
columns={[ | ||
{ | ||
Header: 'Company Number', | ||
accessor: 'companyNo', | ||
}, | ||
{ | ||
Header: 'VAT References', | ||
accessor: 'vatRefs', | ||
}, | ||
{ | ||
Header: 'PAYE References', | ||
accessor: 'payeRefs', | ||
}, | ||
]} | ||
defaultPageSize={1} | ||
loading={this.state.isLoading} | ||
className="-striped -highlight" | ||
showPaginationTop={false} | ||
showPaginationBottom={false} | ||
/> | ||
<h3>Industry Code: {industryCodeDescription[this.state.data.industryCode]}</h3> | ||
<ErrorModal | ||
show={this.state.error} | ||
message={this.state.errorMessage} | ||
close={this.closeModal} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
ChildRefTable.propTypes = { | ||
row: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default ChildRefTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import ReactTable from 'react-table'; | ||
import 'react-table/react-table.css'; | ||
import SummaryTable from '../components/SummaryTable'; | ||
import ChildRefTable from '../components/ChildRefTable'; | ||
|
||
const ResultsTable = ({ results, showFilter, showPagination, defaultPageSize }) => { | ||
return ( | ||
<div id="react-table"> | ||
<ReactTable | ||
showPagination={showPagination} | ||
data={results} | ||
filterable={showFilter} | ||
columns={[ | ||
{ | ||
Header: 'UBRN', | ||
id: 'id', | ||
accessor: d => d.id, | ||
}, | ||
{ | ||
Header: 'Business Name', | ||
id: 'businessName', | ||
accessor: d => d.businessName, | ||
}, | ||
{ | ||
Header: 'PostCode', | ||
id: 'postCode', | ||
accessor: d => d.postCode, | ||
}, | ||
{ | ||
Header: 'Industry Code', | ||
id: 'industryCode', | ||
accessor: d => d.industryCode, | ||
}, | ||
{ | ||
Header: 'Legal Status', | ||
id: 'legalStatus', | ||
accessor: d => d.legalStatus, | ||
}, | ||
{ | ||
Header: 'Trading Status', | ||
id: 'tradingStatus', | ||
accessor: d => d.tradingStatus, | ||
}, | ||
{ | ||
Header: 'Turnover', | ||
id: 'turnover', | ||
accessor: d => d.turnover, | ||
}, | ||
{ | ||
Header: 'Employment Bands', | ||
id: 'employmentBands', | ||
accessor: d => d.employmentBands, | ||
}, | ||
]} | ||
defaultPageSize={defaultPageSize} | ||
className="-striped -highlight" | ||
SubComponent={row => { | ||
return ( | ||
<ChildRefTable row={row} /> | ||
); | ||
}} | ||
/> | ||
<br /><br /> | ||
<SummaryTable | ||
title="Useful Information" | ||
items={[ | ||
{ key: 'Number of results', value: results.length }, | ||
{ key: 'Results capped at 10,000', value: (results.length === 10000) ? 'true' : 'false' }, | ||
]} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
ResultsTable.defaultProps = { | ||
defaultPageSize: 10, | ||
}; | ||
|
||
ResultsTable.propTypes = { | ||
results: PropTypes.array.isRequired, | ||
showFilter: PropTypes.bool.isRequired, | ||
showPagination: PropTypes.bool.isRequired, | ||
defaultPageSize: PropTypes.number, | ||
}; | ||
|
||
export default ResultsTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const SummaryTable = ({ title, items }) => { | ||
return ( | ||
<div className="sdc-isolation"> | ||
<div className="summary"> | ||
<h2 className="summary__title saturn" id="">{title}</h2> | ||
{ | ||
items.map((item) => { | ||
return ( | ||
<div className="summary__items"> | ||
<div className="summary__question" id=""> | ||
{item.key} | ||
</div> | ||
<div className="summary__answer"> | ||
<div className="summary__answer-text" id="">{item.value}</div> | ||
</div> | ||
</div> | ||
); | ||
}) | ||
} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
SummaryTable.propTypes = { | ||
title: PropTypes.string.isRequired, | ||
items: PropTypes.array.isRequired, | ||
}; | ||
|
||
export default SummaryTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.