chore: remove unused code and clean up project structure
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
pkg/serverembed/dist/index.html
vendored
2
pkg/serverembed/dist/index.html
vendored
@@ -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>
|
||||
|
||||
@@ -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 */}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user