summaryrefslogtreecommitdiff
path: root/client/src/components/GlobalSnackbar.tsx
diff options
context:
space:
mode:
authorMichael Hunteman <michael@huntm.net>2024-09-21 08:00:39 -0700
committerMichael Hunteman <michael@huntm.net>2024-09-21 11:39:18 -0700
commit2133253836de428e58b4ba1c9b7e863485b6b870 (patch)
tree9c175fd811975a21fcf60a5b14004443d32fe989 /client/src/components/GlobalSnackbar.tsx
parenta54a93b724a6104213b17271fc298e37adedc1c5 (diff)
Use snackbar globally
Diffstat (limited to 'client/src/components/GlobalSnackbar.tsx')
-rw-r--r--client/src/components/GlobalSnackbar.tsx25
1 files changed, 25 insertions, 0 deletions
diff --git a/client/src/components/GlobalSnackbar.tsx b/client/src/components/GlobalSnackbar.tsx
new file mode 100644
index 0000000..f0019fa
--- /dev/null
+++ b/client/src/components/GlobalSnackbar.tsx
@@ -0,0 +1,25 @@
+import React from 'react';
+import { useDispatch, useSelector } from 'react-redux';
+import { Alert, Snackbar } from '@mui/material';
+import { hideSnackbar, selectSnackbarState } from '../slices/snackbarSlice';
+
+function GlobalSnackbar() {
+ const dispatch = useDispatch();
+ const { open, message, severity } = useSelector(selectSnackbarState);
+
+ const handleClose = () => {
+ dispatch(hideSnackbar());
+ };
+
+ return (
+ <Snackbar open={open} onClose={handleClose} autoHideDuration={5000}>
+ <div>
+ <Alert severity={severity} onClose={handleClose}>
+ {message}
+ </Alert>
+ </div>
+ </Snackbar>
+ );
+}
+
+export default GlobalSnackbar;