Skip to content

Commit

Permalink
error handling message was added in the oficial_products. will displa…
Browse files Browse the repository at this point in the history
…y an error message if problems occur while loading or processing the products.
  • Loading branch information
jandsonrj committed Dec 13, 2023
1 parent 22155f1 commit 524602d
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions frontend/pages/oficial_products.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import Breadcrumbs from '@mui/material/Breadcrumbs'
import FormControl from '@mui/material/FormControl'
import Grid from '@mui/material/Grid'
import Typography from '@mui/material/Typography'
import Snackbar from '@mui/material/Snackbar'
import Alert from '@mui/material/Alert'

import { useRouter } from 'next/router'
import { parseCookies } from 'nookies'
Expand All @@ -36,6 +38,18 @@ export default function Products() {
status: 1 // Published
})

const [errorSnackbar, setErrorSnackbar] = React.useState({
open: false,
message: ''
})

const handleOpenErrorSnackbar = message => {
setErrorSnackbar({
open: true,
message
})
}

return (
// Baseado neste template: https://mira.bootlab.io/dashboard/analytics
<Paper className={classes.root} elevation={3}>
Expand Down Expand Up @@ -84,7 +98,7 @@ export default function Products() {
<Button
variant="contained"
color="primary"
onClick={e => {
onClick={() => {
router.push('/product/new')
}}
>
Expand Down Expand Up @@ -130,11 +144,33 @@ export default function Products() {
</Box>
</Grid>
<Grid item xs={12}>
<ProductGrid query={search} filters={filters} />
<ProductGrid
query={search}
filters={filters}
onError={error => {
console.error('Error loading products:', error)
handleOpenErrorSnackbar(
'Error loading products. Please try again.'
)
}}
/>
</Grid>
</Grid>
</CardContent>
</Card>
<Snackbar
open={errorSnackbar.open}
autoHideDuration={6000}
onClose={() => setErrorSnackbar({ ...errorSnackbar, open: false })}
>
<Alert
onClose={() => setErrorSnackbar({ ...errorSnackbar, open: false })}
severity="error"
sx={{ width: '100%' }}
>
{errorSnackbar.message}
</Alert>
</Snackbar>
</Paper>
)
}
Expand Down

0 comments on commit 524602d

Please sign in to comment.