Skip to content

Commit

Permalink
Merge pull request #73 from deco-finter/fix/close-snackbar
Browse files Browse the repository at this point in the history
Fix snackbars not closable manually
  • Loading branch information
daystram committed Oct 21, 2021
2 parents a0776ff + 6fde3ef commit 5714e46
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions fableous-fe/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from "react";
import { Container } from "@material-ui/core";
import React, { useRef } from "react";
import { Container, IconButton } from "@material-ui/core";
import {
createTheme,
makeStyles,
ThemeProvider,
} from "@material-ui/core/styles";
import CloseIcon from "@material-ui/icons/Close";
import { BrowserRouter as Router } from "react-router-dom";
import { SnackbarProvider } from "notistack";
import { SnackbarKey, SnackbarProvider } from "notistack";
import AuthProvider from "./components/AuthProvider";
import Navbar from "./components/Navbar";
import Routes from "./Routes";
Expand All @@ -28,6 +29,11 @@ const useStyles = makeStyles({
});

export default function App() {
const notistackRef = useRef<SnackbarProvider>(null);
const onSnackbarClose = (key: SnackbarKey) => () => {
notistackRef.current?.closeSnackbar(key);
};

const theme = createTheme({
palette: {
primary: {
Expand Down Expand Up @@ -137,13 +143,25 @@ export default function App() {
<div className="flex flex-col min-h-screen">
{/* place Snackbar outside of React.StrictMode to suppress finddomnode is deprecated warning */}
<SnackbarProvider
ref={notistackRef}
maxSnack={3}
classes={{
variantSuccess: classes.snackbarChildren,
variantInfo: classes.snackbarChildren,
variantWarning: classes.snackbarChildren,
variantError: classes.snackbarChildren,
}}
action={(key) => (
<IconButton
onClick={onSnackbarClose(key)}
size="small"
style={{
marginRight: "4px",
}}
>
<CloseIcon fontSize="small" className="text-white" />
</IconButton>
)}
>
<React.StrictMode>
<AuthProvider>
Expand Down

0 comments on commit 5714e46

Please sign in to comment.