diff --git a/package-lock.json b/package-lock.json
index 8b6e44b..86ecc0b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -21,6 +21,7 @@
"formik": "^2.2.8",
"formik-material-ui": "^3.0.1",
"material-ui-dropzone": "^3.5.0",
+ "notistack": "^1.0.9",
"opener": "^1.5.2",
"qrcode.react": "^1.0.1",
"react": "^17.0.2",
@@ -12991,6 +12992,24 @@
"node": ">=4"
}
},
+ "node_modules/notistack": {
+ "version": "1.0.9",
+ "resolved": "https://registry.npmjs.org/notistack/-/notistack-1.0.9.tgz",
+ "integrity": "sha512-Dal2HtTpWrdYCZ3t0HhJt47NJZwVSPee36WzORRbqUkFR0k9pxFszxBuPSWshBLwF6Av8s86XPP+ED5zRz0CGw==",
+ "dependencies": {
+ "clsx": "^1.1.0",
+ "hoist-non-react-statics": "^3.3.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/notistack"
+ },
+ "peerDependencies": {
+ "@material-ui/core": "^4.0.0",
+ "react": "^16.8.0 || ^17.0.0",
+ "react-dom": "^16.8.0 || ^17.0.0"
+ }
+ },
"node_modules/npm-run-path": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz",
@@ -32672,6 +32691,15 @@
"sort-keys": "^1.0.0"
}
},
+ "notistack": {
+ "version": "1.0.9",
+ "resolved": "https://registry.npmjs.org/notistack/-/notistack-1.0.9.tgz",
+ "integrity": "sha512-Dal2HtTpWrdYCZ3t0HhJt47NJZwVSPee36WzORRbqUkFR0k9pxFszxBuPSWshBLwF6Av8s86XPP+ED5zRz0CGw==",
+ "requires": {
+ "clsx": "^1.1.0",
+ "hoist-non-react-statics": "^3.3.0"
+ }
+ },
"npm-run-path": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz",
diff --git a/package.json b/package.json
index 6d72d3c..a8aa331 100644
--- a/package.json
+++ b/package.json
@@ -36,6 +36,7 @@
"formik": "^2.2.8",
"formik-material-ui": "^3.0.1",
"material-ui-dropzone": "^3.5.0",
+ "notistack": "^1.0.9",
"opener": "^1.5.2",
"qrcode.react": "^1.0.1",
"react": "^17.0.2",
diff --git a/src/App.tsx b/src/App.tsx
index a047f2c..1f7fe87 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -4,6 +4,7 @@ import './App.css'
import { ThemeProvider } from '@material-ui/styles'
import CssBaseline from '@material-ui/core/CssBaseline'
+import { SnackbarProvider } from 'notistack'
import BaseRouter from './routes/routes'
import { lightTheme, darkTheme } from './theme'
@@ -35,12 +36,14 @@ const App = (): ReactElement => {
- <>
-
-
-
-
- >
+
+ <>
+
+
+
+
+ >
+
diff --git a/src/components/CashoutModal.tsx b/src/components/CashoutModal.tsx
index f355a6c..1e6d160 100644
--- a/src/components/CashoutModal.tsx
+++ b/src/components/CashoutModal.tsx
@@ -5,7 +5,8 @@ import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent'
import DialogContentText from '@material-ui/core/DialogContentText'
import DialogTitle from '@material-ui/core/DialogTitle'
-import { Snackbar, Container, CircularProgress } from '@material-ui/core'
+import { Container, CircularProgress } from '@material-ui/core'
+import { useSnackbar } from 'notistack'
import { beeDebugApi } from '../services/bee'
@@ -19,8 +20,7 @@ interface Props {
export default function DepositModal({ peerId, uncashedAmount }: Props): ReactElement {
const [open, setOpen] = useState(false)
const [loadingCashout, setLoadingCashout] = useState(false)
- const [showToast, setToastVisibility] = useState(false)
- const [toastContent, setToastContent] = useState(null)
+ const { enqueueSnackbar } = useSnackbar()
const handleClickOpen = () => {
setOpen(true)
@@ -37,37 +37,30 @@ export default function DepositModal({ peerId, uncashedAmount }: Props): ReactEl
.peerCashout(peerId)
.then(res => {
setOpen(false)
- handleToast(
+ enqueueSnackbar(
Successfully cashed out cheque. Transaction
,
+ { variant: 'success' },
)
})
- .catch(() => {
- // FIXME: handle errors more gracefully
- handleToast(Error with cashout)
+ .catch((e: Error) => {
+ enqueueSnackbar(Error: {e.message}, { variant: 'error' })
})
.finally(() => {
setLoadingCashout(false)
})
} else {
- handleToast(Peer Id invalid)
+ enqueueSnackbar(Peer Id invalid, { variant: 'error' })
}
}
- const handleToast = (text: JSX.Element) => {
- setToastContent(text)
- setToastVisibility(true)
- setTimeout(() => setToastVisibility(false), 7000)
- }
-
return (
-
diff --git a/src/pages/stamps/CreatePostageStampModal.tsx b/src/pages/stamps/CreatePostageStampModal.tsx
index 77ddc52..6a9084f 100644
--- a/src/pages/stamps/CreatePostageStampModal.tsx
+++ b/src/pages/stamps/CreatePostageStampModal.tsx
@@ -12,6 +12,7 @@ import { TextField } from 'formik-material-ui'
import { beeApi } from '../../services/bee'
import { Context } from '../../providers/Stamps'
import { makeStyles, Theme, createStyles } from '@material-ui/core/styles'
+import { useSnackbar } from 'notistack'
interface FormValues {
depth?: string
@@ -55,6 +56,7 @@ export default function FormDialog({ label }: Props): ReactElement {
const { refresh } = useContext(Context)
const handleClickOpen = () => setOpen(true)
const handleClose = () => setOpen(false)
+ const { enqueueSnackbar } = useSnackbar()
return (