+
{isLoggedIn && (
<>
diff --git a/frontend_admin/src/utils/frontendService.ts b/frontend_admin/src/utils/frontendService.ts
index 35114e4..851dd58 100644
--- a/frontend_admin/src/utils/frontendService.ts
+++ b/frontend_admin/src/utils/frontendService.ts
@@ -1,4 +1,5 @@
import Cookies from "js-cookie";
+import { toast, type ToastOptions } from "react-toastify";
export const greeting = () => {
return Cookies.get("name") ?? "Login";
@@ -50,3 +51,19 @@ export const setDarkTheme = () => {
document.body.classList.add("dark");
Cookies.set("theme", "dark", { expires: 365 });
};
+
+export type ToastType = "success" | "error" | "info" | "warning";
+
+export const myToast = (message: string, msgType: ToastType) => {
+ let config: ToastOptions = {
+ position: "top-right",
+ autoClose: 5000,
+ hideProgressBar: false,
+ closeOnClick: true,
+ pauseOnHover: true,
+ draggable: true,
+ progress: undefined,
+ theme: "dark",
+ };
+ toast[msgType](message, config);
+};
diff --git a/frontend_admin/src/utils/userHandler.ts b/frontend_admin/src/utils/userHandler.ts
index 76a37a4..c65f173 100644
--- a/frontend_admin/src/utils/userHandler.ts
+++ b/frontend_admin/src/utils/userHandler.ts
@@ -1,5 +1,5 @@
import Cookies from "js-cookie";
-import { ToastContainer, toast } from "react-toastify";
+import { myToast } from "./frontendService";
export const loginUser = (username: string, password: string) => {
fetch("http://localhost:5002/api/login", {
@@ -22,12 +22,11 @@ export const loginUser = (username: string, password: string) => {
.then((users) => {
localStorage.setItem("users", JSON.stringify(users));
});
- document.location.reload();
- toast("Login successful!");
+ myToast("Logged in successfully!", "success");
} else if (response.status === 401) {
- toast("Invalid credentials");
+ myToast("Invalid username or password!", "error");
} else if (response.status === 403) {
- toast("You are not an Admin!");
+ myToast("You are not an Admin!", "error");
}
})
.catch((error) => {
@@ -39,7 +38,7 @@ export const logout = () => {
Cookies.remove("name");
Cookies.remove("token");
localStorage.removeItem("users");
- window.location.reload();
+ myToast("Logged out successfully!", "info");
};
export const deleteUser = (id: number) => {