chore: remove unused code and clean up project structure
Some checks failed
CI / Test (1.22) (push) Failing after -30m38s
CI / Test (1.23) (push) Failing after -30m31s
CI / Build (push) Failing after -30m42s
CI / Lint (push) Failing after -30m30s

This commit is contained in:
2026-03-05 01:16:02 +02:00
parent 271a0603b8
commit 6f8bac131c
5 changed files with 101 additions and 68 deletions

File diff suppressed because one or more lines are too long

View File

@@ -5,7 +5,7 @@
<link rel="icon" type="image/x-icon" href="favicon.ico" /> <link rel="icon" type="image/x-icon" href="favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>web</title> <title>web</title>
<script type="module" crossorigin src="/ui/assets/index-CAlNxuwF.js"></script> <script type="module" crossorigin src="/ui/assets/index-ByFXF3HF.js"></script>
<link rel="stylesheet" crossorigin href="/ui/assets/index-Bfia8Lvm.css"> <link rel="stylesheet" crossorigin href="/ui/assets/index-Bfia8Lvm.css">
</head> </head>
<body> <body>

View File

@@ -1,28 +1,28 @@
import { useEffect, lazy, Suspense } from 'react'; import { useEffect, lazy, Suspense } from "react";
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'; import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
import { MantineProvider } from '@mantine/core'; import { MantineProvider } from "@mantine/core";
import { Notifications } from '@mantine/notifications'; import { Notifications } from "@mantine/notifications";
import { ModalsProvider } from '@mantine/modals'; import { ModalsProvider } from "@mantine/modals";
import { useAuthStore } from './stores/authStore'; import { useAuthStore } from "./stores/authStore";
import LoginPage from './pages/LoginPage'; import LoginPage from "./pages/LoginPage";
import DashboardLayout from './components/DashboardLayout'; import DashboardLayout from "./components/DashboardLayout";
import DashboardPage from './pages/DashboardPage'; import DashboardPage from "./pages/DashboardPage";
import UsersPage from './pages/UsersPage'; import UsersPage from "./pages/UsersPage";
import HooksPage from './pages/HooksPage'; import HooksPage from "./pages/HooksPage";
import AccountsPage from './pages/AccountsPage'; import AccountsPage from "./pages/AccountsPage";
import EventLogsPage from './pages/EventLogsPage'; import EventLogsPage from "./pages/EventLogsPage";
import MessageCachePage from './pages/MessageCachePage'; import MessageCachePage from "./pages/MessageCachePage";
import SendMessagePage from './pages/SendMessagePage'; import SendMessagePage from "./pages/SendMessagePage";
import WhatsAppBusinessPage from './pages/WhatsAppBusinessPage'; import WhatsAppBusinessPage from "./pages/WhatsAppBusinessPage";
import TemplateManagementPage from './pages/TemplateManagementPage'; import TemplateManagementPage from "./pages/TemplateManagementPage";
import CatalogManagementPage from './pages/CatalogManagementPage'; import CatalogManagementPage from "./pages/CatalogManagementPage";
import FlowManagementPage from './pages/FlowManagementPage'; import FlowManagementPage from "./pages/FlowManagementPage";
const SwaggerPage = lazy(() => import('./pages/SwaggerPage')); const SwaggerPage = lazy(() => import("./pages/SwaggerPage"));
// Import Mantine styles // Import Mantine styles
import '@mantine/core/styles.css'; import "@mantine/core/styles.css";
import '@mantine/notifications/styles.css'; import "@mantine/notifications/styles.css";
import '@mantine/dates/styles.css'; import "@mantine/dates/styles.css";
function App() { function App() {
const { isAuthenticated, checkAuth } = useAuthStore(); const { isAuthenticated, checkAuth } = useAuthStore();
@@ -38,31 +38,54 @@ function App() {
<BrowserRouter basename="/ui"> <BrowserRouter basename="/ui">
<Routes> <Routes>
{/* Public routes */} {/* Public routes */}
<Route path="/login" element={ <Route
isAuthenticated ? <Navigate to="/dashboard" replace /> : <LoginPage /> path="/login"
} /> element={
isAuthenticated ? (
<Navigate to="/dashboard" replace />
) : (
<LoginPage />
)
}
/>
{/* Protected routes */} {/* Protected routes */}
<Route path="/" element={ <Route
isAuthenticated ? <DashboardLayout /> : <Navigate to="/login" replace /> path="/"
}> element={
isAuthenticated ? (
<DashboardLayout />
) : (
<Navigate to="/login" replace />
)
}
>
<Route index element={<Navigate to="/dashboard" replace />} /> <Route index element={<Navigate to="/dashboard" replace />} />
<Route path="dashboard" element={<DashboardPage />} /> <Route path="dashboard" element={<DashboardPage />} />
<Route path="users" element={<UsersPage />} /> <Route path="users" element={<UsersPage />} />
<Route path="hooks" element={<HooksPage />} /> <Route path="hooks" element={<HooksPage />} />
<Route path="accounts" element={<AccountsPage />} /> <Route path="accounts" element={<AccountsPage />} />
<Route path="whatsapp-business" element={<WhatsAppBusinessPage />} /> <Route
<Route path="business-templates" element={<TemplateManagementPage />} /> path="whatsapp-business"
element={<WhatsAppBusinessPage />}
/>
<Route
path="business-templates"
element={<TemplateManagementPage />}
/>
<Route path="catalogs" element={<CatalogManagementPage />} /> <Route path="catalogs" element={<CatalogManagementPage />} />
<Route path="flows" element={<FlowManagementPage />} /> <Route path="flows" element={<FlowManagementPage />} />
<Route path="send-message" element={<SendMessagePage />} /> <Route path="send-message" element={<SendMessagePage />} />
<Route path="event-logs" element={<EventLogsPage />} /> <Route path="event-logs" element={<EventLogsPage />} />
<Route path="message-cache" element={<MessageCachePage />} /> <Route path="message-cache" element={<MessageCachePage />} />
<Route path="sw" element={ <Route
path="sw"
element={
<Suspense fallback={null}> <Suspense fallback={null}>
<SwaggerPage /> <SwaggerPage />
</Suspense> </Suspense>
} /> }
/>
</Route> </Route>
{/* Catch all */} {/* Catch all */}

View File

@@ -21,25 +21,35 @@ import type {
WhatsAppAccountRuntimeStatus, WhatsAppAccountRuntimeStatus,
} from "../types"; } from "../types";
function getApiBaseUrl(): string {
if (import.meta.env.VITE_API_URL) return import.meta.env.VITE_API_URL.replace(/\/+$/, "");
const { hostname, protocol, port } = window.location;
if (hostname === "localhost" || hostname === "127.0.0.1") return "http://localhost:8080";
return `${protocol}//${hostname}${port ? `:${port}` : ""}`.replace(/\/+$/, "");
}
const API_BASE_URL = getApiBaseUrl();
const LOGIN_API_PATH = "/api/v1/auth/login";
const LOGIN_UI_PATH = "/ui/login";
function normalizePath(path: string): string { function normalizePath(path: string): string {
const collapsed = path.replace(/\/{2,}/g, "/"); const collapsed = (path || "/").replace(/\/{2,}/g, "/");
if (collapsed.length > 1 && collapsed.endsWith("/")) { if (collapsed.length > 1 && collapsed.endsWith("/")) {
return collapsed.slice(0, -1); return collapsed.slice(0, -1);
} }
return collapsed || "/"; return collapsed || "/";
} }
function getAppBasePath(pathname: string): string {
const normalized = normalizePath(pathname);
const match = normalized.match(/^(.*)\/ui(?:\/|$)/);
if (!match) return "";
const prefix = match[1] || "";
return prefix === "/" ? "" : prefix;
}
function getApiBaseUrl(): string {
if (import.meta.env.VITE_API_URL) return import.meta.env.VITE_API_URL.replace(/\/+$/, "");
const { hostname, protocol, port } = window.location;
const appBasePath = getAppBasePath(window.location.pathname);
if (hostname === "localhost" || hostname === "127.0.0.1") return "http://localhost:8080";
return `${protocol}//${hostname}${port ? `:${port}` : ""}${appBasePath}`.replace(/\/+$/, "");
}
const API_BASE_URL = getApiBaseUrl();
const APP_BASE_PATH = getAppBasePath(window.location.pathname);
const LOGIN_API_PATH = "/api/v1/auth/login";
const LOGIN_UI_PATH = `${APP_BASE_PATH}/ui/login`.replace(/\/{2,}/g, "/");
function getNormalizedPathFromURL(input: string): string { function getNormalizedPathFromURL(input: string): string {
if (!input) return "/"; if (!input) return "/";
try { try {
@@ -118,7 +128,7 @@ class ApiClient {
if (error.response?.status === 401) { if (error.response?.status === 401) {
const requestPath = getNormalizedPathFromURL(error.config?.url || ""); const requestPath = getNormalizedPathFromURL(error.config?.url || "");
const currentPath = normalizePath(window.location.pathname); const currentPath = normalizePath(window.location.pathname);
const isLoginRequest = requestPath === LOGIN_API_PATH; const isLoginRequest = requestPath === LOGIN_API_PATH || requestPath.endsWith(LOGIN_API_PATH);
const isLoginPage = currentPath === LOGIN_UI_PATH; const isLoginPage = currentPath === LOGIN_UI_PATH;
// Keep failed login attempts on the same page. // Keep failed login attempts on the same page.