diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index 851e44752..fe0e2a4f0 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -37,6 +37,9 @@ "Input": "Input", "Output": "Output" }, + "dataset": { + "Confirm to delete the data": "Confirm to delete the data?" + }, "file": { "Click to download CSV template": "Click to download CSV template", "Drag and drop": "Drag and drop files here, or click", diff --git a/client/public/locales/zh/common.json b/client/public/locales/zh/common.json index 29e84dd57..c8c8653b7 100644 --- a/client/public/locales/zh/common.json +++ b/client/public/locales/zh/common.json @@ -37,6 +37,9 @@ "Input": "输入", "Output": "输出" }, + "dataset": { + "Confirm to delete the data": "确认删除该数据?" + }, "file": { "Click to download CSV template": "点击下载 CSV 模板", "Drag and drop": "拖拽文件至此,或点击", diff --git a/client/src/pages/kb/detail/components/DataCard.tsx b/client/src/pages/kb/detail/components/DataCard.tsx index 171e82ac5..9540a0516 100644 --- a/client/src/pages/kb/detail/components/DataCard.tsx +++ b/client/src/pages/kb/detail/components/DataCard.tsx @@ -16,15 +16,21 @@ import Papa from 'papaparse'; import InputModal, { FormData as InputDataType } from './InputDataModal'; import { debounce } from 'lodash'; import { getErrText } from '@/utils/tools'; +import { useConfirm } from '@/hooks/useConfirm'; +import { useTranslation } from 'react-i18next'; import MyIcon from '@/components/Icon'; import MyTooltip from '@/components/MyTooltip'; const DataCard = ({ kbId }: { kbId: string }) => { const BoxRef = useRef(null); const lastSearch = useRef(''); + const { t } = useTranslation(); const [searchText, setSearchText] = useState(''); const { toast } = useToast(); const [isDeleting, setIsDeleting] = useState(false); + const { openConfirm, ConfirmModal } = useConfirm({ + content: t('dataset.Confirm to delete the data') + }); const { data: kbDataList, @@ -225,19 +231,21 @@ const DataCard = ({ kbId }: { kbId: string }) => { borderRadius={'md'} _hover={{ color: 'red.600' }} isLoading={isDeleting} - onClick={async (e) => { + onClick={(e) => { e.stopPropagation(); - try { - setIsDeleting(true); - await delOneKbDataByDataId(item.id); - refetchData(pageNum); - } catch (error) { - toast({ - title: getErrText(error), - status: 'error' - }); - } - setIsDeleting(false); + openConfirm(async () => { + try { + setIsDeleting(true); + await delOneKbDataByDataId(item.id); + refetchData(pageNum); + } catch (error) { + toast({ + title: getErrText(error), + status: 'error' + }); + } + setIsDeleting(false); + })(); }} /> @@ -267,6 +275,7 @@ const DataCard = ({ kbId }: { kbId: string }) => { onSuccess={() => refetchData()} /> )} + ); };