Starting to resolve the issue on prediction9
This commit is contained in:
parent
b2e4fbfc5d
commit
415afe8ac8
@ -4,7 +4,20 @@ server {
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Vite hashed bundles — safe to cache forever; soft reload (F5) reuses them.
|
||||
location /assets/ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
# HTML entry must always revalidate so clients pick up new hashed asset names.
|
||||
location = /index.html {
|
||||
add_header Cache-Control "no-cache";
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
add_header Cache-Control "no-cache";
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,13 +4,16 @@
|
||||
*/
|
||||
import { CssBaseline, ThemeProvider } from '@mui/material';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { useMemo } from 'react';
|
||||
import { lazy, Suspense, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { RouterProvider } from 'react-router-dom';
|
||||
import { createAppTheme } from './theme/theme';
|
||||
import { router } from './router/router';
|
||||
import { AuthProvider } from '../shared/auth/AuthContext';
|
||||
import { SupportWidget } from '../features/support/components/SupportWidget';
|
||||
|
||||
const SupportWidget = lazy(() =>
|
||||
import('../features/support/components/SupportWidget').then((m) => ({ default: m.SupportWidget }))
|
||||
);
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
@ -33,7 +36,9 @@ function AppProviders() {
|
||||
<ThemeProvider theme={theme}>
|
||||
<CssBaseline />
|
||||
<RouterProvider router={router} />
|
||||
<SupportWidget />
|
||||
<Suspense fallback={null}>
|
||||
<SupportWidget />
|
||||
</Suspense>
|
||||
</ThemeProvider>
|
||||
</AuthProvider>
|
||||
</QueryClientProvider>
|
||||
|
||||
@ -1,49 +1,113 @@
|
||||
/**
|
||||
* Client-side route configuration for the web admin console.
|
||||
* Defines public login routes, authenticated app shell routes, and admin-only sections.
|
||||
* Heavy feature pages are lazy-loaded so a hard refresh only parses the shell + active route.
|
||||
*/
|
||||
import { lazy, Suspense, type ComponentType, type ReactNode } from 'react';
|
||||
import { createBrowserRouter, Navigate } from 'react-router-dom';
|
||||
import { Box, CircularProgress } from '@mui/material';
|
||||
import { AppShell } from '../../shared/layout/AppShell';
|
||||
import { DashboardPage } from '../../features/dashboard/DashboardPage';
|
||||
import { OptionsPage } from '../../features/options/OptionsPage';
|
||||
import { UserManagementPage } from '../../features/users/UserManagementPage';
|
||||
import { SettingsPage } from '../../features/settings/SettingsPage';
|
||||
import { RequireAuth } from '../../shared/auth/RequireAuth';
|
||||
import { LoginPage } from '../../features/auth/LoginPage';
|
||||
import { SetupPage } from '../../features/auth/SetupPage';
|
||||
import { RegisterPage } from '../../features/auth/RegisterPage';
|
||||
import { VerifyEmailPage } from '../../features/auth/VerifyEmailPage';
|
||||
import { ForgotPasswordPage } from '../../features/auth/ForgotPasswordPage';
|
||||
import { ResetPasswordPage } from '../../features/auth/ResetPasswordPage';
|
||||
import { CountriesAdminPage } from '../../features/countries/CountriesAdminPage';
|
||||
import { RequireAuth } from '../../shared/auth/RequireAuth';
|
||||
import { WalletPage } from '../../features/wallet/WalletPage';
|
||||
import { ProfilePage } from '../../features/profile/ProfilePage';
|
||||
import { HomePage } from '../../features/home/HomePage';
|
||||
import { CatalogAdminPage } from '../../features/catalog/CatalogAdminPage';
|
||||
import { TreasuryAdminPage } from '../../features/treasury/TreasuryAdminPage';
|
||||
import { ApprovalsPage } from '../../features/approvals/ApprovalsPage';
|
||||
import { ApprovalPoliciesPage } from '../../features/approvals/ApprovalPoliciesPage';
|
||||
import { ReferralAdminPage } from '../../features/referral/ReferralAdminPage';
|
||||
import { ReferralRegularizationPage } from '../../features/referral/ReferralRegularizationPage';
|
||||
import { ReferralPage } from '../../features/referral/ReferralPage';
|
||||
import { ReferralFraudDashboardPage } from '../../features/referral/ReferralFraudDashboardPage';
|
||||
import { TestWalletAdminPage } from '../../features/test-wallet/TestWalletAdminPage';
|
||||
import { ShareCardsAdminPage } from '../../features/share-cards/ShareCardsAdminPage';
|
||||
import { SoloEncouragementAdminPage } from '../../features/solo-encouragement/SoloEncouragementAdminPage';
|
||||
import { MarketingAdminPage } from '../../features/marketing/MarketingAdminPage';
|
||||
import { ShareResultVerifyPage } from '../../features/share-cards/ShareResultVerifyPage';
|
||||
import { SecurityAdminPage } from '../../features/security/SecurityAdminPage';
|
||||
import { ReportsHubPage } from '../../features/reports/ReportsHubPage';
|
||||
import { ReportDetailPage } from '../../features/reports/ReportDetailPage';
|
||||
import { NetworkStatusPage } from '../../features/network/NetworkStatusPage';
|
||||
import { SupportAdminPage } from '../../features/support/SupportAdminPage';
|
||||
import { FaqPublicPage } from '../../features/faq/FaqPublicPage';
|
||||
import { FaqPage } from '../../features/faq/FaqPage';
|
||||
import { FaqAdminPage } from '../../features/faq/FaqAdminPage';
|
||||
import { RoleManagementPage } from '../../features/rbac/RoleManagementPage';
|
||||
import { AdminUsersPage } from '../../features/rbac/AdminUsersPage';
|
||||
import { AdminUserPermissionsPage } from '../../features/rbac/AdminUserPermissionsPage';
|
||||
import { GamePlayRoute } from '../../features/games/GamePlayRoute';
|
||||
|
||||
function lazyNamed<T extends Record<string, unknown>, K extends keyof T>(
|
||||
loader: () => Promise<T>,
|
||||
exportName: K
|
||||
) {
|
||||
return lazy(async () => {
|
||||
const mod = await loader();
|
||||
return { default: mod[exportName] as ComponentType<Record<string, never>> };
|
||||
});
|
||||
}
|
||||
|
||||
const RegisterPage = lazyNamed(() => import('../../features/auth/RegisterPage'), 'RegisterPage');
|
||||
const VerifyEmailPage = lazyNamed(() => import('../../features/auth/VerifyEmailPage'), 'VerifyEmailPage');
|
||||
const ForgotPasswordPage = lazyNamed(
|
||||
() => import('../../features/auth/ForgotPasswordPage'),
|
||||
'ForgotPasswordPage'
|
||||
);
|
||||
const ResetPasswordPage = lazyNamed(() => import('../../features/auth/ResetPasswordPage'), 'ResetPasswordPage');
|
||||
const FaqPublicPage = lazyNamed(() => import('../../features/faq/FaqPublicPage'), 'FaqPublicPage');
|
||||
const ShareResultVerifyPage = lazyNamed(
|
||||
() => import('../../features/share-cards/ShareResultVerifyPage'),
|
||||
'ShareResultVerifyPage'
|
||||
);
|
||||
|
||||
const HomePage = lazyNamed(() => import('../../features/home/HomePage'), 'HomePage');
|
||||
const GamePlayRoute = lazyNamed(() => import('../../features/games/GamePlayRoute'), 'GamePlayRoute');
|
||||
const WalletPage = lazyNamed(() => import('../../features/wallet/WalletPage'), 'WalletPage');
|
||||
const ReferralPage = lazyNamed(() => import('../../features/referral/ReferralPage'), 'ReferralPage');
|
||||
const ProfilePage = lazyNamed(() => import('../../features/profile/ProfilePage'), 'ProfilePage');
|
||||
const FaqPage = lazyNamed(() => import('../../features/faq/FaqPage'), 'FaqPage');
|
||||
|
||||
const SupportAdminPage = lazyNamed(() => import('../../features/support/SupportAdminPage'), 'SupportAdminPage');
|
||||
const FaqAdminPage = lazyNamed(() => import('../../features/faq/FaqAdminPage'), 'FaqAdminPage');
|
||||
|
||||
const DashboardPage = lazyNamed(() => import('../../features/dashboard/DashboardPage'), 'DashboardPage');
|
||||
const OptionsPage = lazyNamed(() => import('../../features/options/OptionsPage'), 'OptionsPage');
|
||||
const UserManagementPage = lazyNamed(
|
||||
() => import('../../features/users/UserManagementPage'),
|
||||
'UserManagementPage'
|
||||
);
|
||||
const ReportsHubPage = lazyNamed(() => import('../../features/reports/ReportsHubPage'), 'ReportsHubPage');
|
||||
const ReportDetailPage = lazyNamed(() => import('../../features/reports/ReportDetailPage'), 'ReportDetailPage');
|
||||
const SettingsPage = lazyNamed(() => import('../../features/settings/SettingsPage'), 'SettingsPage');
|
||||
const CatalogAdminPage = lazyNamed(() => import('../../features/catalog/CatalogAdminPage'), 'CatalogAdminPage');
|
||||
const TreasuryAdminPage = lazyNamed(() => import('../../features/treasury/TreasuryAdminPage'), 'TreasuryAdminPage');
|
||||
const ApprovalsPage = lazyNamed(() => import('../../features/approvals/ApprovalsPage'), 'ApprovalsPage');
|
||||
const ApprovalPoliciesPage = lazyNamed(
|
||||
() => import('../../features/approvals/ApprovalPoliciesPage'),
|
||||
'ApprovalPoliciesPage'
|
||||
);
|
||||
const SecurityAdminPage = lazyNamed(() => import('../../features/security/SecurityAdminPage'), 'SecurityAdminPage');
|
||||
const ReferralAdminPage = lazyNamed(() => import('../../features/referral/ReferralAdminPage'), 'ReferralAdminPage');
|
||||
const ReferralRegularizationPage = lazyNamed(
|
||||
() => import('../../features/referral/ReferralRegularizationPage'),
|
||||
'ReferralRegularizationPage'
|
||||
);
|
||||
const ReferralFraudDashboardPage = lazyNamed(
|
||||
() => import('../../features/referral/ReferralFraudDashboardPage'),
|
||||
'ReferralFraudDashboardPage'
|
||||
);
|
||||
const TestWalletAdminPage = lazyNamed(
|
||||
() => import('../../features/test-wallet/TestWalletAdminPage'),
|
||||
'TestWalletAdminPage'
|
||||
);
|
||||
const ShareCardsAdminPage = lazyNamed(
|
||||
() => import('../../features/share-cards/ShareCardsAdminPage'),
|
||||
'ShareCardsAdminPage'
|
||||
);
|
||||
const SoloEncouragementAdminPage = lazyNamed(
|
||||
() => import('../../features/solo-encouragement/SoloEncouragementAdminPage'),
|
||||
'SoloEncouragementAdminPage'
|
||||
);
|
||||
const MarketingAdminPage = lazyNamed(
|
||||
() => import('../../features/marketing/MarketingAdminPage'),
|
||||
'MarketingAdminPage'
|
||||
);
|
||||
const CountriesAdminPage = lazyNamed(
|
||||
() => import('../../features/countries/CountriesAdminPage'),
|
||||
'CountriesAdminPage'
|
||||
);
|
||||
const NetworkStatusPage = lazyNamed(() => import('../../features/network/NetworkStatusPage'), 'NetworkStatusPage');
|
||||
const RoleManagementPage = lazyNamed(() => import('../../features/rbac/RoleManagementPage'), 'RoleManagementPage');
|
||||
const AdminUsersPage = lazyNamed(() => import('../../features/rbac/AdminUsersPage'), 'AdminUsersPage');
|
||||
const AdminUserPermissionsPage = lazyNamed(
|
||||
() => import('../../features/rbac/AdminUserPermissionsPage'),
|
||||
'AdminUserPermissionsPage'
|
||||
);
|
||||
|
||||
function RouteFallback() {
|
||||
return (
|
||||
<Box sx={{ display: 'grid', placeItems: 'center', minHeight: 240, width: '100%' }}>
|
||||
<CircularProgress size={28} />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
function L({ children }: { children: ReactNode }) {
|
||||
return <Suspense fallback={<RouteFallback />}>{children}</Suspense>;
|
||||
}
|
||||
|
||||
/** Browser router instance with login, dashboard, options, and admin route trees. */
|
||||
export const router = createBrowserRouter([
|
||||
@ -57,27 +121,51 @@ export const router = createBrowserRouter([
|
||||
},
|
||||
{
|
||||
path: '/register',
|
||||
element: <RegisterPage />,
|
||||
element: (
|
||||
<L>
|
||||
<RegisterPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/verify-email',
|
||||
element: <VerifyEmailPage />,
|
||||
element: (
|
||||
<L>
|
||||
<VerifyEmailPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/forgot-password',
|
||||
element: <ForgotPasswordPage />,
|
||||
element: (
|
||||
<L>
|
||||
<ForgotPasswordPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/reset-password',
|
||||
element: <ResetPasswordPage />,
|
||||
element: (
|
||||
<L>
|
||||
<ResetPasswordPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/faq',
|
||||
element: <FaqPublicPage />,
|
||||
element: (
|
||||
<L>
|
||||
<FaqPublicPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/share/r/:token',
|
||||
element: <ShareResultVerifyPage />,
|
||||
element: (
|
||||
<L>
|
||||
<ShareResultVerifyPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
@ -87,45 +175,262 @@ export const router = createBrowserRouter([
|
||||
element: <AppShell />,
|
||||
children: [
|
||||
{ index: true, element: <Navigate to="/home" replace /> },
|
||||
{ path: 'home', element: <HomePage /> },
|
||||
{ path: 'games/:slug', element: <GamePlayRoute /> },
|
||||
{ path: 'wallet', element: <WalletPage /> },
|
||||
{ path: 'referral', element: <ReferralPage /> },
|
||||
{ path: 'profile', element: <ProfilePage /> },
|
||||
{ path: 'help/faq', element: <FaqPage /> },
|
||||
{
|
||||
path: 'home',
|
||||
element: (
|
||||
<L>
|
||||
<HomePage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'games/:slug',
|
||||
element: (
|
||||
<L>
|
||||
<GamePlayRoute />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'wallet',
|
||||
element: (
|
||||
<L>
|
||||
<WalletPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'referral',
|
||||
element: (
|
||||
<L>
|
||||
<ReferralPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'profile',
|
||||
element: (
|
||||
<L>
|
||||
<ProfilePage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'help/faq',
|
||||
element: (
|
||||
<L>
|
||||
<FaqPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
element: <RequireAuth staffOnly />,
|
||||
children: [
|
||||
{ path: 'admin/support', element: <SupportAdminPage /> },
|
||||
{ path: 'admin/faq', element: <FaqAdminPage /> },
|
||||
{
|
||||
path: 'admin/support',
|
||||
element: (
|
||||
<L>
|
||||
<SupportAdminPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/faq',
|
||||
element: (
|
||||
<L>
|
||||
<FaqAdminPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
element: <RequireAuth adminOnly />,
|
||||
children: [
|
||||
{ path: 'dashboard', element: <DashboardPage /> },
|
||||
{ path: 'options', element: <OptionsPage /> },
|
||||
{ path: 'admin/users', element: <UserManagementPage /> },
|
||||
{ path: 'admin/reports', element: <ReportsHubPage /> },
|
||||
{ path: 'admin/reports/:reportKey', element: <ReportDetailPage /> },
|
||||
{ path: 'admin/settings', element: <SettingsPage /> },
|
||||
{ path: 'admin/catalog', element: <CatalogAdminPage /> },
|
||||
{ path: 'admin/treasury', element: <TreasuryAdminPage /> },
|
||||
{ path: 'admin/approvals', element: <ApprovalsPage /> },
|
||||
{ path: 'admin/approval-policies', element: <ApprovalPoliciesPage /> },
|
||||
{ path: 'admin/security', element: <SecurityAdminPage /> },
|
||||
{ path: 'admin/referral', element: <ReferralAdminPage /> },
|
||||
{ path: 'admin/referral/regularization', element: <ReferralRegularizationPage /> },
|
||||
{ path: 'admin/referral/fraud', element: <ReferralFraudDashboardPage /> },
|
||||
{ path: 'admin/test-wallet', element: <TestWalletAdminPage /> },
|
||||
{ path: 'admin/share-cards', element: <ShareCardsAdminPage /> },
|
||||
{ path: 'admin/solo-encouragement', element: <SoloEncouragementAdminPage /> },
|
||||
{ path: 'admin/marketing', element: <MarketingAdminPage /> },
|
||||
{ path: 'admin/countries', element: <CountriesAdminPage /> },
|
||||
{ path: 'admin/network', element: <NetworkStatusPage /> },
|
||||
{ path: 'admin/rbac', element: <RoleManagementPage /> },
|
||||
{ path: 'admin/admin-users', element: <AdminUsersPage /> },
|
||||
{ path: 'admin/admin-users/:userId/permissions', element: <AdminUserPermissionsPage /> },
|
||||
{
|
||||
path: 'dashboard',
|
||||
element: (
|
||||
<L>
|
||||
<DashboardPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'options',
|
||||
element: (
|
||||
<L>
|
||||
<OptionsPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/users',
|
||||
element: (
|
||||
<L>
|
||||
<UserManagementPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/reports',
|
||||
element: (
|
||||
<L>
|
||||
<ReportsHubPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/reports/:reportKey',
|
||||
element: (
|
||||
<L>
|
||||
<ReportDetailPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/settings',
|
||||
element: (
|
||||
<L>
|
||||
<SettingsPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/catalog',
|
||||
element: (
|
||||
<L>
|
||||
<CatalogAdminPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/treasury',
|
||||
element: (
|
||||
<L>
|
||||
<TreasuryAdminPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/approvals',
|
||||
element: (
|
||||
<L>
|
||||
<ApprovalsPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/approval-policies',
|
||||
element: (
|
||||
<L>
|
||||
<ApprovalPoliciesPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/security',
|
||||
element: (
|
||||
<L>
|
||||
<SecurityAdminPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/referral',
|
||||
element: (
|
||||
<L>
|
||||
<ReferralAdminPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/referral/regularization',
|
||||
element: (
|
||||
<L>
|
||||
<ReferralRegularizationPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/referral/fraud',
|
||||
element: (
|
||||
<L>
|
||||
<ReferralFraudDashboardPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/test-wallet',
|
||||
element: (
|
||||
<L>
|
||||
<TestWalletAdminPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/share-cards',
|
||||
element: (
|
||||
<L>
|
||||
<ShareCardsAdminPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/solo-encouragement',
|
||||
element: (
|
||||
<L>
|
||||
<SoloEncouragementAdminPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/marketing',
|
||||
element: (
|
||||
<L>
|
||||
<MarketingAdminPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/countries',
|
||||
element: (
|
||||
<L>
|
||||
<CountriesAdminPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/network',
|
||||
element: (
|
||||
<L>
|
||||
<NetworkStatusPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/rbac',
|
||||
element: (
|
||||
<L>
|
||||
<RoleManagementPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/admin-users',
|
||||
element: (
|
||||
<L>
|
||||
<AdminUsersPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/admin-users/:userId/permissions',
|
||||
element: (
|
||||
<L>
|
||||
<AdminUserPermissionsPage />
|
||||
</L>
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@ -5,7 +5,6 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
type PointerEvent as ReactPointerEvent,
|
||||
type WheelEvent as ReactWheelEvent,
|
||||
} from 'react';
|
||||
import {
|
||||
Box,
|
||||
@ -277,25 +276,35 @@ export function ReferralTreeView({
|
||||
dragRef.current = null;
|
||||
};
|
||||
|
||||
const onWheel = (e: ReactWheelEvent) => {
|
||||
e.preventDefault();
|
||||
const el = viewportRef.current;
|
||||
if (!el) return;
|
||||
const rect = el.getBoundingClientRect();
|
||||
const fx = e.clientX - rect.left;
|
||||
const fy = e.clientY - rect.top;
|
||||
const factor = e.deltaY < 0 ? 1.1 : 1 / 1.1;
|
||||
setTransform((prev) => {
|
||||
const nextScale = Math.max(MIN_SCALE, Math.min(MAX_SCALE, prev.scale * factor));
|
||||
const sceneX = (fx - prev.x) / prev.scale;
|
||||
const sceneY = (fy - prev.y) / prev.scale;
|
||||
return {
|
||||
scale: nextScale,
|
||||
x: fx - sceneX * nextScale,
|
||||
y: fy - sceneY * nextScale,
|
||||
};
|
||||
});
|
||||
};
|
||||
// Native non-passive wheel listener — React's onWheel is passive and cannot preventDefault.
|
||||
const detachWheelRef = useRef<(() => void) | null>(null);
|
||||
const setViewportRef = useCallback((node: HTMLDivElement | null) => {
|
||||
detachWheelRef.current?.();
|
||||
detachWheelRef.current = null;
|
||||
viewportRef.current = node;
|
||||
if (!node) return;
|
||||
const onWheel = (e: WheelEvent) => {
|
||||
e.preventDefault();
|
||||
const rect = node.getBoundingClientRect();
|
||||
const fx = e.clientX - rect.left;
|
||||
const fy = e.clientY - rect.top;
|
||||
const factor = e.deltaY < 0 ? 1.1 : 1 / 1.1;
|
||||
setTransform((prev) => {
|
||||
const nextScale = Math.max(MIN_SCALE, Math.min(MAX_SCALE, prev.scale * factor));
|
||||
const sceneX = (fx - prev.x) / prev.scale;
|
||||
const sceneY = (fy - prev.y) / prev.scale;
|
||||
return {
|
||||
scale: nextScale,
|
||||
x: fx - sceneX * nextScale,
|
||||
y: fy - sceneY * nextScale,
|
||||
};
|
||||
});
|
||||
};
|
||||
node.addEventListener('wheel', onWheel, { passive: false });
|
||||
detachWheelRef.current = () => node.removeEventListener('wheel', onWheel);
|
||||
}, []);
|
||||
|
||||
useEffect(() => () => detachWheelRef.current?.(), []);
|
||||
|
||||
const directRoots = childMap.get(rootUserId) ?? [];
|
||||
if (directRoots.length === 0 && members.length === 0) {
|
||||
@ -335,12 +344,11 @@ export function ReferralTreeView({
|
||||
</Typography>
|
||||
|
||||
<Box
|
||||
ref={viewportRef}
|
||||
ref={setViewportRef}
|
||||
onPointerDown={onPointerDown}
|
||||
onPointerMove={onPointerMove}
|
||||
onPointerUp={onPointerUp}
|
||||
onPointerCancel={onPointerUp}
|
||||
onWheel={onWheel}
|
||||
sx={{
|
||||
position: 'absolute',
|
||||
inset: 0,
|
||||
|
||||
@ -5,14 +5,14 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import './shared/i18n';
|
||||
import { initSentry } from './shared/observability/sentry';
|
||||
import { App } from './app/App';
|
||||
import './styles/global.css';
|
||||
|
||||
initSentry();
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
|
||||
// Observability after first paint — do not block boot on Sentry SDK parse/init.
|
||||
void import('./shared/observability/sentry').then(({ initSentry }) => initSentry());
|
||||
|
||||
@ -2,10 +2,11 @@
|
||||
* React context for authentication state in the web admin console.
|
||||
*/
|
||||
import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { Box, CircularProgress } from '@mui/material';
|
||||
import { clearAuth, readAuth, writeAuth } from './tokenStorage';
|
||||
import { hasAdminAccess, hasStaffAccess, hasAdminPanelAccess } from './roleAccess';
|
||||
import { hasPermission as checkPermission } from './permissions';
|
||||
import { ensureFreshAccessToken, logoutSession } from '../services/api';
|
||||
import { ensureFreshAccessToken, isAccessTokenExpiringSoon, logoutSession } from '../services/api';
|
||||
|
||||
export type AuthState = {
|
||||
accessToken: string | null;
|
||||
@ -18,7 +19,7 @@ export type AuthState = {
|
||||
|
||||
type AuthContextValue = {
|
||||
auth: AuthState;
|
||||
/** False until boot refresh finishes — avoid firing protected calls with a stale JWT. */
|
||||
/** False only while a network refresh is in flight for an expiring session. */
|
||||
authReady: boolean;
|
||||
isAuthenticated: boolean;
|
||||
isAdmin: boolean;
|
||||
@ -35,23 +36,34 @@ type AuthContextValue = {
|
||||
|
||||
const AuthContext = createContext<AuthContextValue | null>(null);
|
||||
|
||||
function sessionNeedsNetworkRefresh(): boolean {
|
||||
const a = readAuth();
|
||||
if (!a.refreshToken && !a.accessToken) return false;
|
||||
return isAccessTokenExpiringSoon(a.accessToken, 60);
|
||||
}
|
||||
|
||||
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
const [auth, setAuthState] = useState<AuthState>(() => readAuth());
|
||||
const [authReady, setAuthReady] = useState(false);
|
||||
// Do not block the whole app when the access token is still valid.
|
||||
const [authReady, setAuthReady] = useState(() => !sessionNeedsNetworkRefresh());
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
void (async () => {
|
||||
const hadSession = Boolean(readAuth().refreshToken || readAuth().accessToken);
|
||||
if (!sessionNeedsNetworkRefresh()) {
|
||||
if (!cancelled) {
|
||||
setAuthState(readAuth());
|
||||
setAuthReady(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const token = await ensureFreshAccessToken();
|
||||
if (cancelled) return;
|
||||
if (token) {
|
||||
setAuthState(readAuth());
|
||||
} else if (hadSession && !readAuth().refreshToken) {
|
||||
clearAuth();
|
||||
setAuthState(readAuth());
|
||||
} else if (hadSession && !token) {
|
||||
// Refresh failed (revoked / secret rotated) — clear so UI redirects to login.
|
||||
} else if (hadSession) {
|
||||
clearAuth();
|
||||
setAuthState(readAuth());
|
||||
} else {
|
||||
@ -105,7 +117,11 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
}, [auth, authReady]);
|
||||
|
||||
if (!authReady) {
|
||||
return null;
|
||||
return (
|
||||
<Box sx={{ minHeight: '100vh', display: 'grid', placeItems: 'center' }}>
|
||||
<CircularProgress size={32} />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
||||
|
||||
@ -6,5 +6,29 @@ export default defineConfig({
|
||||
server: {
|
||||
port: 5173,
|
||||
},
|
||||
build: {
|
||||
// Split large vendor libs so hard refresh can download/parse them in parallel
|
||||
// and soft reload can reuse cached chunks across deploys that only change app code.
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks(id) {
|
||||
if (!id.includes('node_modules')) return;
|
||||
if (id.includes('@mui') || id.includes('@emotion')) return 'mui';
|
||||
if (
|
||||
id.includes('node_modules/react/') ||
|
||||
id.includes('node_modules/react-dom/') ||
|
||||
id.includes('node_modules/scheduler/') ||
|
||||
id.includes('react-router')
|
||||
) {
|
||||
return 'react';
|
||||
}
|
||||
if (id.includes('i18next')) return 'i18n';
|
||||
if (id.includes('@tanstack/react-query')) return 'query';
|
||||
if (id.includes('@sentry')) return 'sentry';
|
||||
return 'vendor';
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user