fix: frontend-backend integration — 14 issues resolved
- nginx: add proxy routes for /settings/, /templates/, /ipam/, /logs/, /admin/, /health
- dashboard: fix data format mismatch (servers[] not nodes[]/vms[])
- dashboard: add WebSocket subscription to dashboard_metrics for real-time updates
- dashboard: connect activity feed to /logs/api/logs endpoint
- dashboard: reduce polling to 15s with WS as primary update source
- graphs: fix rrddata response unwrap (backend returns {data:[],timeframe:''})
- graphs: add i18n translations for chart titles
- console: add xterm.js CSS import for proper terminal rendering
- console: add i18n translations (connecting, reconnect)
- workspace: add switcher dropdown in TopBar
- workspace: add edit dialog in WorkspacesPage
- workspace: create Zustand store with localStorage persistence
- workspace: add X-Active-Workspace header to API client
- sidebar: replace generic icon with actual favicon.svg logo
- instances: translate RowActionMenu and InstanceDetailPage strings
- locales: add graphs, console, workspace, instance tab keys to en/ru
This commit is contained in:
70
frontend/src/stores/auth-store.ts
Normal file
70
frontend/src/stores/auth-store.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import { create } from 'zustand';
|
||||
import { apiClient } from '@/lib/api-client';
|
||||
import type { User, LoginRequest, AuthResponse } from '@/types';
|
||||
|
||||
interface AuthState {
|
||||
user: User | null;
|
||||
token: string | null;
|
||||
isAuthenticated: boolean;
|
||||
isLoading: boolean;
|
||||
error: string | null;
|
||||
|
||||
login: (credentials: LoginRequest) => Promise<void>;
|
||||
logout: () => Promise<void>;
|
||||
loadUser: () => Promise<void>;
|
||||
clearError: () => void;
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthState>((set) => ({
|
||||
user: null,
|
||||
token: localStorage.getItem('access_token'),
|
||||
isAuthenticated: !!localStorage.getItem('access_token'),
|
||||
isLoading: false,
|
||||
error: null,
|
||||
|
||||
login: async (credentials: LoginRequest) => {
|
||||
set({ isLoading: true, error: null });
|
||||
try {
|
||||
const data = await apiClient.post<AuthResponse>('/api/auth/login', credentials);
|
||||
apiClient.setToken(data.access_token);
|
||||
set({ token: data.access_token, isAuthenticated: true, isLoading: false });
|
||||
|
||||
// Load user info
|
||||
const user = await apiClient.get<User>('/api/auth/me');
|
||||
set({ user });
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Login failed';
|
||||
set({ error: message, isLoading: false, isAuthenticated: false });
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
|
||||
logout: async () => {
|
||||
try {
|
||||
await apiClient.post('/api/auth/logout');
|
||||
} catch {
|
||||
// Ignore logout errors
|
||||
}
|
||||
apiClient.setToken(null);
|
||||
set({ user: null, token: null, isAuthenticated: false });
|
||||
},
|
||||
|
||||
loadUser: async () => {
|
||||
const token = localStorage.getItem('access_token');
|
||||
if (!token) {
|
||||
set({ isAuthenticated: false, isLoading: false });
|
||||
return;
|
||||
}
|
||||
set({ isLoading: true });
|
||||
try {
|
||||
apiClient.setToken(token);
|
||||
const user = await apiClient.get<User>('/api/auth/me');
|
||||
set({ user, isAuthenticated: true, isLoading: false });
|
||||
} catch {
|
||||
apiClient.setToken(null);
|
||||
set({ user: null, token: null, isAuthenticated: false, isLoading: false });
|
||||
}
|
||||
},
|
||||
|
||||
clearError: () => set({ error: null }),
|
||||
}));
|
||||
45
frontend/src/stores/theme-store.ts
Normal file
45
frontend/src/stores/theme-store.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { create } from 'zustand';
|
||||
|
||||
type Theme = 'dark' | 'light';
|
||||
|
||||
interface ThemeState {
|
||||
theme: Theme;
|
||||
setTheme: (theme: Theme) => void;
|
||||
toggleTheme: () => void;
|
||||
}
|
||||
|
||||
function getInitialTheme(): Theme {
|
||||
const stored = localStorage.getItem('pve-theme');
|
||||
if (stored === 'light' || stored === 'dark') return stored;
|
||||
return 'dark'; // Dark by default per TZ
|
||||
}
|
||||
|
||||
function applyTheme(theme: Theme) {
|
||||
const root = document.documentElement;
|
||||
if (theme === 'dark') {
|
||||
root.classList.add('dark');
|
||||
} else {
|
||||
root.classList.remove('dark');
|
||||
}
|
||||
localStorage.setItem('pve-theme', theme);
|
||||
}
|
||||
|
||||
// Apply initial theme immediately
|
||||
applyTheme(getInitialTheme());
|
||||
|
||||
export const useThemeStore = create<ThemeState>((set) => ({
|
||||
theme: getInitialTheme(),
|
||||
|
||||
setTheme: (theme: Theme) => {
|
||||
applyTheme(theme);
|
||||
set({ theme });
|
||||
},
|
||||
|
||||
toggleTheme: () => {
|
||||
set((state) => {
|
||||
const next = state.theme === 'dark' ? 'light' : 'dark';
|
||||
applyTheme(next);
|
||||
return { theme: next };
|
||||
});
|
||||
},
|
||||
}));
|
||||
21
frontend/src/stores/workspace-store.ts
Normal file
21
frontend/src/stores/workspace-store.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { create } from 'zustand';
|
||||
|
||||
interface WorkspaceState {
|
||||
activeWorkspaceId: number | null;
|
||||
setActiveWorkspace: (id: number | null) => void;
|
||||
}
|
||||
|
||||
export const useWorkspaceStore = create<WorkspaceState>((set) => ({
|
||||
activeWorkspaceId: (() => {
|
||||
const stored = localStorage.getItem('pve-active-workspace');
|
||||
return stored ? Number(stored) : null;
|
||||
})(),
|
||||
setActiveWorkspace: (id) => {
|
||||
if (id !== null) {
|
||||
localStorage.setItem('pve-active-workspace', String(id));
|
||||
} else {
|
||||
localStorage.removeItem('pve-active-workspace');
|
||||
}
|
||||
set({ activeWorkspaceId: id });
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user