Skip to content

Commit

Permalink
placeholder when empty data
Browse files Browse the repository at this point in the history
  • Loading branch information
edmdz committed Aug 6, 2024
1 parent 0a60acc commit 5b3f916
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
17 changes: 14 additions & 3 deletions src/components/ItemCardList.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import Grid from '@mui/material/Grid';
import {ItemCard} from './ItemCard'; // Assuming ItemCard is in the same directory
import { ItemCard } from './ItemCard';
import { Typography, Box } from '@mui/material';

const ItemsCardList = ({ rows, columns, itemCardProps }) => {
if (rows.length === 0) {
return (
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '200px' }}>
<Typography variant="h6" color="text.secondary">
No hay elementos disponibles en este momento.
</Typography>
</Box>
);
}

const ItemsCardList = ({ rows, columns, itemCardProps}) => {
return (
<Grid container spacing={2}>
{rows.map((row) => (
Expand All @@ -13,4 +24,4 @@ const ItemsCardList = ({ rows, columns, itemCardProps}) => {
);
};

export default ItemsCardList;
export default ItemsCardList;
3 changes: 2 additions & 1 deletion src/pages/Products/ModelViewer/CarModelContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const CarModelListContainer = () => {
setLoading(false); // Set loading to false after fetching data
} catch (error) {
setLoading(false); // Set loading to false in case of error
openSnackbar(`Error al obtener los modelos de vehículos: ${error.errorMessage}`, 'error');
const severity = error.statusCode >= 400 && error.statusCode < 500 ? 'warning' : 'error';
openSnackbar(`Error al obtener los modelos de vehículos: ${error.errorMessage}`, severity);
}
};

Expand Down
23 changes: 10 additions & 13 deletions src/pages/Products/ProductViewer/ProductContainer.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect, useState } from 'react';
import { getImageURLFromStorage } from '../../../services/Firebase/storage';
import { CSSTransition } from 'react-transition-group'; // Importa CSSTransition
import '../../../styles/brandContainer.css';
import { useSnackbar } from '../../../components/SnackbarContext';
import { getAllCarModelsProducts, getCarModelProducts } from '../../../services/CarModelService';
Expand All @@ -9,11 +8,12 @@ import { Screens } from '../ProductsConstants';
import ProductList from './ProductList';
import { ProductCarModel } from '../../../models/ProductCarModel';
import { deleteProduct } from '../../../services/ProductService';
import { Box, CircularProgress } from '@mui/material';

const ProductContainer = () => {
const [productCarModels, setProductCarModels] = useState([]);
const { openSnackbar } = useSnackbar();
const { handleItemSelect, searchTerm, setLoading, selectedCarModel, productType } = useProductsContext();
const { handleItemSelect, searchTerm, setLoading, selectedCarModel, productType, loading } = useProductsContext();

const handleProductSelect = (e, item) => {
const productCarModel = productCarModels.find(productCarModel => productCarModel.product.id === item.id);
Expand All @@ -22,7 +22,6 @@ const ProductContainer = () => {

const handleOnDelete = async (productCarModel) => {
try {
console.log(productCarModel)
let result = await deleteProduct(productCarModel.id);
if (result) {
const products = productCarModels.filter(pcm => pcm.product.id !== productCarModel.id);
Expand Down Expand Up @@ -81,18 +80,16 @@ const ProductContainer = () => {
fetchProducts();
}, [searchTerm, setLoading]);

if (loading) {
return (
<Box display="flex" justifyContent="center" alignItems="center" minHeight="200px">
<CircularProgress size={40} />
</Box>
);
}

return (
<CSSTransition
in={productCarModels.length > 0} // Establece la condición para mostrar la animación
timeout={300}
classNames="fade"
unmountOnExit
>
<div>
<ProductList products={productCarModels} onProductSelect={handleProductSelect} handleOnDelete={handleOnDelete} />
</div>
</CSSTransition>
<ProductList products={productCarModels} onProductSelect={handleProductSelect} handleOnDelete={handleOnDelete} />
);
};

Expand Down

0 comments on commit 5b3f916

Please sign in to comment.