| 
									
										
										
										
											2023-08-18 17:37:31 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import React, { useEffect, useState } from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							| 
									
										
										
										
											2024-06-20 11:05:08 +08:00
										 |  |  | import { RiCloseLine } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2023-08-18 17:37:31 +08:00
										 |  |  | import CSVUploader from './csv-uploader' | 
					
						
							|  |  |  | import CSVDownloader from './csv-downloader' | 
					
						
							|  |  |  | import Button from '@/app/components/base/button' | 
					
						
							|  |  |  | import Modal from '@/app/components/base/modal' | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  | import type { ChunkingMode } from '@/models/datasets' | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  | import { noop } from 'lodash-es' | 
					
						
							| 
									
										
										
										
											2023-08-18 17:37:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export type IBatchModalProps = { | 
					
						
							|  |  |  |   isShow: boolean | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |   docForm: ChunkingMode | 
					
						
							| 
									
										
										
										
											2023-08-18 17:37:31 +08:00
										 |  |  |   onCancel: () => void | 
					
						
							|  |  |  |   onConfirm: (file: File) => void | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const BatchModal: FC<IBatchModalProps> = ({ | 
					
						
							|  |  |  |   isShow, | 
					
						
							|  |  |  |   docForm, | 
					
						
							|  |  |  |   onCancel, | 
					
						
							|  |  |  |   onConfirm, | 
					
						
							|  |  |  | }) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  |   const [currentCSV, setCurrentCSV] = useState<File>() | 
					
						
							|  |  |  |   const handleFile = (file?: File) => setCurrentCSV(file) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const handleSend = () => { | 
					
						
							|  |  |  |     if (!currentCSV) | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     onCancel() | 
					
						
							|  |  |  |     onConfirm(currentCSV) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     if (!isShow) | 
					
						
							|  |  |  |       setCurrentCSV(undefined) | 
					
						
							|  |  |  |   }, [isShow]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  |     <Modal isShow={isShow} onClose={noop} className='!max-w-[520px] !rounded-xl px-8 py-6'> | 
					
						
							| 
									
										
										
										
											2023-08-18 17:37:31 +08:00
										 |  |  |       <div className='relative pb-1 text-xl font-medium leading-[30px] text-gray-900'>{t('datasetDocuments.list.batchModal.title')}</div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       <div className='absolute right-4 top-4 cursor-pointer p-2' onClick={onCancel}> | 
					
						
							|  |  |  |         <RiCloseLine className='h-4 w-4 text-gray-500' /> | 
					
						
							| 
									
										
										
										
											2023-08-18 17:37:31 +08:00
										 |  |  |       </div> | 
					
						
							|  |  |  |       <CSVUploader | 
					
						
							|  |  |  |         file={currentCSV} | 
					
						
							|  |  |  |         updateFile={handleFile} | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |       <CSVDownloader | 
					
						
							|  |  |  |         docForm={docForm} | 
					
						
							|  |  |  |       /> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       <div className='mt-[28px] flex justify-end pt-6'> | 
					
						
							| 
									
										
										
										
											2024-06-21 14:17:45 +08:00
										 |  |  |         <Button className='mr-2' onClick={onCancel}> | 
					
						
							| 
									
										
										
										
											2023-08-18 17:37:31 +08:00
										 |  |  |           {t('datasetDocuments.list.batchModal.cancel')} | 
					
						
							|  |  |  |         </Button> | 
					
						
							| 
									
										
										
										
											2024-06-21 14:17:45 +08:00
										 |  |  |         <Button variant="primary" onClick={handleSend} disabled={!currentCSV}> | 
					
						
							| 
									
										
										
										
											2023-08-18 17:37:31 +08:00
										 |  |  |           {t('datasetDocuments.list.batchModal.run')} | 
					
						
							|  |  |  |         </Button> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     </Modal> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | export default React.memo(BatchModal) |