import { ProxyType, TypedProxyConfig } from '@/types/proxy' import { useTranslation } from 'react-i18next' import { Button } from '../ui/button' import { BaseDropdownMenu } from '../base/drop-down-menu' import { deleteProxyConfig, startProxy, stopProxy } from '@/api/proxy' import { useMutation } from '@tanstack/react-query' import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import { ProxyConfigMutateForm } from './mutate_proxy_config' import { useEffect, useMemo, useState } from 'react' import { Row } from '@tanstack/react-table' import { ProxyConfigTableSchema } from './proxy_config_item' import { MoreHorizontal } from 'lucide-react' import { toast } from 'sonner' import { $proxyTableRefetchTrigger } from '@/store/refetch-trigger' import { DropdownMenuGroup, DropdownMenuItem } from '../ui/dropdown-menu' export interface ProxyConfigActionsProps { serverID: string clientID: string name: string row: Row } export function ProxyConfigActions({ serverID, clientID, name, row }: ProxyConfigActionsProps) { const { t } = useTranslation() const [proxyMutateFormOpen, setProxyMutateFormOpen] = useState(false) const [deleteWarnDialogOpen, setDeleteWarnDialogOpen] = useState(false) const proxyConfig = row.original const deleteProxyConfigMutation = useMutation({ mutationKey: ['deleteProxyConfig', serverID, clientID, name], mutationFn: () => deleteProxyConfig({ serverId: serverID, clientId: clientID, name, }), onSuccess: () => { toast(t('proxy.action.delete_success')) $proxyTableRefetchTrigger.set(Math.random()) }, onError: (e) => { toast(t('proxy.action.delete_failed'), { description: JSON.stringify(e), }) $proxyTableRefetchTrigger.set(Math.random()) }, }) const stopProxyMutation = useMutation({ mutationKey: ['stopProxy', serverID, clientID, name], mutationFn: () => stopProxy({ serverId: serverID, clientId: clientID, name, }), onSuccess: () => { toast(t('proxy.action.stop_success')) $proxyTableRefetchTrigger.set(Math.random()) }, onError: (e) => { toast(t('proxy.action.stop_failed'), { description: JSON.stringify(e), }) $proxyTableRefetchTrigger.set(Math.random()) }, }) const startProxyMutation = useMutation({ mutationKey: ['startProxy', serverID, clientID, name], mutationFn: () => startProxy({ serverId: serverID, clientId: clientID, name, }), onSuccess: () => { toast(t('proxy.action.start_success')) $proxyTableRefetchTrigger.set(Math.random()) }, onError: (e) => { toast(t('proxy.action.start_failed'), { description: JSON.stringify(e), }) $proxyTableRefetchTrigger.set(Math.random()) }, }) const menuActions = [ [ { name: t('proxy.action.edit'), onClick: () => { setProxyMutateFormOpen(true) }, }, { name: t('proxy.action.delete'), onClick: () => { setDeleteWarnDialogOpen(true) }, className: 'text-destructive', }, ], ] const extraButtons = useMemo( () => ( {!proxyConfig.stopped && ( stopProxyMutation.mutate()}> {t('client.actions_menu.pause')} )} {proxyConfig.stopped && ( startProxyMutation.mutate()}> {t('client.actions_menu.resume')} )} ), [proxyConfig, startProxyMutation, stopProxyMutation, t], ) return ( <> {t('proxy.action.delete_tunnel')}

{t('proxy.action.delete_attention_title')}

{t('proxy.action.delete_attention_description')}

} extraButtons={extraButtons} /> ) }