fullstackbench-tasks / screenshot2-add-expense-sparse /environment /app /frontend /src /components /Dashboard.jsx
Download screenshot2-add-expense-sparse/environment/app/frontend/src/components/Dashboard.jsx from ApolloTeam/fullstackbench-tasks: direct link, hf CLI and curl.
- Browser
- Download file 5.1 kB
-
https://huggingface.co/datasets/ApolloTeam/fullstackbench-tasks/resolve/main/screenshot2-add-expense-sparse/environment/app/frontend/src/components/Dashboard.jsx
- Command line
-
hf download hf://datasets/ApolloTeam/fullstackbench-tasks/screenshot2-add-expense-sparse/environment/app/frontend/src/components/Dashboard.jsx
-
curl -L -o Dashboard.jsx https://huggingface.co/datasets/ApolloTeam/fullstackbench-tasks/resolve/main/screenshot2-add-expense-sparse/environment/app/frontend/src/components/Dashboard.jsx
5.1 kB
| import { useState, useEffect } from 'react'; | |
| import { Link } from 'react-router-dom'; | |
| import { getUsers, createUser, getGroups } from '../api'; | |
| export default function Dashboard() { | |
| const [users, setUsers] = useState([]); | |
| const [groups, setGroups] = useState([]); | |
| const [name, setName] = useState(''); | |
| const [email, setEmail] = useState(''); | |
| const [error, setError] = useState(''); | |
| const [loading, setLoading] = useState(true); | |
| useEffect(() => { | |
| loadData(); | |
| }, []); | |
| async function loadData() { | |
| try { | |
| const [u, g] = await Promise.all([getUsers(), getGroups()]); | |
| setUsers(u); | |
| setGroups(g); | |
| } catch (e) { | |
| setError(e.message); | |
| } finally { | |
| setLoading(false); | |
| } | |
| } | |
| async function handleAddUser(e) { | |
| e.preventDefault(); | |
| setError(''); | |
| if (!name.trim() || !email.trim()) return; | |
| try { | |
| const user = await createUser(name.trim(), email.trim()); | |
| setUsers((prev) => [...prev, user]); | |
| setName(''); | |
| setEmail(''); | |
| } catch (e) { | |
| setError(e.message); | |
| } | |
| } | |
| if (loading) return <div className="loading">Loading...</div>; | |
| return ( | |
| <div> | |
| <div | |
| style={{ | |
| display: 'flex', | |
| alignItems: 'center', | |
| justifyContent: 'space-between', | |
| marginBottom: 24, | |
| }} | |
| > | |
| <h1 style={{ fontSize: 28, fontWeight: 700 }}>Dashboard</h1> | |
| <Link to="/create-group" className="btn btn-primary"> | |
| + New Group | |
| </Link> | |
| </div> | |
| {error && <div className="error-msg">{error}</div>} | |
| <div className="dashboard-grid"> | |
| <div> | |
| <div className="section-title">Groups</div> | |
| {groups.length === 0 ? ( | |
| <div className="card"> | |
| <div className="empty-state"> | |
| <div className="empty-state-icon">G</div> | |
| <p>No groups yet. Create one to get started!</p> | |
| </div> | |
| </div> | |
| ) : ( | |
| <div className="groups-list"> | |
| {groups.map((g) => ( | |
| <Link | |
| key={g.id} | |
| to={`/groups/${g.id}`} | |
| className="group-card" | |
| > | |
| <div className="group-card-icon"> | |
| {g.name.charAt(0).toUpperCase()} | |
| </div> | |
| <div className="group-card-info"> | |
| <div className="group-card-name">{g.name}</div> | |
| <div className="group-card-members"> | |
| {g.members | |
| ? `${g.members.length} member${g.members.length !== 1 ? 's' : ''}` | |
| : ''} | |
| </div> | |
| </div> | |
| <div className="group-card-arrow">›</div> | |
| </Link> | |
| ))} | |
| </div> | |
| )} | |
| </div> | |
| <div className="sidebar"> | |
| <div className="card"> | |
| <div className="card-header"> | |
| <h2>Add User</h2> | |
| </div> | |
| <div className="card-body"> | |
| <form onSubmit={handleAddUser}> | |
| <div className="form-group"> | |
| <label>Name</label> | |
| <input | |
| className="form-input" | |
| type="text" | |
| placeholder="John Doe" | |
| value={name} | |
| onChange={(e) => setName(e.target.value)} | |
| required | |
| /> | |
| </div> | |
| <div className="form-group"> | |
| <label>Email</label> | |
| <input | |
| className="form-input" | |
| type="email" | |
| placeholder="john@example.com" | |
| value={email} | |
| onChange={(e) => setEmail(e.target.value)} | |
| required | |
| /> | |
| </div> | |
| <button className="btn btn-primary" style={{ width: '100%' }}> | |
| Add User | |
| </button> | |
| </form> | |
| </div> | |
| </div> | |
| <div className="card"> | |
| <div className="card-header"> | |
| <h2>Users ({users.length})</h2> | |
| </div> | |
| <div className="card-body"> | |
| {users.length === 0 ? ( | |
| <p style={{ color: 'var(--text-light)', fontSize: 14 }}> | |
| No users yet. | |
| </p> | |
| ) : ( | |
| <ul className="user-list"> | |
| {users.map((u) => ( | |
| <li key={u.id}> | |
| <div className="user-avatar"> | |
| {u.name.charAt(0).toUpperCase()} | |
| </div> | |
| <div> | |
| <div className="user-info-name">{u.name}</div> | |
| <div className="user-info-email">{u.email}</div> | |
| </div> | |
| </li> | |
| ))} | |
| </ul> | |
| )} | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |