feat: del dat confirm

This commit is contained in:
archer
2023-08-14 10:43:05 +08:00
parent 3a49efd46d
commit 90f5f84bd8
3 changed files with 27 additions and 12 deletions

View File

@@ -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",

View File

@@ -37,6 +37,9 @@
"Input": "输入",
"Output": "输出"
},
"dataset": {
"Confirm to delete the data": "确认删除该数据?"
},
"file": {
"Click to download CSV template": "点击下载 CSV 模板",
"Drag and drop": "拖拽文件至此,或点击",

View File

@@ -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<HTMLDivElement>(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);
})();
}}
/>
</Flex>
@@ -267,6 +275,7 @@ const DataCard = ({ kbId }: { kbId: string }) => {
onSuccess={() => refetchData()}
/>
)}
<ConfirmModal />
</Box>
);
};