chore: improve toast and show once
This commit is contained in:
		| @@ -5,7 +5,7 @@ export default function useApiToast() { | |||||||
|  |  | ||||||
|     const handleError = (error, defaultMessage = 'API error') => { |     const handleError = (error, defaultMessage = 'API error') => { | ||||||
|         console.error(error); |         console.error(error); | ||||||
|         enqueueSnackbar(error.message || defaultMessage, { variant: 'error' }); |         enqueueSnackbar(defaultMessage, { variant: 'error' }); | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     return { handleError }; |     return { handleError }; | ||||||
|   | |||||||
| @@ -9,12 +9,7 @@ import App from './App.jsx' | |||||||
| createRoot(document.getElementById('root')).render( | createRoot(document.getElementById('root')).render( | ||||||
|   <StrictMode> |   <StrictMode> | ||||||
|     <ThemeProvider theme={theme}> |     <ThemeProvider theme={theme}> | ||||||
|       <SnackbarProvider maxSnack={3} |       <SnackbarProvider maxSnack={3} autoHideDuration={3000}> | ||||||
|         autoHideDuration={5000} |  | ||||||
|         anchorOrigin={{ |  | ||||||
|           vertical: 'top', |  | ||||||
|           horizontal: 'right', |  | ||||||
|         }}> |  | ||||||
|         <App /> |         <App /> | ||||||
|       </SnackbarProvider> |       </SnackbarProvider> | ||||||
|     </ThemeProvider> |     </ThemeProvider> | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| import SectionContainer from '../../components/SectionContainer'; | import SectionContainer from '../../components/SectionContainer'; | ||||||
| import { useEffect, useState } from 'react'; | import { useEffect, useState, useRef } from 'react'; | ||||||
| import { DataGrid } from '@mui/x-data-grid'; | import { DataGrid } from '@mui/x-data-grid'; | ||||||
| import { Typography, Button, Dialog, DialogTitle, DialogContent, IconButton, Box } from '@mui/material'; | import { Typography, Button, Dialog, DialogTitle, DialogContent, IconButton, Box } from '@mui/material'; | ||||||
| import EditRoundedIcon from '@mui/icons-material/EditRounded'; | import EditRoundedIcon from '@mui/icons-material/EditRounded'; | ||||||
| @@ -42,10 +42,13 @@ export default function Admin() { | |||||||
|     const [rowToDelete, setRowToDelete] = useState(null); |     const [rowToDelete, setRowToDelete] = useState(null); | ||||||
|     const { handleError } = useApiToast(); |     const { handleError } = useApiToast(); | ||||||
|  |  | ||||||
|  | const hasLoaded = useRef(false); | ||||||
|  |  | ||||||
| useEffect(() => { | useEffect(() => { | ||||||
|         let isMounted = true; |   if (!hasLoaded.current) { | ||||||
|     loadData(); |     loadData(); | ||||||
|         return () => { isMounted = false }; |     hasLoaded.current = true; | ||||||
|  |   } | ||||||
| }, []); | }, []); | ||||||
|  |  | ||||||
|     const handleEditClick = (params) => { |     const handleEditClick = (params) => { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Rodolfo Ruiz
					Rodolfo Ruiz