fix: power control 502 error and add instant refresh
- Power operations use /api2/extjs endpoint (not /api2/json) - Remove unprivileged parameter that causes 400 validation error - Refetch VM/LXC/node/status after successful power action via SWR mutate Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import useSWR from 'swr';
|
||||
import useSWR, { mutate } from 'swr';
|
||||
import NodeList from './NodeList';
|
||||
import VMList from './VMList';
|
||||
import LXCList from './LXCList';
|
||||
@@ -45,6 +45,11 @@ export default function Dashboard() {
|
||||
setPowerActionStatus({ text: `${action.charAt(0).toUpperCase() + action.slice(1)}ing ${type === 'qemu' ? 'VM' : 'LXC'} ${vmid}...`, type: 'pending' });
|
||||
try {
|
||||
await axios.post('/api/power', { node, vmid, type, action });
|
||||
// Immediately refetch all data instead of waiting for polling interval
|
||||
await mutate('/api/nodes');
|
||||
await mutate('/api/vms');
|
||||
await mutate('/api/lxc');
|
||||
await mutate('/api/status');
|
||||
setPowerActionStatus({ text: `${action.charAt(0).toUpperCase() + action.slice(1)} successful`, type: 'success' });
|
||||
} catch (err) {
|
||||
setPowerActionStatus({ text: err.message || `${action.charAt(0).toUpperCase() + action.slice(1)} failed`, type: 'error' });
|
||||
|
||||
Reference in New Issue
Block a user