選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

index.tsx 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useEffect, useState } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { RiCloseLine } from '@remixicon/react'
  6. import CSVUploader from './csv-uploader'
  7. import CSVDownloader from './csv-downloader'
  8. import Button from '@/app/components/base/button'
  9. import Modal from '@/app/components/base/modal'
  10. import type { ChunkingMode } from '@/models/datasets'
  11. import { noop } from 'lodash-es'
  12. export type IBatchModalProps = {
  13. isShow: boolean
  14. docForm: ChunkingMode
  15. onCancel: () => void
  16. onConfirm: (file: File) => void
  17. }
  18. const BatchModal: FC<IBatchModalProps> = ({
  19. isShow,
  20. docForm,
  21. onCancel,
  22. onConfirm,
  23. }) => {
  24. const { t } = useTranslation()
  25. const [currentCSV, setCurrentCSV] = useState<File>()
  26. const handleFile = (file?: File) => setCurrentCSV(file)
  27. const handleSend = () => {
  28. if (!currentCSV)
  29. return
  30. onCancel()
  31. onConfirm(currentCSV)
  32. }
  33. useEffect(() => {
  34. if (!isShow)
  35. setCurrentCSV(undefined)
  36. }, [isShow])
  37. return (
  38. <Modal isShow={isShow} onClose={noop} className='!max-w-[520px] !rounded-xl px-8 py-6'>
  39. <div className='relative pb-1 text-xl font-medium leading-[30px] text-text-primary'>{t('datasetDocuments.list.batchModal.title')}</div>
  40. <div className='absolute right-4 top-4 cursor-pointer p-2' onClick={onCancel}>
  41. <RiCloseLine className='h-4 w-4 text-text-secondary' />
  42. </div>
  43. <CSVUploader
  44. file={currentCSV}
  45. updateFile={handleFile}
  46. />
  47. <CSVDownloader
  48. docForm={docForm}
  49. />
  50. <div className='mt-[28px] flex justify-end pt-6'>
  51. <Button className='mr-2' onClick={onCancel}>
  52. {t('datasetDocuments.list.batchModal.cancel')}
  53. </Button>
  54. <Button variant="primary" onClick={handleSend} disabled={!currentCSV}>
  55. {t('datasetDocuments.list.batchModal.run')}
  56. </Button>
  57. </div>
  58. </Modal>
  59. )
  60. }
  61. export default React.memo(BatchModal)