feat: improve the gridview presentation

This commit is contained in:
Rodolfo Ruiz
2025-06-09 22:31:06 -06:00
parent c667d7e606
commit a79f27dc3d
5 changed files with 94 additions and 55 deletions

View File

@@ -18,6 +18,7 @@ a {
color: #646cff; color: #646cff;
text-decoration: inherit; text-decoration: inherit;
} }
a:hover { a:hover {
color: #535bf2; color: #535bf2;
} }
@@ -50,9 +51,11 @@ button {
cursor: pointer; cursor: pointer;
transition: border-color 0.25s; transition: border-color 0.25s;
} }
button:hover { button:hover {
border-color: #646cff; border-color: #646cff;
} }
button:focus, button:focus,
button:focus-visible { button:focus-visible {
outline: 4px auto -webkit-focus-ring-color; outline: 4px auto -webkit-focus-ring-color;
@@ -63,9 +66,11 @@ button:focus-visible {
color: #213547; color: #213547;
background-color: #ffffff; background-color: #ffffff;
} }
a:hover { a:hover {
color: #747bff; color: #747bff;
} }
button { button {
background-color: #f9f9f9; background-color: #f9f9f9;
} }

View File

@@ -2,43 +2,44 @@
import SectionContainer from '../components/SectionContainer'; import SectionContainer from '../components/SectionContainer';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { DataGrid } from '@mui/x-data-grid'; import { DataGrid } from '@mui/x-data-grid';
import { Typography, Button, Dialog, DialogTitle, DialogContent, IconButton, Box, Avatar } from '@mui/material'; import { Grid, Card, CardMedia, CardContent, Typography, Button, Dialog, DialogTitle, DialogContent, IconButton, Box, Avatar } from '@mui/material';
import AddOrEditProductForm from './AddOrEditProductForm.jsx'; import AddOrEditProductForm from './AddOrEditProductForm.jsx';
import EditIcon from '@mui/icons-material/Edit'; import EditIcon from '@mui/icons-material/Edit';
import DeleteIcon from '@mui/icons-material/Delete'; import DeleteIcon from '@mui/icons-material/Delete';
import EditRoundedIcon from '@mui/icons-material/EditRounded';
import DeleteRoundedIcon from '@mui/icons-material/DeleteRounded';
import '../App.css'; import '../App.css';
import { Visibility } from '@mui/icons-material';
const columnsBase = [ const columnsBase = [
{ field: 'id', headerName: 'ID', width: 70, hide: false },
{ field: 'company', headerName: 'Company', flex: 1 },
{ field: 'name', headerName: 'Name', flex: 1 },
{ field: 'price', headerName: '$', width: 120, type: 'number' },
{ field: 'provider', headerName: 'Provider', flex: 1 },
{ field: 'stock', headerName: 'Stock', width: 120, type: 'number' },
{ field: 'category', headerName: 'Category', flex: 1 },
{ {
field: 'representation', field: 'representation',
headerName: 'Representation', headerName: 'Representation',
width: 200, flex: 2,
renderCell: (params) => ( renderCell: (params) => {
<Box display="flex" justifyContent="center" width="100%"> const { representation, name, provider, price } = params.row;
<Avatar return (
variant="rounded" <Box display="flex" alignItems="center" gap={2}>
src={params.value} <Box
sx={{ width: 180, height: 48 }} component="img"
imgProps={{ src={representation || '/favicon.png'}
style: { alt={name}
objectFit: 'contain', // or 'cover' if you want it to fill and crop sx={{ width: 140, height: 140, borderRadius: 1, objectFit: 'cover' }}
width: '100%',
height: '100%',
}
}}
/> />
<Box>
<Typography fontWeight={700}>{name}</Typography>
<Typography variant="body2" color="text.secondary">{provider}</Typography>
<Typography variant="h6" color="text.secondary">${Number(price).toFixed(2)}</Typography>
</Box> </Box>
) </Box>
);
} }
},
{ field: 'company', headerName: 'Company', flex: 1 },
{ field: 'name', headerName: 'Name', flex: 1 },
{ field: 'stock', headerName: 'Stock', width: 120, type: 'number' },
{ field: 'category', headerName: 'Category', flex: 1 },
]; ];
export default function Admin({ children, maxWidth = 'lg', sx = {} }) { export default function Admin({ children, maxWidth = 'lg', sx = {} }) {
@@ -88,15 +89,43 @@ export default function Admin({ children, maxWidth = 'lg', sx = {} }) {
...columnsBase, ...columnsBase,
{ {
field: 'actions', field: 'actions',
headerName: 'Actions', headerName: '',
width: 130, width: 130,
renderCell: (params) => ( renderCell: (params) => (
<Box> <Box display="flex"
<IconButton color="primary" onClick={() => handleEditClick(params)}> alignItems="center"
<EditIcon /> justifyContent="flex-start"
height="100%"
gap={2}>
<IconButton
size="small"
sx={{
backgroundColor: '#DFCCBC',
color: '#26201A',
'&:hover': {
backgroundColor: '#C2B2A4',
},
borderRadius: 2,
p: 1,
}}
onClick={() => handleEditClick(params)}
>
<EditRoundedIcon fontSize="small" />
</IconButton> </IconButton>
<IconButton color="error" onClick={() => handleDeleteClick(params.row)}> <IconButton
<DeleteIcon /> size="small"
sx={{
backgroundColor: '#FBE9E7',
color: '#C62828',
'&:hover': {
backgroundColor: '#EF9A9A',
},
borderRadius: 2,
p: 1,
}}
onClick={() => handleDeleteClick(params.row)}
>
<DeleteRoundedIcon fontSize="small" />
</IconButton> </IconButton>
</Box> </Box>
) )
@@ -132,10 +161,15 @@ export default function Admin({ children, maxWidth = 'lg', sx = {} }) {
<Box mt={2}> <Box mt={2}>
<DataGrid <DataGrid
getRowHeight={() => 140}
rows={rows} rows={rows}
columns={columns} columns={columns}
pageSize={5} pageSize={5}
rowsPerPageOptions={[5]} rowsPerPageOptions={[5]}
getRowSpacing={() => ({
top: 8,
bottom: 8,
})}
/> />
<Box display="flex" justifyContent="flex-end" mt={2}> <Box display="flex" justifyContent="flex-end" mt={2}>