'use client'; import { useState, useEffect } from 'react'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, } from '@/components/ui/dialog'; import { Sidebar, SidebarContent, SidebarGroup, SidebarGroupContent, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarProvider, } from '@/components/ui/sidebar'; import { Button } from '@/components/ui/button'; import BotForm from '@/app/home/bots/components/bot-form/BotForm'; import { BotLogListComponent } from '@/app/home/bots/components/bot-log/view/BotLogListComponent'; import { useTranslation } from 'react-i18next'; import { z } from 'zod'; import { httpClient } from '@/app/infra/http/HttpClient'; interface BotDetailDialogProps { open: boolean; onOpenChange: (open: boolean) => void; botId?: string; // eslint-disable-next-line @typescript-eslint/no-explicit-any onFormSubmit: (value: z.infer) => void; onFormCancel: () => void; onBotDeleted: () => void; onNewBotCreated: (botId: string) => void; } export default function BotDetailDialog({ open, onOpenChange, botId: propBotId, onFormSubmit, onFormCancel, onBotDeleted, onNewBotCreated, }: BotDetailDialogProps) { const { t } = useTranslation(); const [botId, setBotId] = useState(propBotId); const [activeMenu, setActiveMenu] = useState('config'); const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); useEffect(() => { setBotId(propBotId); setActiveMenu('config'); }, [propBotId, open]); const menu = [ { key: 'config', label: t('bots.configuration'), icon: ( ), }, { key: 'logs', label: t('bots.logs'), icon: ( ), }, ]; // eslint-disable-next-line @typescript-eslint/no-explicit-any const handleFormSubmit = (value: any) => { onFormSubmit(value); }; const handleFormCancel = () => { onFormCancel(); }; const handleBotDeleted = () => { httpClient.deleteBot(botId ?? '').then(() => { onBotDeleted(); }); }; const handleNewBotCreated = (newBotId: string) => { setBotId(newBotId); setActiveMenu('config'); onNewBotCreated(newBotId); }; const handleDelete = () => { setShowDeleteConfirm(true); }; const confirmDelete = () => { handleBotDeleted(); setShowDeleteConfirm(false); }; if (!botId) { return ( <>
{t('bots.createBot')}
); } return ( <> {menu.map((item) => ( setActiveMenu(item.key)} > {item.icon} {item.label} ))}
{activeMenu === 'config' ? t('bots.editBot') : t('bots.botLogTitle')}
{activeMenu === 'config' && ( )} {activeMenu === 'logs' && botId && ( )}
{activeMenu === 'config' && (
)}
{/* 删除确认对话框 */} {t('common.confirmDelete')}
{t('bots.deleteConfirmation')}
); }