implement admin panel with login functionality and dashboard layout

This commit is contained in:
2025-08-31 18:07:49 +02:00
parent 8fb70ccccd
commit 217803ba8f
16 changed files with 409 additions and 2 deletions

View File

@@ -0,0 +1,43 @@
import Cookies from "js-cookie";
export type LoginSuccess = { success: true };
export type LoginFailure = {
success: false;
message: string;
description: string;
};
export type LoginResult = LoginSuccess | LoginFailure;
export const loginFunc = async (
username: string,
password: string
): Promise<LoginResult> => {
try {
const response = await fetch("http://localhost:8002/api/loginAdmin", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password }),
});
if (!response.ok) {
return {
success: false,
message: "Login failed!",
description: "Invalid username or password.",
};
}
// Successful login
const data = await response.json();
Cookies.set("token", data.token);
localStorage.setItem("userName", data.first_name);
return { success: true };
} catch (error) {
console.error("Error logging in:", error);
return {
success: false,
message: "Login failed!",
description: "Server error.",
};
}
};

View File

@@ -0,0 +1,18 @@
import { toast, Flip, type ToastOptions } from "react-toastify";
export type ToastType = "success" | "error" | "info" | "warning";
export const myToast = (message: string, msgType: ToastType) => {
let config: ToastOptions = {
position: "top-right",
autoClose: 3000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "colored",
transition: Flip,
};
toast[msgType](message, config);
};