import { AlertDialog, AlertDialogActions, AlertDialogCancelButton, AlertDialogConfirmButton, AlertDialogContent, AlertDialogDescription, AlertDialogTitle, } from '@langgenius/dify-ui/alert-dialog' import { toast } from '@langgenius/dify-ui/toast' import { useState } from 'react' import { useTranslation } from 'react-i18next' import Input from '@/app/components/base/input' import { useDeleteTriggerSubscription } from '@/service/use-triggers' import { useSubscriptionList } from './use-subscription-list' type Props = Readonly<{ onClose: (deleted: boolean) => void isShow: boolean currentId: string currentName: string workflowsInUse: number }> const tPrefix = 'subscription.list.item.actions.deleteConfirm' export const DeleteConfirm = (props: Props) => { const { onClose, isShow, currentId, currentName, workflowsInUse } = props const { refetch } = useSubscriptionList() const { mutate: deleteSubscription, isPending: isDeleting } = useDeleteTriggerSubscription() const { t } = useTranslation() const [inputName, setInputName] = useState('') const handleOpenChange = (open: boolean) => { if (isDeleting) return if (!open) onClose(false) } const onConfirm = () => { if (workflowsInUse > 0 && inputName !== currentName) { toast.error(t(($) => $[`${tPrefix}.confirmInputWarning`], { ns: 'pluginTrigger' })) return } deleteSubscription(currentId, { onSuccess: () => { toast.success(t(($) => $[`${tPrefix}.success`], { ns: 'pluginTrigger', name: currentName })) refetch?.() onClose(true) }, onError: (error: unknown) => { toast.error( error instanceof Error ? error.message : t(($) => $[`${tPrefix}.error`], { ns: 'pluginTrigger', name: currentName }), ) }, }) } return (
{t(($) => $[`${tPrefix}.title`], { ns: 'pluginTrigger', name: currentName })} {workflowsInUse > 0 ? t(($) => $[`${tPrefix}.contentWithApps`], { ns: 'pluginTrigger', count: workflowsInUse, }) : t(($) => $[`${tPrefix}.content`], { ns: 'pluginTrigger' })} {workflowsInUse > 0 && (
{t(($) => $[`${tPrefix}.confirmInputTip`], { ns: 'pluginTrigger', name: currentName, })}
setInputName(e.target.value)} placeholder={t(($) => $[`${tPrefix}.confirmInputPlaceholder`], { ns: 'pluginTrigger', name: currentName, })} />
)}
{t(($) => $['operation.cancel'], { ns: 'common' })} {t(($) => $[`${tPrefix}.confirm`], { ns: 'pluginTrigger' })}
) }