As an AI text-based model, I'm unable to directly create a React app for you, but I can provide a rough outline for building a simple employee time tracking app using React.
- Create a new React app using
create-react-app command:
npx create-react-app employee-time-tracking-app
cd employee-time-tracking-app
- Open the
src/App.js file and replace the content with the following:
import React, { useState } from 'react';
import './App.css';
function App() {
const [employees, setEmployees] = useState([]);
const [formData, setFormData] = useState({
name: '',
startTime: '',
endTime: '',
});
const handleInputChange = (event) => {
const { name, value } = event.target;
setFormData({ ...formData, [name]: value });
};
const handleSubmit = (event) => {
event.preventDefault();
const newEmployee = {
name: formData.name,
startTime: formData.startTime,
endTime: formData.endTime,
};
setEmployees([...employees, newEmployee]);
setFormData({ name: '', startTime: '', endTime: '' });
};
return (
<div className="App">
<h1>Employee Time Tracking</h1>
<form onSubmit={handleSubmit}>
<label>
Employee Name:
<input
type="text"
name="name"
value={formData.name}
onChange={handleInputChange}
required
/>
</label>
<label>
Start Time:
<input
type="time"
name="startTime"
value={formData.startTime}
onChange={handleInputChange}
required
/>
</label>
<label>
End Time:
<input
type="time"
name="endTime"
value={formData.endTime}
onChange={handleInputChange}
required
/>
</label>
<button type="submit">Add Employee</button>
</form>
<h2>Employee Records</h2>
<ul>
{employees.map((employee, index) => (
<li key={index}>
{employee.name} worked from {employee.startTime} to {employee.endTime}
</li>
))}
</ul>
</div>
);
}
export default App;
- This example is very basic, and you'll likely want to expand and improve it. To get started, you might consider:
- Adding validation for the input fields to ensure only valid times are entered
- Implementing a search or filter functionality to easily locate a specific employee's records
- Including functionality to edit or delete employee records
- Implementing a backend to store the data persistently
Remember, this is just an outline. There's a lot more you can do with a React app, and it's up to you to customize and expand it as needed for your specific use case.