Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users #30

Open
elicharlese opened this issue Feb 6, 2023 · 0 comments
Open

Users #30

elicharlese opened this issue Feb 6, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@elicharlese
Copy link
Member

elicharlese commented Feb 6, 2023

import React, { useState } from "react";
import {
  makeStyles,
  Table,
  TableBody,
  TableCell,
  TableContainer,
  TableHead,
  TableRow,
  Paper,
  TextField,
  Button,
} from "@material-ui/core";

const useStyles = makeStyles((theme) => ({
  table: {
    minWidth: 650,
  },
  input: {
    marginRight: theme.spacing(1),
  },
  button: {
    marginBottom: theme.spacing(1),
  },
}));

const initialData = [
  {
    id: 1,
    name: "John Doe",
    email: "[email protected]",
    role: "user",
  },
  {
    id: 2,
    name: "Jane Doe",
    email: "[email protected]",
    role: "admin",
  },
  {
    id: 3,
    name: "Bob Smith",
    email: "[email protected]",
    role: "user",
  },
];

export default function Users() {
  const classes = useStyles();
  const [users, setUsers] = useState(initialData);
  const [newUser, setNewUser] = useState({ name: "", email: "", role: "" });

  const handleAddUser = () => {
    const newUserWithId = {
      ...newUser,
      id: users.length + 1,
    };
    setUsers([...users, newUserWithId]);
    setNewUser({ name: "", email: "", role: "" });
  };

  const handleInputChange = (e) => {
    const { name, value } = e.target;
    setNewUser({ ...newUser, [name]: value });
  };

  return (
    <TableContainer component={Paper}>
      <Table className={classes.table} aria-label="users table">
        <TableHead>
          <TableRow>
            <TableCell>ID</TableCell>
            <TableCell>Name</TableCell>
            <TableCell>Email</TableCell>
            <TableCell>Role</TableCell>
          </TableRow>
        </TableHead>
        <TableBody>
          {users.map((user) => (
            <TableRow key={user.id}>
              <TableCell>{user.id}</TableCell>
              <TableCell>{user.name}</TableCell>
              <TableCell>{user.email}</TableCell>
              <TableCell>{user.role}</TableCell>
            </TableRow>
          ))}
          <TableRow>
            <TableCell></TableCell>
            <TableCell>
              <TextField
                className={classes.input}
                label="Name"
                variant="outlined"
                name="name"
                value={newUser.name}
                onChange={handleInputChange}
              />
            </TableCell>
            <TableCell>
              <TextField
                className={classes.input}
                label="Email"
                variant="outlined"
                name="email"
                value={newUser.email}
                onChange={handleInputChange}
              />
            </TableCell>
            <TableCell>
              <TextField
                className={classes.input}
                label="Role"
                variant="outlined"
                name="role"
                value={newUser.role}
                onChange={handleInputChange}
              />
              <Button
                variant="contained"
                color="primary"
                className={classes.button}
                onClick={handleAddUser}
              >
                Add
              </Button>
            </TableCell>
          </TableRow>
        </TableBody>
      </Table>
    </TableContainer>
  );
}

This component uses the Table and TableContainer components from Material-UI to display a list of users with their ID, name, email, and role. It also allows an admin to add new users to the list by entering their info.

@elicharlese elicharlese added the bug Something isn't working label Feb 6, 2023
@elicharlese elicharlese self-assigned this Feb 6, 2023
@elicharlese elicharlese added this to the Front-End base for all dapps in Framer milestone Feb 6, 2023
@elicharlese elicharlese removed this from the Front-End base for all dapps in Framer milestone Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant