File tree Expand file tree Collapse file tree 4 files changed +37
-3
lines changed Expand file tree Collapse file tree 4 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -4,11 +4,13 @@ import ProductDetailPage from './pages/ProductDetailPage';
4
4
import About from './pages/About' ;
5
5
import NotFound from './pages/NotFound' ;
6
6
import { BrowserRouter as Router , Switch , Route } from "react-router-dom" ;
7
-
7
+ import Toast from "./components/Toast" ;
8
+ import 'react-toastify/dist/ReactToastify.css' ;
8
9
9
10
function App ( ) {
10
11
return (
11
12
< >
13
+ < Toast />
12
14
< Router >
13
15
< Switch >
14
16
< Route path = "/" component = { Home } exact />
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ import Cart from '../components/Cart';
9
9
import Loading from '../components/Loading' ;
10
10
import axios from 'axios' ;
11
11
import { setProductDetail , resetProductDetail } from '../redux/actions/productActions' ;
12
+ import { toast } from 'react-toastify' ;
13
+ import { ToastObjects } from "../util/toastObject" ;
14
+
12
15
13
16
const ProductDetailPage = ( ) => {
14
17
@@ -19,10 +22,13 @@ const ProductDetailPage = () => {
19
22
20
23
const fetchProductDetail = async ( ) => {
21
24
const response = await axios . get ( `https://dummyjson.com/products/${ id } ` ) . catch ( ( err ) => {
22
- console . log ( err ) ;
25
+ toast . error ( "No data found" , ToastObjects ) ;
23
26
} ) ;
24
27
25
- dispatch ( setProductDetail ( response . data ) ) ;
28
+ if ( response ) {
29
+ dispatch ( setProductDetail ( response . data ) ) ;
30
+ }
31
+
26
32
} ;
27
33
28
34
useEffect ( ( ) => {
Original file line number Diff line number Diff line change
1
+ export const ToastObjects = {
2
+ pauseOnFocusLoss : false ,
3
+ draggable : false ,
4
+ pauseOnHover : false ,
5
+ autoClose : 2000 ,
6
+ hideProgressBar : true ,
7
+ } ;
8
+
You can’t perform that action at this time.
0 commit comments