import { useState } from 'react'; import { Loader2, Send, X } from 'lucide-react'; import { usePluginContext } from './client'; import type { S3Credential } from './types'; const API_BASE = '/api/v1/plugin/data_analytics'; interface Props { credentials: S3Credential[]; onClose: () => void; onCreated: () => void; } export function NewJobDialog({ credentials, onClose, onCreated }: Props) { const { client } = usePluginContext(); const [credId, setCredId] = useState(credentials[0]?.cred_id || ''); const [description, setDescription] = useState(''); const [busy, setBusy] = useState(false); const [error, setError] = useState(''); const submit = async () => { if (!credId) { setError('请选择 S3 凭证'); return; } if (!description.trim()) { setError('请描述要做的分析'); return; } setBusy(true); setError(''); try { await client.post(`${API_BASE}/jobs`, { cred_id: credId, description: description.trim(), }); onCreated(); onClose(); } catch (e: unknown) { const msg = (e as { response?: { data?: { detail?: string } } }).response?.data?.detail; setError(msg || '提交失败'); } finally { setBusy(false); } }; return (