I'll create a React app that displays the tax data table and allows users to add new companies. Here's the implementation:
// App.jsx
import React, { useState } from 'react';
import './App.css';
const initialCompanies = [
{
id: 1,
name: "Amazon UK Services",
employees: 30000,
profit: "£204m",
estimatedTax: "£50m",
actualTax: "£0 (tax credit)",
address: "1 Principal Place, London, EC2A 2FA",
ceo: "Doug Gurr"
},
// ... add other companies from the table
];
function App() {
const [companies, setCompanies] = useState(initialCompanies);
const [formData, setFormData] = useState({
name: '',
employees: '',
profit: '',
estimatedTax: '',
actualTax: '',
address: '',
ceo: ''
});
const handleInputChange = (e) => {
const { name, value } = e.target;
setFormData(prevState => ({
...prevState,
[name]: value
}));
};
const handleSubmit = (e) => {
e.preventDefault();
const newCompany = {
id: companies.length + 1,
...formData
};
setCompanies([...companies, newCompany]);
setFormData({
name: '',
employees: '',
profit: '',
estimatedTax: '',
actualTax: '',
address: '',
ceo: ''
});
};
return (
<div className="app">
<h1>UK Companies Tax Data During COVID</h1>
<div className="table-container">
<table>
<thead>
<tr>
<th>Company Name</th>
<th>Employees</th>
<th>Profit</th>
<th>Estimated Tax</th>
<th>Actual Tax Paid</th>
<th>Address</th>
<th>CEO</th>
</tr>
</thead>
<tbody>
{companies.map(company => (
<tr key={company.id}>
<td>{company.name}</td>
<td>{company.employees}</td>
<td>{company.profit}</td>
<td>{company.estimatedTax}</td>
<td>{company.actualTax}</td>
<td>{company.address}</td>
<td>{company.ceo}</td>
</tr>
))}
</tbody>
</table>
</div>
<div className="form-container">
<h2>Add New Company</h2>
<form onSubmit={handleSubmit}>
<div className="form-group">
<label>Company Name:</label>
<input
type="text"
name="name"
value={formData.name}
onChange={handleInputChange}
required
/>
</div>
<div className="form-group">
<label>Employees:</label>
<input
type="number"
name="employees"
value={formData.employees}
onChange={handleInputChange}
required
/>
</div>
<div className="form-group">
<label>Profit:</label>
<input
type="text"
name="profit"
value={formData.profit}
onChange={handleInputChange}
required
/>
</div>
<div className="form-group">
<label>Estimated Tax:</label>
<input
type="text"
name="estimatedTax"
value={formData.estimatedTax}
onChange={handleInputChange}
required
/>
</div>
<div className="form-group">
<label>Actual Tax Paid:</label>
<input
type="text"
name="actualTax"
value={formData.actualTax}
onChange={handleInputChange}
required
/>
</div>
<div className="form-group">
<label>Address:</label>
<input
type="text"
name="address"
value={formData.address}
onChange={handleInputChange}
required
/>
</div>
<div className="form-group">
<label>CEO:</label>
<input
type="text"
name="ceo"
value={formData.ceo}
onChange={handleInputChange}
required
/>
</div>
<button type="submit">Add Company</button>
</form>
</div>
</div>
);
}
export default App;
/* App.css */
.app {
padding: 20px;
max-width: 1200px;
margin: 0 auto;
}
.table-container {
overflow-x: auto;
margin-bottom: 30px;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}
th {
background-color: #f4f4f4;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
.form-container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
background-color: #007bff;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
This React app includes:
- A table displaying the company data
- A form to add new companies
- State management using useState
- Basic styling with CSS
- Form validation (required fields)
- Responsive design
To use this app, you would need to:
- Create a new React project using Create React App
- Replace the default App.jsx content with the provided code
- Create the App.css file with the provided styles
- Add the remaining companies from the initial table to the initialCompanies array
Features you might want to add:
- Data persistence (localStorage or backend database)
- Edit/delete functionality
- Sorting and filtering
- Input validation for specific formats (e.g., currency)
- Pagination for large datasets
- Search functionality
Would you like me to implement any of these additional features?