aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common/components/ErrorHandler.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/common/components/ErrorHandler.jsx')
-rw-r--r--modern/src/common/components/ErrorHandler.jsx27
1 files changed, 27 insertions, 0 deletions
diff --git a/modern/src/common/components/ErrorHandler.jsx b/modern/src/common/components/ErrorHandler.jsx
new file mode 100644
index 00000000..5c9c26d9
--- /dev/null
+++ b/modern/src/common/components/ErrorHandler.jsx
@@ -0,0 +1,27 @@
+import { Snackbar, Alert } from '@mui/material';
+import React from 'react';
+import { useDispatch, useSelector } from 'react-redux';
+import { usePrevious } from '../../reactHelper';
+import { errorsActions } from '../../store';
+
+const ErrorHandler = () => {
+ const dispatch = useDispatch();
+
+ const error = useSelector((state) => state.errors.errors.find(() => true));
+ const previousError = usePrevious(error);
+
+ return (
+ <Snackbar open={!!error}>
+ <Alert
+ elevation={6}
+ onClose={() => dispatch(errorsActions.pop())}
+ severity="error"
+ variant="filled"
+ >
+ {error || previousError}
+ </Alert>
+ </Snackbar>
+ );
+};
+
+export default ErrorHandler;