feat: integrate TanStack Router and update routing structure

- Added TanStack Router for improved routing management.
- Created route tree and individual routes for login, index, add-product, inventory, and view-product.
- Implemented authentication checks for the inventory route.
- Introduced a landing page component.
- Updated App component to utilize RouterProvider and ToastContainer for notifications.
- Refactored CSS to use Tailwind CSS, removing custom styles.
- Added API configuration for backend URL management.
- Implemented authentication utilities for user sign-in and sign-out.
- Integrated i18next for internationalization with English and German language support.
- Created localization files for English and German languages.
This commit is contained in:
2026-05-26 14:59:16 +02:00
parent b3c3be5590
commit d6e29a74af
21 changed files with 706 additions and 419 deletions
+55
View File
@@ -0,0 +1,55 @@
import { API_BASE } from "../config/api.config";
import Cookies from "js-cookie";
import { useTranslation } from "react-i18next";
import { toast } from "react-toastify";
import { redirect } from "@tanstack/react-router";
const { t } = useTranslation();
export async function isAuthenticated() {
const result = await fetch(`${API_BASE}/users/verify-token`, {
method: "POST",
headers: {
Authorization: `Bearer ${Cookies.get("token") || ""}`,
"Content-Type": "application/json",
Accept: "application/json",
},
});
if (result.status === 200) {
return true;
}
return false;
}
export async function signInUser(username: string, password: string) {
const result = await fetch(`${API_BASE}/users/login`, {
method: "POST",
headers: {
Authorization: `Bearer ${Cookies.get("token") || ""}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({ username, password }),
});
const response = await result.json();
if (result.status === 202) {
Cookies.set("token", response.token);
return true;
}
if (result.status !== 202) {
Cookies.remove("token");
toast.error(t(response.code));
}
}
export function signOutUser() {
Cookies.remove("token");
throw redirect({
to: "/login",
});
}
+34
View File
@@ -0,0 +1,34 @@
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import Cookies from "js-cookie";
import enLang from "./locales/en/en.json";
import deLang from "./locales/de/de.json";
// the translations
// (tip move them in a JSON file and import them,
// or even better, manage them separated from your code: https://react.i18next.com/guides/multiple-translation-files)
const resources = {
en: {
translation: enLang,
},
de: {
translation: deLang,
},
};
i18n
.use(initReactI18next) // passes i18n down to react-i18next
.init({
resources,
fallbackLng: "en", // use en if detected lng is not available
lng: Cookies.get("language") || "en", // language to use, more information here: https://www.i18next.com/overview/configuration-options#languages-namespaces-resources
// you can use the i18n.changeLanguage function to change the language manually: https://www.i18next.com/overview/api#changelanguage
// if you're using a language detector, do not define the lng option
interpolation: {
escapeValue: false, // react already safes from xss
},
});
export default i18n;