Skip to content

Commit

Permalink
[FEAT]: created useToast component
Browse files Browse the repository at this point in the history
  • Loading branch information
Ananyamadhu08 committed Jul 30, 2022
1 parent 769fb81 commit d17e496
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
36 changes: 35 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"react-circular-progressbar": "^2.0.4",
"react-dom": "^18.1.0",
"react-moment": "^1.1.2",
"react-router-dom": "^6.3.0"
"react-router-dom": "^6.3.0",
"react-toastify": "^9.0.1"
}
}
20 changes: 17 additions & 3 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import React from "react";
import { Footer, Header } from "./components";
import { useTheme } from "./context";
import { useAuth, useTheme } from "./context";
import { ToastContainer } from "react-toastify";

import { WebsiteRoutes } from "./routes";

const App = () => {
const { theme } = useTheme();
const { authenticated } = useAuth();

return (
<div className={`${theme === "light" ? "bg-orange-200" : "bg-slate-900"}`}>
<Header />
<ToastContainer
theme={theme === "light" ? "light" : "dark"}
position="bottom-left"
autoClose={2000}
hideProgressBar={false}
newestOnTop={false}
closeOnClick
rtl={false}
draggable
pauseOnHover
/>

{authenticated && <Header />}
<WebsiteRoutes />
<Footer />
{authenticated && <Footer />}
</div>
);
};
Expand Down
22 changes: 22 additions & 0 deletions src/hooks/useToast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { toast } from "react-toastify";

const useToast = () => {
const showToast = (toastText, toastTheme) => {
const notify = () => {
toast[toastTheme](toastText, {
position: "top-right",
autoClose: 3000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
});
};
notify();
};

return { showToast };
};

export { useToast };

0 comments on commit d17e496

Please sign in to comment.