Skip to content

Commit 90d0cf2

Browse files
author
WebDeveloperGuide
committed
Toast Alert functionality added
1 parent 56b3887 commit 90d0cf2

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

web_panel/src/App.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import ProductDetailPage from './pages/ProductDetailPage';
44
import About from './pages/About';
55
import NotFound from './pages/NotFound';
66
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
7-
7+
import Toast from "./components/Toast";
8+
import 'react-toastify/dist/ReactToastify.css';
89

910
function App() {
1011
return (
1112
<>
13+
<Toast/>
1214
<Router>
1315
<Switch>
1416
<Route path="/" component={Home} exact/>

web_panel/src/components/Toast.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from "react";
2+
import { ToastContainer } from "react-toastify";
3+
4+
const Toast = () => {
5+
return (
6+
<>
7+
<ToastContainer
8+
position="top-right"
9+
hideProgressBar={false}
10+
newestOnTop={false}
11+
closeOnClick
12+
rtl={false}
13+
/>
14+
</>
15+
);
16+
};
17+
18+
export default Toast;

web_panel/src/pages/ProductDetailPage.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import Cart from '../components/Cart';
99
import Loading from '../components/Loading';
1010
import axios from 'axios';
1111
import {setProductDetail,resetProductDetail} from '../redux/actions/productActions';
12+
import { toast } from 'react-toastify';
13+
import {ToastObjects} from "../util/toastObject";
14+
1215

1316
const ProductDetailPage = () => {
1417

@@ -19,10 +22,13 @@ const ProductDetailPage = () => {
1922

2023
const fetchProductDetail = async() =>{
2124
const response = await axios.get(`https://dummyjson.com/products/${id}`).catch((err) =>{
22-
console.log(err);
25+
toast.error("No data found", ToastObjects);
2326
});
2427

25-
dispatch(setProductDetail(response.data));
28+
if(response){
29+
dispatch(setProductDetail(response.data));
30+
}
31+
2632
};
2733

2834
useEffect(()=>{

web_panel/src/util/toastObject.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const ToastObjects = {
2+
pauseOnFocusLoss: false,
3+
draggable: false,
4+
pauseOnHover: false,
5+
autoClose: 2000,
6+
hideProgressBar: true,
7+
};
8+

0 commit comments

Comments
 (0)