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" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<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">
</head>
<body>

View File

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

View File

@@ -21,25 +21,35 @@ import type {
WhatsAppAccountRuntimeStatus,
} 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 {
const collapsed = path.replace(/\/{2,}/g, "/");
const collapsed = (path || "/").replace(/\/{2,}/g, "/");
if (collapsed.length > 1 && collapsed.endsWith("/")) {
return collapsed.slice(0, -1);
}
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 {
if (!input) return "/";
try {
@@ -118,7 +128,7 @@ class ApiClient {
if (error.response?.status === 401) {
const requestPath = getNormalizedPathFromURL(error.config?.url || "");
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;
// Keep failed login attempts on the same page.