- Updated LoanTable component to fetch loan data from new API endpoint and display notes. - Enhanced UserTable component to include additional user fields (first name, last name, email, admin status) and updated input handling. - Modified fetcher utility to use new user data API endpoint. - Adjusted login functionality to point to the new admin login endpoint and handle unauthorized access. - Refactored user actions utility to align with updated API endpoints for user management. - Updated backend routes for user and loan data management to reflect new structure and naming conventions. - Revised SQL schema and mock data to accommodate new fields and constraints. - Changed Docker configuration to use the new database name.
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import React, { useState } from "react";
|
|
import { useEffect } from "react";
|
|
import Dashboard from "./Dashboard";
|
|
import Login from "./Login";
|
|
import Cookies from "js-cookie";
|
|
import { API_BASE } from "@/config/api.config";
|
|
|
|
const Layout: React.FC = () => {
|
|
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
|
|
|
useEffect(() => {
|
|
if (Cookies.get("token")) {
|
|
const verifyToken = async () => {
|
|
const response = await fetch(
|
|
`${API_BASE}/api/admin/user-mgmt/verify-token`,
|
|
{
|
|
method: "GET",
|
|
headers: {
|
|
Authorization: `Bearer ${Cookies.get("token")}`,
|
|
},
|
|
}
|
|
);
|
|
if (response.ok) {
|
|
setIsLoggedIn(true);
|
|
} else {
|
|
Cookies.remove("token");
|
|
setIsLoggedIn(false);
|
|
window.location.reload();
|
|
}
|
|
};
|
|
verifyToken();
|
|
}
|
|
}, []);
|
|
|
|
const handleLogout = () => {
|
|
Cookies.remove("token");
|
|
window.location.pathname = "/";
|
|
setIsLoggedIn(false);
|
|
};
|
|
|
|
return (
|
|
<main>
|
|
{isLoggedIn ? (
|
|
<Dashboard onLogout={() => handleLogout()} />
|
|
) : (
|
|
<Login onSuccess={() => setIsLoggedIn(true)} />
|
|
)}
|
|
</main>
|
|
);
|
|
};
|
|
|
|
export default Layout;
|