-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gisubizo Jovan
authored and
gisubizo Jovan
committed
Jul 8, 2024
1 parent
9652708
commit ce7c781
Showing
8 changed files
with
147 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from "react"; | ||
import { useSelector, useDispatch } from "react-redux"; | ||
|
||
import { clearNetworkError } from "../../../redux/reducers/NetworkErrorSlice"; | ||
|
||
const Popup = () => { | ||
const dispatch = useDispatch(); | ||
// @ts-ignore | ||
const showPopup = useSelector((state) => state.networkError.showPopup); | ||
|
||
if (!showPopup) return null; | ||
|
||
return ( | ||
<div className="fixed inset-0 z-40 flex items-center justify-center bg-[#D0D0D0] bg-opacity-50"> | ||
<div className="relative bg-white rounded-lg p-10 w-[90%] md:w-[65%] lg:w-[55%] xl:w-[50%] duration-75 animate-fadeIn"> | ||
<p> | ||
📵 | ||
<b>Network Error </b> | ||
<br /> | ||
Please check your internet connection. | ||
</p> | ||
<button | ||
onClick={() => dispatch(clearNetworkError())} | ||
className="mt-10 bg-transparent text-primary border border-[#DB4444] px-4 py-2 rounded" | ||
> | ||
Close | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
export default Popup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,44 @@ | ||
import axios from "axios"; | ||
|
||
import store from "../store"; | ||
import { setNetworkError } from "../reducers/NetworkErrorSlice"; | ||
|
||
const api = axios.create({ | ||
baseURL: process.env.VITE_BASE_URL, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
let navigateFunction = null; | ||
|
||
export const setNavigateFunction = (navigate) => { | ||
navigateFunction = navigate; | ||
}; | ||
const redirectToLogin = (navigate) => { | ||
setTimeout(() => { | ||
navigate("/login"); | ||
}, 2000); | ||
}; | ||
|
||
const redirectToLanding = (navigate) => { | ||
setTimeout(() => { | ||
navigate("/"); | ||
}, 3000); | ||
}; | ||
|
||
api.interceptors.response.use( | ||
(response) => response, | ||
(error) => { | ||
// const navigate = useNavigate(); | ||
if (error.response && error.response.status === 401) { | ||
if (navigateFunction) { | ||
redirectToLogin(navigateFunction); | ||
} | ||
} else if (!error.response) { | ||
store.dispatch(setNetworkError()); | ||
} | ||
return Promise.reject(error); | ||
}, | ||
); | ||
|
||
export default api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { createSlice } from "@reduxjs/toolkit"; | ||
|
||
export const networkErrorSlice = createSlice({ | ||
name: "networkError", | ||
initialState: { showPopup: false }, | ||
reducers: { | ||
setNetworkError: (state) => { | ||
state.showPopup = true; | ||
}, | ||
clearNetworkError: (state) => { | ||
state.showPopup = false; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setNetworkError, clearNetworkError } = networkErrorSlice.actions; | ||
|
||
export default networkErrorSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters