|
| 1 | +import { useSelector } from 'react-redux' |
| 2 | +import DeleteIcon from '@material-ui/icons/Delete' |
| 3 | +import EditIcon from '@material-ui/icons/Edit' |
| 4 | +import IconButton from '@material-ui/core/IconButton' |
| 5 | +import Table from '@material-ui/core/Table' |
| 6 | +import TableBody from '@material-ui/core/TableBody' |
| 7 | +import TableCell from '@material-ui/core/TableCell' |
| 8 | +import TableContainer from '@material-ui/core/TableContainer' |
| 9 | +import TableHead from '@material-ui/core/TableHead' |
| 10 | +import TableRow from '@material-ui/core/TableRow' |
| 11 | +import Paper from '@material-ui/core/Paper' |
| 12 | +import AddIcon from '@material-ui/icons/Add' |
| 13 | +import numberFormat from '../../utils/numberFormat' |
| 14 | +import { RootState } from '../../store' |
| 15 | +import { useNavigate } from 'react-router-dom' |
| 16 | +import { Fab, makeStyles } from '@material-ui/core' |
| 17 | + |
| 18 | +const useStyles = makeStyles((theme) => ({ |
| 19 | + heroContent: { |
| 20 | + padding: theme.spacing(8, 0, 6), |
| 21 | + }, |
| 22 | + fab: { |
| 23 | + position: 'absolute', |
| 24 | + bottom: theme.spacing(2), |
| 25 | + right: theme.spacing(2), |
| 26 | + }, |
| 27 | +})) |
| 28 | + |
| 29 | + |
| 30 | +export const ItemsList = () => { |
| 31 | + const items = useSelector((state: RootState) => state.rules.items) |
| 32 | + const classes = useStyles() |
| 33 | + const navigate = useNavigate() |
| 34 | + |
| 35 | + return ( |
| 36 | + <> |
| 37 | + <TableContainer component={Paper}> |
| 38 | + <Table aria-label="simple table"> |
| 39 | + <TableHead> |
| 40 | + <TableRow> |
| 41 | + <TableCell>Name</TableCell> |
| 42 | + <TableCell align="right">Price</TableCell> |
| 43 | + <TableCell align="right">Lines per seconds</TableCell> |
| 44 | + <TableCell align="right">Action</TableCell> |
| 45 | + </TableRow> |
| 46 | + </TableHead> |
| 47 | + <TableBody> |
| 48 | + {items.map((item) => ( |
| 49 | + <TableRow key={item.id}> |
| 50 | + <TableCell component="th" scope="row">{item.name}</TableCell> |
| 51 | + <TableCell align="right">{numberFormat(item.price)}</TableCell> |
| 52 | + <TableCell align="right">{numberFormat(item.linesPerMillisecond * 10)}</TableCell> |
| 53 | + <TableCell align="right"> |
| 54 | + <IconButton |
| 55 | + onClick={() => navigate(`/rules/edit/${item.id}`)} |
| 56 | + aria-label="edit" |
| 57 | + > |
| 58 | + <EditIcon /> |
| 59 | + </IconButton> |
| 60 | + <IconButton |
| 61 | + color="secondary" |
| 62 | + aria-label="delete" |
| 63 | + > |
| 64 | + <DeleteIcon /> |
| 65 | + </IconButton> |
| 66 | + </TableCell> |
| 67 | + </TableRow> |
| 68 | + ))} |
| 69 | + </TableBody> |
| 70 | + </Table> |
| 71 | + </TableContainer> |
| 72 | + <Fab |
| 73 | + onClick={() => navigate('/rules/add')} |
| 74 | + className={classes.fab} |
| 75 | + color="primary" |
| 76 | + aria-label="add" |
| 77 | + > |
| 78 | + <AddIcon /> |
| 79 | + </Fab> |
| 80 | + </> |
| 81 | + ) |
| 82 | +} |
0 commit comments