import { useState } from ‘react’; import { Button } from “/components/ui/button”; import { Input } from “/components/ui/input”; import { Label } from “/components/ui/label”; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from “/components/ui/select”; import { Textarea } from “/components/ui/textarea”; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from “/components/ui/card”; interface Project { id: number; name: string; description: string; hours: { [key: string]: number }; } interface User { id: number; name: string; } const App = () => { const [projects, setProjects] = useState<Project[]>([]); const [users, setUsers] = useState<User[]>([]); const [selectedProject, setSelectedProject] = useState(null); const [selectedUser, setSelectedUser] = useState(null); const [newProjectName, setNewProjectName] = useState(”); const [newProjectDescription, setNewProjectDescription] = useState(”); const [newUserName, setNewUserName] = useState(”); const [hours, setHours] = useState(0); const addProject = () => { const newProject: Project = { id: projects.length + 1, name: newProjectName, description: newProjectDescription, hours: {}, }; setProjects([…projects, newProject]); setNewProjectName(”); setNewProjectDescription(”); }; const removeProject = (id: number) => { setProjects(projects.filter((project) => project.id !== id)); }; const modifyProject = (id: number, name: string, description: string) => { setProjects( projects.map((project) => { if (project.id === id) { return { …project, name, description }; } return project; }) ); }; const addUser = () => { const newUser: User = { id: users.length + 1, name: newUserName, }; setUsers([…users, newUser]); setNewUserName(”); }; const removeUser = (id: number) => { setUsers(users.filter((user) => user.id !== id)); }; const modifyUser = (id: number, name: string) => { setUsers( users.map((user) => { if (user.id === id) { return { …user, name }; } return user; }) ); }; const addHours = () => { if (selectedProject && selectedUser) { const newHours = { …selectedProject.hours }; newHours[selectedUser.name] = (newHours[selectedUser.name] || 0) + hours; modifyProject(selectedProject.id, selectedProject.name, selectedProject.description); setProjects( projects.map((project) => { if (project.id === selectedProject.id) { return { …project, hours: newHours }; } return project; }) ); } }; const generateReport = () => { if (selectedProject) { const report = Object.keys(selectedProject.hours).map((user) => ({ user, hours: selectedProject.hours[user], })); return report; } return []; }; return (
- {projects.map((project) => (
- {project.name} ))}