'use client'; import { useState } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { Power, RefreshCw, Check, X, Play, Square, RotateCcw, AlertTriangle } from 'lucide-react'; export function QuickActions() { const [loading, setLoading] = useState(null); const [message, setMessage] = useState<{ type: 'success' | 'error'; text: string } | null>(null); const handleAction = async (action: 'start' | 'stop' | 'restart') => { setLoading(action); setMessage(null); try { const response = await fetch('/api/actions', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action }), }); const result = await response.json(); if (result.success) { setMessage({ type: 'success', text: result.message }); } else { setMessage({ type: 'error', text: result.message || 'Action failed' }); } } catch (error) { setMessage({ type: 'error', text: 'Failed to execute action' }); } finally { setLoading(null); } }; const actions = [ { id: 'start' as const, title: 'Start Gateway', description: 'Start the OpenClaw Gateway daemon', icon: Play, variant: 'default' as const, color: 'bg-green-600 hover:bg-green-700', }, { id: 'stop' as const, title: 'Stop Gateway', description: 'Stop the OpenClaw Gateway daemon', icon: Square, variant: 'outline' as const, color: 'border-red-600 text-red-400 hover:bg-red-600/10', }, { id: 'restart' as const, title: 'Restart Gateway', description: 'Restart the OpenClaw Gateway daemon', icon: RotateCcw, variant: 'outline' as const, color: 'border-orange-600 text-orange-400 hover:bg-orange-600/10', }, ]; return (
{/* Warning */} These actions affect the entire Gateway. Be careful when stopping or restarting. {/* Message */} {message && ( {message.type === 'success' ? ( ) : ( )} {message.text} )} {/* Action Cards */}
{actions.map((action) => { const Icon = action.icon; const isLoading = loading === action.id; return ( {action.title}

{action.description}

); })}
{/* Info */} Quick Actions Info
Start Gateway: Launches the OpenClaw Gateway daemon if it's not running.
Stop Gateway: Gracefully stops the Gateway. All active sessions will be terminated.
Restart Gateway: Stops and immediately starts the Gateway again. Useful for applying config changes.
); }